Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JavaScript compatible with strict Page Object Pattern?

I have built various Test Automation frameworks using the Page Object Pattern with Java (https://code.google.com/p/selenium/wiki/PageObjects).

Two of the big benefits I have found are:

1) You can see what methods are available when you have an instance of a page (e.g. typing homepage. will show me all the actions/methods you can call from the homepage)

2) Because navigation methods (e.g. goToHomepage()) return an instance of the subsequent page (e.g. homepage), you can navigate through your tests simply by writing the code and seeing where it takes you.

e.g.

WelcomePage welcomePage = loginPage.loginWithValidUser(validUser);
PaymentsPage paymentsPage = welcomePage.goToPaymentsPage();

These benefits work perfectly with Java since the type of object (or page in this case) is known by the IDE.

However, with JavaScript (dynamically typed language), the object type is not fixed at any point and is often ambiguous to the IDE. Therefore, I cannot see how you can realise these benefits on an automation suite built using JavaScript (e.g. by using Cucumber).

Can anyone show me how you would use JavaScript with the Page Object Pattern to gain these benefits?

like image 481
Charlie Seligman Avatar asked Jan 31 '17 14:01

Charlie Seligman


People also ask

What is POM in Javascript?

The Page Object Model (POM) is a design pattern that can be used with Selenium with any kind of framework. Using this pattern for tests means that you create two separate types of classes; Pages and Test Cases.

Does Cypress Use Page Object Model?

Page Object Model is the most commonly used method in test automation for Web testing. So Cypress also allows the usage of the Page Object Model.

What is a page object pattern?

What is Page Object Model in Selenium? Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance.


2 Answers

From Gerrit0's comment above and investigating it further, it seems a great way to achieve this is to use TypeScript (which is a statically typed version of JavaScript):

https://en.wikipedia.org/wiki/TypeScript

like image 174
Charlie Seligman Avatar answered Oct 11 '22 16:10

Charlie Seligman


I am not much about this patterns.but i will give some details maybe it helps to you. http://www.guru99.com/page-object-model-pom-page-factory-in-selenium-ultimate-guide.html

http://www.assertselenium.com/automation-design-practices/page-object-pattern/

It seems a great way to achieve this is to use TypeScript (which is a statically typed version of JavaScript):

https://en.wikipedia.org/wiki/TypeScript

like image 27
bob marti Avatar answered Oct 11 '22 16:10

bob marti