How to implement Page object Model in Robot Framework

Page Object Model in Robot Framework



Page Object Model: In short it is pom. POM is more of putting all the actions and attributes of a specific page together. Which helps increase maintainability, modularity and reusability.

We can implement POM in Robot Framework. Which will be very helpful to maintain the project when many people are working on same project.
Here is the snapshot on how you can create your directory structure,


Lets get into section by section,

Tests:
I would suggest to write similar or related user journeys in same file as different test cases. If we follow such process then business analysts also can write user stories / test cases and give to QA team. And QA team can use the same files to implement with out modifying many things or write completely new test cases. You can just import the required files to the testcase robot file

Using the `Resource` word, you can import all the required robot files where you have implemented keywords for the pages


Keywords:
As we are implementing POM in robot framework, keep individual page activities in individual robot files. Write all the activities of the page as keywords with proper naming, so that it can be easily understandable to others.

If you observe the `Settings` section,
  • I have imported AppiumLibrary (has all keywords that you can use in mobile automation) using `Library`
  • `Base.Robot` using `Resource` because it is user defined library( or a .robot file, which contains user defined keywords)
  • I have imported a python file using `Variables`. This python file contains all the element locators of this page.Once you import the python file which has the required element locators, you can use the variables using ${variable_name} as shown in the picture. You can use directly or first you can add to `Arguments` section and use it

Locators:
(Optional, better to keep the element locators with in the Page keywords file)
I have created a different directory for maintaining the element locators in robot framework. Just import to the respective page keyword file using `Variables ..`. Its up to you, if it is really necessary to make a separate file you can do this, else you can place the element locators in the same keyword file under `Variables section` where you have implemented the page.

utils:
Im using this directory to place configuration related / global variables that are common or reusable. Variables like application url, db url, port numbers or some constants.


Implementing POM in robot framework is very simple. Isn’t it?



Thanks for reading. Happy learning. Please post a comment if you don’t understand any point or if you find anything incorrect. Thankyou.

Please Subscribe for more helpful articles.

Comments