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
-
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?Bryan Oakley– Bryan Oakley2015-08-24 10:47:27 +00:00Commented Aug 24, 2015 at 10:47
Add a comment
|
3 Answers
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
Comments
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
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.