1

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

9 Comments

Hi Hemant, i am getting the following error `No keyword with name 'Connect to Database using Custom Params' found.'
Please check documentation here.. franz-see.github.io/Robotframework-Database-Library/api/0.5/… Also make sure that you are using right indentation.
@SaradaAkurathi thats becasue you copied the keyword's name. It using capital in every word, like Connect To Database Using Custom Params check the corresponding documentation: franz-see.github.io/Robotframework-Database-Library/api/0.5/…
Thanks Hemanth and Richard, it worked. I need one more small help, to give this DatabaseLibrary as dependancy in Eclipse Maven project, can you please tell me how to give, otherwise how to make it work under maven also. I searched there is no Maven Dependency for this DatabaseLibrary(Python).
That was relative path for library I have. You can have it accordingly as per your computer path. My complete file looks like- *** Settings *** Library ..${/}..${/}lib${/}databaselibrary-0.6${/}DatabaseLibrary${/} *** Variables *** *** Keywords *** Query Database [Arguments] ${sql} Connect to Database using Custom Params cx_Oracle '${lsuser}/${lspasswd}@172.16.225.40:1521/${dbschema}' @{result} = Query ${sql} Disconnect From Database [Return] ${result}
|
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.