JavaScript是否与严格的页面对象模式兼容? [英] Is JavaScript compatible with strict Page Object Pattern?

查看:197
本文介绍了JavaScript是否与严格的页面对象模式兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Page Object Pattern with Java构建了各种Test Automation框架( https://code.google。 com / p / selenium / wiki / PageObjects )。

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

我发现的两大好处是:

1)当你有一个页面实例时,你可以看到可用的方法(例如输入主页。将显示你可以从主页调用的所有动作/方法)

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)因为导航方法(例如goToHomepage())返回后续页面的实例(例如主页),所以只需编写代码并查看它所在的位置即可浏览测试。

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.

例如

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

这些好处与Java完美配合,因为对象的类型(或本例中的页面)是已知的IDE。

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

但是,使用JavaScript(动态类型语言),对象类型在任何时候都不固定,并且通常与IDE不明确。因此,我无法看到如何在使用JavaScript构建的自动化套件中实现这些优势(例如,使用Cucumber)。

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).

任何人都可以告诉我如何使用JavaScript页面对象模式可以获得这些好处吗?

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

推荐答案

我对这种模式并不多。但我会提供一些细节,也许它对你有所帮助。
http: //www.guru99.com/page-object-model-pom-page-factory-in-selenium-ultimate-guide.html

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 /

实现此目的的一个好方法是使用 TypeScript (这是 JavaScript 的静态类型版本:

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

这篇关于JavaScript是否与严格的页面对象模式兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆