2

I have to define two variables ${p1} and ${p2} whose scope should be global means they can be use in various teat cases in a single test suite.

when I am doing the below activity inside test case it is working fine:

${p1}= GET LIBRARY INSTANCE    P1

${p2}= GET LIBRARY INSTANCE    P2

But when I am assigning p1 and p2 as global, I am not able to get the desired result:

set Suite Variable ${p1}= GET LIBRARY INSTANCE    P1

set Suite Variable ${p2}= GET LIBRARY INSTANCE    P2

I did not want to write ${p1}= GET LIBRARY INSTANCE P1 line in all test cases, what should I do? Any help will be appreciated.

1
  • What dos "not able to get the desired result" mean? What result are you getting, and how is it different than what you want? Commented Dec 18, 2018 at 16:41

2 Answers 2

4

You should define a Suite Setup in which you could set your variables for the whole suite. You should get your library instances first and then simply set those variables as suite variables like it is shown in the example.

${ID} =   Get ID      
Set Suite Variable    ${ID}

In your case it should look like something this:

*** Settings ***
Suite Setup    Setup Global Variables

*** Keywords ***
Setup Global Variables
    ${p1}=    GET LIBRARY INSTANCE    P1
    ${p2}=    GET LIBRARY INSTANCE    P2
    Set Suite Variable    ${p1}
    Set Suite Variable    ${p2}

*** Test Cases ***
Test CaseA
    Log   ${p1}
    Log   ${p2}

Test CaseB
    Log   ${p1}
    Log   ${p2}

Note that these variables will be accessible only in this suite file.

Sign up to request clarification or add additional context in comments.

Comments

2

You are using invalid syntax. The documentation for Set suite variable says that it takes a variable name as the first argument and one or more values (not a keyword) as subsequent arguments. You are giving the string ${p1}= GET LIBRARY INSTANCE as the variable name, and the string P1 as the value.

The correct form is like the following. Because ${p1} exists locally you do not need to specify it when calling set suite variable.

${p1}=  GET LIBRARY INSTANCE    P1
set Suite Variable  ${p1}  

1 Comment

I tried this thing earlier but it haven't worked in this case. Solution provided above is the correct implementation that worked for me. Thanks for your help @Bryan

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.