Is JavaScript compatible with strict Page Object Pattern?

♀尐吖头ヾ 提交于 2019-12-07 02:34:54

问题


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?


回答1:


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




回答2:


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




回答3:


If you use Jetbrains products like IntelliJ IDEA it will do a code completion and ther proper navigation for you. In javascript world page object is a known pattern too. AngularJs offers it too in it's own e2e test framework (http://www.protractortest.org/#/page-objects). Personally I use IIFE for page objects and IntelliJ does the rest. If it doesn't fit to your needs you can still choose typescript and transpile it to javascript.



来源:https://stackoverflow.com/questions/41960059/is-javascript-compatible-with-strict-page-object-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!