2

I am working in robot framework. I have two variables files in it. I want to pass these variables files dynamically. In certain condition I want to send a.py and in others b.py. But this information I want to pass dynamically. Can you please help me with this

1
  • When you say "pass these variable files dynamically", what do you mean? Pass them from where? Pass them to where? Do you mean that you want to pass them into a keyword? Or, are you saying you want to pass them from the command line to a test suite? Commented Aug 24, 2015 at 10:47

3 Answers 3

6

You can use the Import library keyword to manually import an external file.

Then use the Run Keyword If keyword to check which library to import. For example:

Run Keyword If   '${VAR}' == 'a'   Import Library   a.py
Run Keyword If   '${VAR}' == 'b'   Import Library   b.py

You can pass the VAR as a parameter to your test:

pybot --variable VAR:a TestSuite
Sign up to request clarification or add additional context in comments.

Comments

0

You can import files based on the variable you are passing during execution

*** Settings ***
Variables    config_${TEST_ENVIRONMENT}.yaml

*** Test Cases ***

*** Keywords ***

Robot command to execute:

$ robot --variable TEST_ENVIRONMENT:local file_name.robot

3 Comments

Did this ever work?
Yes, It is working for me and should work for you as well.
yes it ended up working, I was facing a non-related issue apparently.
0

The most Simple and straightforward way is that you will declare all of your variables in a Python file. For example:

#usbconf.py
target_port="COM29"
target_baudrate=115200

Then import this usbconf.py file in your target robot file as follows:

#test_uart.robot
*** settings ***
Library    SerialLibrary
Library    SeleniumLibrary
Variables    usbconf.py

*** Variables ***

${response}    0A

*** test cases ***
Test UART Device
    [Documentation]    Test Serial Connection
    [Setup]    Add Port    ${target_port}    timeout=30  encoding=ascii  baudrate=${target_baudrate}  bytesize=8
    Open Port   ${target_port}
    Log To Console    ${target_port}
    Port Should Be Open

Additional note: You should have both files in the same folder.

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.