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









share|improve this question




























    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









    share|improve this question


























      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









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 7:50









      luator

      2,44911631




      2,44911631










      asked Nov 19 at 13:30









      El Fred

      7311




      7311
























          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





          share|improve this answer




























            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






            share|improve this answer




























              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/






              share|improve this answer





















                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',
                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
                });


                }
                });














                draft saved

                draft discarded


















                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








                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





                share|improve this answer

























                  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





                  share|improve this answer























                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 19 at 16:50









                    Wojtek T

                    998422




                    998422
























                        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






                        share|improve this answer

























                          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






                          share|improve this answer























                            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






                            share|improve this answer












                            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







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 21 at 14:24









                            Nav.Munjal

                            315




                            315






















                                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/






                                share|improve this answer

























                                  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/






                                  share|improve this answer























                                    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/






                                    share|improve this answer












                                    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/







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 22 at 8:48









                                    pankaj mishra

                                    9952415




                                    9952415






























                                        draft saved

                                        draft discarded




















































                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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







                                        Popular posts from this blog

                                        Costa Masnaga

                                        Fotorealismo

                                        Sidney Franklin