Robot Framework: conditional import of resource
up vote
0
down vote
favorite
Is it possible to do a conditional import of a resource file in robot framework? Depending on the test environment, I want to import a resource file with different variables. The variable could be read from the robot CLI (e.g. robot --variable VAR:production myTestSuite)
Illustrating Example:
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
import frameworks robotframework
add a comment |
up vote
0
down vote
favorite
Is it possible to do a conditional import of a resource file in robot framework? Depending on the test environment, I want to import a resource file with different variables. The variable could be read from the robot CLI (e.g. robot --variable VAR:production myTestSuite)
Illustrating Example:
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
import frameworks robotframework
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it possible to do a conditional import of a resource file in robot framework? Depending on the test environment, I want to import a resource file with different variables. The variable could be read from the robot CLI (e.g. robot --variable VAR:production myTestSuite)
Illustrating Example:
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
import frameworks robotframework
Is it possible to do a conditional import of a resource file in robot framework? Depending on the test environment, I want to import a resource file with different variables. The variable could be read from the robot CLI (e.g. robot --variable VAR:production myTestSuite)
Illustrating Example:
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
import frameworks robotframework
import frameworks robotframework
edited Nov 20 at 7:50
luator
2,44911631
2,44911631
asked Nov 19 at 13:30
El Fred
7311
7311
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
add a comment |
up vote
0
down vote
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
add a comment |
up vote
0
down vote
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
add a comment |
up vote
0
down vote
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
You could use Arguments file that will have different Environmental variables, You could use something like
QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
Then in your Robot.test
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
NOTE: This is just an example of the argument file use Login with User is not an actual keyword
And then execute command
robot --argumentfile "QA.args" tests
You can also overwrite the variables on the command line.
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
answered Nov 19 at 16:50
Wojtek T
998422
998422
add a comment |
add a comment |
up vote
0
down vote
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
add a comment |
up vote
0
down vote
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
You could use a variable in the name of import file.
Set the value of the variable from pom.xml file in case you are using maven.
Something like below, where ${PLATFORM} is a variable :
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
Below is snippet from POM.xml
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
Also, this way you can pass the value of platform from jenkins (if used)
using -Denv.platform=Platform_5
answered Nov 21 at 14:24
Nav.Munjal
315
315
add a comment |
add a comment |
up vote
0
down vote
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
add a comment |
up vote
0
down vote
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
add a comment |
up vote
0
down vote
up vote
0
down vote
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
I dont think conditional imort is possible in Robot Framework in the way you liked.
However,what you can do is instead of importing envorimnent file as resoucres , you can pass them to your test as --variablefile
How i will do it?
variables_url_environment_a.py
msg='env a'
variables_url_environment_b.py
msg='env b'
Test.robot
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
Now just run your test suite as per the enviroment you need by creating a simple python script.
Python_run_script
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
For more information about how to use --variablefile , you can also refer below url
https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/
answered Nov 22 at 8:48
pankaj mishra
9952415
9952415
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375712%2frobot-framework-conditional-import-of-resource%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown