Page Objects / Modules¶
The term Modules can be used as a synonym for Page Objects. The concept and benefits remain the same—creating modular and reusable components that represent different pages or user interfaces of a web application.
In the context of testing frameworks, a Page Object is a design pattern used to enhance the maintainability and reusability of automated tests, particularly in web application testing. It provides an object-oriented approach to represent the different pages or user interfaces of a web application.
The main idea behind the Page Object pattern is to encapsulate the elements, actions, and behaviors of a web page within a dedicated module.
Here are some key aspects and benefits of using Page Objects:
Abstraction of Web Elements: The Page Object encapsulates the object repository (such as buttons, text fields, dropdowns, etc.) present on a specific page. It provides a layer of abstraction, allowing tests to interact with the elements using intuitive methods rather than directly dealing with individual repository objects or HTML tags.
Reusability and Maintainability: By separating the page-specific logic into Page Objects, the code becomes more modular and reusable. Changes in the application's user interface or functionality can be easily handled by updating the relevant Page Object class, rather than modifying the tests themselves.
Improved Readability: Page Objects provide a higher-level representation of the application, making the tests more readable and easier to understand. Test code can be written in a more concise and declarative manner, enhancing collaboration between testers and developers.
Centralized Locators: The Page Object pattern centralizes the locators or selectors used to identify web elements on a particular page. This reduces duplication and allows for easier maintenance if the locators change, as they can be updated in a single location within the Page Object class.
While the typical usage of Page Objects or modules in testing frameworks revolves around encapsulating individual web pages or user interfaces, they can also be expanded to encapsulate groups of functionality within an application. This allows for a more comprehensive and organized approach to testing, including tasks such as navigation through the application.
In addition to representing a single page or UI element, a Page Object or module can be designed to encapsulate a logical grouping of related functionality within the application. This could include a set of pages that are interconnected or share a common purpose, or even a specific workflow or user journey across multiple pages.
For example, consider an e-commerce application that consists of various pages such as a product listing page, product details page, shopping cart page, and checkout page. Instead of creating separate Page Objects for each individual page, a module could be created to encapsulate the entire shopping flow, including navigating between these pages and performing actions related to the shopping process (e.g., adding items to the cart, updating quantities, and completing the checkout).
By encapsulating a group of functionality within a single module, the tests can focus on testing that specific area of the application or a complete workflow. This approach offers several advantages:
Improved Modularity: The encapsulation of related functionality within a module enhances code organization and modularity. It allows for a more cohesive representation of the application's features, making the tests easier to understand and maintain.
Seamless Navigation: The module can provide methods or actions for navigating through different pages or steps within the application. This simplifies the test code by abstracting the navigation logic and makes it more readable and intuitive.
Reusability: Since a module encapsulates a group of functionality, it can be reused across multiple tests or scenarios that involve the same set of features. This promotes code reusability, reduces duplication, and saves effort in maintaining similar test code in different places.
Clearer Test Scenarios: By encapsulating related functionality within a module, test scenarios can be defined more clearly. It becomes easier to create tests that cover specific user journeys or workflows, making the test cases more meaningful and representative of real-world usage.
In summary, while Page Objects or Modules are commonly associated with encapsulating individual web pages, they can be expanded to encapsulate groups of functionality within an application. This approach enhances code organization, simplifies navigation, promotes reusability, and enables clearer test scenarios for comprehensive testing of various application features or workflows.
Page Objects vs Test Cases¶
What are the differences between Page Objects / Modules and Test Cases?
A Test Case typically has a single entry point, while a Page Object may have several action methods.
Test Cases may have a single set of input parameters, whereas Page Objects may have a set of input parameters for each action.
Page Object actions may return a value.
Page Objects can be organized into modules.
Creating a Page Object / Module¶
There are two ways of creating a Page Object (PO) or Module:
- Main menu:
Go to File > Add to Framework > Page Object / Module.
- Right-click on the Page Objects / Modules node in the object tree.
Page Object - RVL vs JS¶
RVL is appropriate in most cases when the module mostly covers some plain scenarios - a set of interactions with the application.
In all other cases, choose RVL.
Adding Page Object Actions¶
When in RVL mode, adding a sheet creates a new action, with the exception of two specific sheets:
RVLsheet, which is the default sheet. It is typically left empty in the Page Object or may contain an internal test executed via the Play this Sheet context menu.
PageObjectsheet, which is the default sheet for the Page Object. It is intended to include a comment with a detailed description of the action, which will be displayed to the user.
Any other sheet is considered an action. The action name should be alphanumeric, meaning it should not contain spaces and should start with a letter or an underscore.
The distinction between a global object and a Page Object lies in their usage and features. Typically, a global object encompasses various functionalities like PDF support, text manipulations, and other utilities. It does not involve an object repository or web services. On the other hand, a page object can include an object repository and is often specific to an application, representing its unique characteristics and functionality.
Action Naming and Reporting¶
The preferred name for an action is
DoAction. When this name is used, the result of the action is checked and reflected in the report. Checking the result involves verifying if the return value is 0,
false, or an empty string, indicating a failed action. The inclusion of the
Do prefix ensures that the result is checked and a line about the action is included in the report.
Alternatively, you can name the action simply as
Action. In this case, the action will not be displayed in the report, although it may have a return value that will not be checked.
It is common to have actions with names like
SetSmth. These actions are meant to update or return a value but are not reflected in the report, similar to the behavior of
In certain situations, you may want to call a
DoAction but ignore its output value and exclude it from the report. To achieve this, you can prefix the action name with an underscore, such as
_DoAction, resulting in an empty execution report.
Description, Parameters and Return Values¶
When creating an action in RVL, it generates necessary placeholders:
- Is an action description. You may see it when choosing an action:
or when hovering over it in the tree:
Parameters. Zero or more. All variable definitions appearing before
ReturnValuevariable assumed to be action parameters. Everything after
ReturnValueare just internal variables needed for given action.
ReturnValue. May contain an action result (you may assign it through the course of the action)
To call a Page Object, you can use
Alternatively, you can invoke a single action for the Page Object itself by using the context menu and selecting "Invoke ActionName()".
For RVL Modules, you can run any part of the module using standard RVL features such as Play Selection or Play this Sheet.
Page Object Recording¶
In RVL mode you do recording just like you do for usual test case with RVL.
Page Object and Web Service¶
When incorporating a Web Service (
When generating a recorded script, it will be placed in the Page Object's
Main.js file, which is not executed. Therefore, you will need to manually copy the generated script from
Main.js and paste it into the appropriate action within the