1

For example, we have:

Get ticket value
        Wait Until Element is Visible    ${ticketDescription}
        ${ticketDescValue}=    Execute Javascript    return window.document.querySelector('p[class*="ticket-description"]').innerHTML.toString()


Verify if ticket value matches
       Element Text Should Be    ${some_locator}    ${ticketDescValue}

where, ${ticketDescValue} would be an expected text

Test Cases example:

*** Test Cases ***
Ticket value is correct
    [Documentation]    OK: test test test
    [Tags]    Add to basket
    Go to some URL
    Get ticket value
    Navigate to product details page
    Verify if ticket value matches

Is there some way to share variables between existing keywords? In Java I can use getters and setters for this case. Or send parameters to method, etc...

How to implement it using Robot Framework?

2 Answers 2

1

You need to either set the variable value as a Global or suite variable using something similar to the below after your assignment line:

 Set Suite Variable    ${ticketDescValue}

Alternatively, you could return the variable from the first keyword and pass it as an argument into the second keyword

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

Comments

0

A better way would be to modify your Get ticket value keyword to return a parameter, and your Verify if ticket value matches keyword to take the ticket value as an argument. That way you don't need to use global variables.

Get ticket value
    Wait Until Element is Visible    ${ticketDescription}
    ${ticketDescValue}=    Execute Javascript    return window.document.querySelector('p[class*="ticket-description"]').innerHTML.toString()
    [Return]    ${ticketDescValue}

Verify if ticket value matches
   [Arguments]    ${value}
   Element Text Should Be    ${some_locator}    ${value}

Then your test would look like this:

*** Test Cases ***
Ticket value is correct
    [Documentation]    OK: test test test
    [Tags]    Add to basket
    Go to some URL
    ${ticket value}=    Get ticket value
    Navigate to product details page
    Verify if ticket value matches    ${ticket value}

I made all the parameter names different to emphasize that they do not have to be all the same - but you can make them all the same if you want.

Comments

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.