Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RobotFramework, how to check text on page

if there appears text on a page after hitting a button.

the only thing it is in is a class, like so:

<label class="err">2 van de 3 velden  Eiwit, Koolhydraten, Vet  zijn leeg.</label>

with what should you verify?

I tried:

Page Should Contain Textfield    err

but that's not the way to go I think

    *** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Maximize Browser Window
    Set Browser Implicit Wait    5
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open

Login Page Should Be Open
    Title Should Be    Hippe testautomatisering getest i.c.m. testtechnieken

Go To Login Page
    Go To    ${LOGIN URL}
    Login Page Should Be Open

Input Username
    [Arguments]    ${username} 
    Input Text    voedselnaam    ${username}

Input Password
    [Arguments]    ${password}
    Input Text    Eenheid    ${password}
    Input Text    Kcal    ${password}
    Input Text    Eiwit    ${password}

Submit Credentials
    Click Element   getdata    
    page should contain  //label[@class='err']  2 van de 3 velden Eiwit, Koolhydraten, Vet zijn leeg.


Welcome Page Should Be Open
    Location Should Be    ${LOGIN URL}
    Title Should Be    Welcome Page
like image 588
tijnn Avatar asked Jan 17 '19 18:01

tijnn


1 Answers

There are various options choose which suites you most

Using Keywords

  1. If you want exact text match then use

    Element Text Should Be    //label[@class='err']    2 van de 3 velden  Eiwit, Koolhydraten, Vet  zijn leeg.
    
  2. If you want substring in text

    Element Should Contain    //label[@class='err']    velden
    
  3. It waits until the locator with text appears on page , I think another option to suffice to serve you verify text

    Wait Until Element Contains    locator        text
    
  4. This will verify text on entire page so it may be present multiple times on page or only single time

    Wait Until Page Contains        text_you_want_to_verify_on_page 
    

Using Locators

to match complete text

//label[text()="2 van de 3 velden  Eiwit, Koolhydraten, Vet  zijn leeg."]

to match partial text

//label[contains(text(),'velden')]

and pass it to one of keyword which verifies element on page. for more option you can explore here

like image 88
Dev Avatar answered Nov 15 '22 10:11

Dev