Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20



Page Object Model in Selenium Robot Framework Python

In this example, you will learn how to use Page Object Model in Selenium Robot Framework Python test automation. We use RIDE to create Site Element resource file and Test Case. For RIDE example, please see other articles in this category. 


Test Case: authorized users are able to login Mahara Demo site. Here are test steps.

1. Navigate to and verify that web page title "Home-Mahara" displays.

2. Enter "student2" in the Username filed.

3. Enter "Testing1" in the Password field.

4. Click on the Login button

5. Assert that Dashboard Title is "Dashboard - Mahara".

Note: if the above username and password do not work, try registering one and use your own user account for testing because the demo user password may have been changed by others.

Selenium Python Robot Framework Implementation with Page Object Model


Step 1: open command window as administrator and launch RIDE with the command "".  RIDE window will display. Please remember that do not close the command window, or else RIDE will be closed. 

Step 2: Open the existing "LoginModuleTest" explained in the previous article titled "Selenium Robot Framework Python Test Case with RIDE". 

Step 3: Right click on the "LoginModuleTest" and select New Resource. For format, choose "TXT" and enter the resource name as "siteelements"

Step 4: Add the username, password and login button element definition in the "siteelements" resource. 

Step 5: Save the "siteelements.txt" file and add it to the Login as a resource. 

Step 6: Use the site element variable in the "siteelements.txt" resource in keywords: Enter User Name, Enter Password, and Click Login. 

Step 7: Run the Login test and see the result. 

The result showed that Login test passed. This Page Model Object in Selenium Robot Framework makes the UI elements maintenance very easy over time. Whenever a UI changes, we just need to update it in the "siteelements.txt" file and tests should stay untouched. 

Here is the text view of the test framework. 

*** Settings ***
Library           Selenium2Library
Resource          siteelements.txt

*** Variables ***
${Username}       student2
${Password}       Testing1
${Browser}        Firefox
${DashboardTitle}    Dashboard - Mahara
${Delay}          5s

*** Test Cases ***
    Open Browser to the Login Page
    Enter User Name
    Enter Password
    Click Login
    sleep    ${Delay}
    Assert Dashboard Title
    [Teardown]    Close Browser

*** Keywords ***
Open Browser to the Login Page
    open browser    ${SiteUrl}    ${Browser}
    Maximize Browser Window

Enter User Name
    Input Text    ${UserNameTextBox}    ${Username}

Enter Password
    Input Text    ${PasswordTextBox}    ${Password}

Click Login
    click button    ${LoginButton}

Assert Dashboard Title
    Title Should be    ${DashboardTitle}