Sarada Akurathi
Sarada Akurathi

Reputation: 1188

Robot Framework : Error while connecting Oracle Database through DatabaseLibrary

I tried to connect to Oracle Database through Robot framework, i am getting error.

In Database Library documention given the syntax as below:

# explicitly specifies all db property values                       
Connect To Database     psycopg2    my_db   postgres    s3cr3t  tiger.foobar.com    5432

Link to DatabaseLibrary

I used the same in my code as below:

*** Settings ***
Documentation  Trouble Ticket Test Cases
Library     Selenium2Library
Library     DatabaseLibrary

*** Test Cases ***
Connect To Database

*** Keywords ***
Connect To Database
    Connect To Database cx_Oracle    MTNIODC48    ABL_DBOBJECTS    abill_2808_prod    172.20.22.48    1521  

I ran and got the below error: Keyword 'DatabaseLibrary.Connect To Database' expected 4 arguments, got 6.

Can anyone please help on this.

Thanks Sarada

Upvotes: 1

Views: 3205

Answers (2)

Muditha Perera
Muditha Perera

Reputation: 1252

I had the same issue and This is the solution which I found

Step 1: Install Oracle instant client (32 bit) ( I'm using instantclient_18_3, You don't have to install cx_oracle seperately )

Step 2: Install Operating System Literary and the Database Library for Robot and import it

*** Settings ***
Library           DatabaseLibrary
Library           OperatingSystem

Then in your robot script, Add The following variable and make sure it's with the test cases (NOT in an external resource file)

*** Variables ***
${DB_CONNECT_STRING}    'DB_USERNAME/DB_PASSWORD@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=YOUR_DB_OR_HOST)(PORT=YOUR_PORT))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=YOUR_SID)))'

Then you can use the following keywords to set the environment variables and to run queries

*** Keywords ***
Connect To DB
    [Arguments]    ${DB_CONNECT_STRING_VALUE}
    Set Environment Variable    PATH    PATH_TO_YOUR_INSTANT_CLIENT\\instantclient_18_3
    Set Global Variable    ${DB_CONNECT_STRING_VALUE}
    #Connect to DB
    connect to database using custom params    cx_Oracle    ${DB_CONNECT_STRING_VALUE}

Run Query and log results
    [Arguments]    ${QUERY_TO_EXECUTE}
    Set Global Variable    ${QUERY_TO_EXECUTE}
    ${queryResults}    Query    ${QUERY_TO_EXECUTE}
    log to console    ${queryResults}

Disconnect From DB
    #Disconnect from DB
    disconnect from database

Finally, in your test case run it like this

*** Test Cases ***
Get Sysdate Test
    [Tags]    DBConnect
    Connect To DB    ${DB_CONNECT_STRING}
    Run Query and log results    SELECT sysdate from Dual

This should work fine for you

Upvotes: 1

Hemant Kulkarni
Hemant Kulkarni

Reputation: 193

Can you try using -

Connect to Database using Custom Params  cx_Oracle  '${ABL_DBOBJECTS}/${abill_2808_prod}@172.20.22.48:1521/${MTNIODC48}'

Also, you can add the dependency like

*** Settings ***
Library           ..${/}..${/}lib${/}databaselibrary-0.6${/}DatabaseLibrary${/}

& download the DatabaseLibrary Here

Upvotes: 2

Related Questions