2

I need to develop reusable POM with Page Factory for dependent Scenarios. How I can use minimal time and memory for filling up POM with Page Factory.

General idea:

Scenario1:
Given Do something NUM1
When Do Something NUM2
And Do Something NUM3

Scenario2:
Given Do something NUM4.
When Do Something NUM5.
And Do Something NUM6.

Scenario 3
.....

: Remember all scenarios are dependent. And every sentence is in different step deffinition file(different class).

Assume that StepDefinition for "Do SomethingNUM 3,5, and 6 will use the same POM (visit same page) but they are in different classes.

With conventional model I will call constructor for these three classes and will initialize same POM 3 times (in realality it could be 1000 times). So,I think that there is a way to save some time by creating POM just once for all of these three clases.

On the other hand if I create (store) 5000 element am i dealing with performance or memory issues? (I assume that memory is not the issue,and I am willing to secrefise it so I can save the execution time)

Can I fill the POM just in one class, and then use it in other classes with all the elements inside it. I have some ideas how it might work, but I need someone that already have same issue.

Gaj Julije
  • 646
  • 4
  • 24
  • 1
    Just for clarity... POM is page object model. At a high level, it is a way of organizing locators and methods into a class per page/widget where the class itself is called a page object. When you use POM in your question, you are actually referring to a page object. – JeffC Nov 06 '20 at 17:18
  • The Selenium contributors recommend against using Page Factory. Here's Simon Stewart, Selenium project lead and creator of Page Factory, at a Selenium Conference... https://youtu.be/gyfUpOysIF8?t=1518. If you create your page objects in such a way that you don't initialize any elements when the class is instantiated, you shouldn't have any performance issues. – JeffC Nov 06 '20 at 17:27
  • 2
    And yet another point... don't try to create one instance of your page object that is used for more than one test. Doing this will prevent parallel execution and you want parallel execution if you are going to run more than a few tests. Best practices are to create each test to be run independently and in any order. – JeffC Nov 06 '20 at 17:30
  • 1
    You will need to set up a dependency injection framework in order to initialize one page object per test. – Greg Burghardt Nov 06 '20 at 23:42
  • 1
    See https://cucumber.io/docs/cucumber/state/#dependency-injection – Greg Burghardt Nov 06 '20 at 23:43
  • @GregBurghardt tere is a lot things in documentation, but not sure what is the reccomendation – Gaj Julije Nov 07 '20 at 16:45
  • @GajJulije I believe you can find a clue [here](https://www.webelement.click/en/cucumber_java_8_selenium_pageobject_picocontainer_tutorial). This is example of how to use DI for cucumber and selenium when you implement Page Object, so that you initialize all your objects once per scenario. This demonstrates `cucmber-java8`. It has to be easier in regular cucumber syntax. – Alexey R. Nov 08 '20 at 20:17
  • Take a look at this https://stackoverflow.com/questions/57478175/design-issue-in-cucumber-spring-webdriver-quit-in-after-method/57523697#57523697 May help – Rahul L Nov 09 '20 at 05:08

0 Answers0