zoukankan      html  css  js  c++  java
  • RF:connecting to multiple databases

    Hello,
    I am trying to connect to multiple databases with DatabaseLibrary but its not working.


    *** Settings ***
    Library           DatabaseLibrary    WITH NAME    db1
    Library           DatabaseLibrary    WITH NAME    db2

    *** Keywords ***
    connect db1 database
        db1.Connect To Database Using Custom Params    cx_Oracle    'db1 connection string'
        @{queryResults1}=    db1.Query    select * from db1_table  --> OK
        db2.Connect To Database Using Custom Params    cx_Oracle    'db2 connection string'
        @{queryResults1}=    db2.Query    select * from db2_table  --> also OK
        @{queryResults1}=    db1.Query    select * from d1table  --> fails saying that db1_table does not exist
    ==============================
    You did not specify which DatabaseLibrary you are talking about, but they both appear to have the same design flaw.
    They both have a test library scope of GLOBAL.
    RF will not create another instance of a library that is scoped GLOBAL. From the user guide, this appears to be by design.
    In other words both db1 and db2 reference the same instance of DatabaseLibrary.
    To fix, do all your queries in db1, then disconnect and connect to db2 and do all your queries there, etc.
    If you want to do queries in both databases without (dis)connecting, there is a fairly easy way with the Python version.
     
    Create a custom library as below:
    ----start content of DatabaseLibrarySS.py----
    from DatabaseLibrary import DatabaseLibrary
     
    class DatabaseLibrarySS(DatabaseLibrary):
        ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
    ----end content of DatabaseLibrarySS.py----
     
    *** Settings ***
    Library           DatabaseLibrarySS.py    WITH NAME    db1
    Library           DatabaseLibrarySS.py    WITH NAME    db2
     
    *** Test Cases ***
    Multiple Instances of DatabaseLibrary
        ${db1}=    Get Library Instance    db1
        ${db2}=    Get Library Instance    db2
        Should Not Be Equal    ${db1}    ${db2}
     
    A library with a scope of GLOBAL should implement keywords to make concurrent use from different contexts possible. For examples, see Switch Process in OperatingSystem or Switch Browser in Selenium2Library.


        
    what am i doing wrong here?

    Thanks in advance for your time and help.
  • 相关阅读:
    Notepad++ 6.2.3 发布,开源文本编辑器
    Scrum项目如何获得管理层的支持和合作
    Concurrency Kit 0.2.13 发布,并发工具包
    Orubase:为Windows Phone、Android和iOS平台开发混合本地手机应用程序
    CyaSSL 2.4.6 发布,SSL 加密库
    谷歌移动应用强调设计元素:向极简风格转型
    Bitcoin 0.7.2 发布, 匿名数字货币
    Netty 3.5.11 发布
    LDAP Account Manager 4.0 发布
    Apache Commons Math 3.1 发布
  • 原文地址:https://www.cnblogs.com/glre09/p/3490613.html
Copyright © 2011-2022 走看看