How to navigate in Robot framework

We will learn about how to build custom robot keyword and navigate between pages like backward or forward with working example.

How to navigate in Robot framework

What you will learn

  1. How to build robot keywords
  2. Navigate to links and back in robot
  3. Navigation example

How to build robot keywords

Keywords are actual test steps executed during the Test runs, Robot Framework has predefined keywords that are frequently used that are available in builtin library.

To get started with Robot Framework, follow this link.

How to install robot framework
We will learn how to install robot framework and get started with the real example.

For the web automation Robot Framework uses SeleniumLibrary.

Keyword - To open browser

Open Browser    https://google.com/   chrome

Keyword - Maximize Browser Window

Maximize Browser Window

Keyword - Close the browser session

[Teardown]    Close Browser

How to build custom keywords

Open chrome browser, goto https://google.com and maximize the browser window.

Open Browser To Google
    Open Browser    https://google.com/   chrome
    Maximize Browser Window
    Set Selenium Speed    0

We have combined three builtin keywords and create custom keyword.

Keyword - Input Text Area

Input Search
    Input Text  //input[@title="Search"]    mobilelabs.in

Keyword - Navigate to back

Go Back
    Execute Javascript  history.back()

This executes the history.back() JS api to push the browser to back.

Example - Test Case

  1. Open Browser and go to https://google.com
  2. Enter mobilelabs.in in google search input
  3. Hit search button
  4. View search results for the mobilelabs.in
  5. Go back to google home page
  6. Close the browser
*** Settings ***
Documentation     A test suite with a single test for opening google.com.
...
...               This test has a workflow that is created using keywords in
...               the imported resource file.
Library           SeleniumLibrary

*** Variables ***
${SERVER}         https://google.com/
${BROWSER}        Chrome
${DELAY}          0
${SEARCHWORD}     mobilelabs.in

*** Keywords ***
Open Browser To Google
    Open Browser    ${SERVER}   ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}

Input Search
    Input Text  //input[@title="Search"]    ${SEARCHWORD}

Submit Credentials
    Press Keys   None   RETURN

Go Back
    Execute Javascript  history.back()

*** Test Cases ***
Open Google Home Page
    Open Browser To Google
    Input Search
    Submit Credentials
    Go Back
    [Teardown]    Close Browser

Output

Robot framework - Test report
Created by - mobilelabs.in

Conclusion

We have seen how to navigate between pages using Robot framework. Coming up next building RPA using robot framework.

Please leave your comments below.