Robot Framework: conditional import of resource
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 |
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 |
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 '18 at 7:50
luator
2,49911832
2,49911832
asked Nov 19 '18 at 13:30
El FredEl Fred
8011
8011
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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 |
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 |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 16:50
Wojtek TWojtek T
1,336422
1,336422
add a comment |
add a comment |
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 |
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 |
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 '18 at 14:24
Naveen MunjalNaveen Munjal
766
766
add a comment |
add a comment |
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 |
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 |
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 '18 at 8:48
pankaj mishrapankaj mishra
1,1242416
1,1242416
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.
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