Selenium Java - 页面对象模型查询 [英] Selenium Java - Page Object Model Query

查看:28
本文介绍了Selenium Java - 页面对象模型查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,有一个页面说 http://google.com/AddUser 在这里你输入详细信息记录并单击保存.执行此操作后,页面将重定向到

Imagine there is a page say http://google.com/AddUser and here you enter details for a record and click save. Once you do this the page redirects to

http://google.com/userList

您可以在其中查看用户列表,包括您刚刚输入的新记录.

where you can see list of users including the new record you just entered.

如果我们通过页面对象模型,输入详细信息和保存记录的方法应该在AddUser.java上,验证记录是否实际保存和显示的方法应该在<代码>UserList.java

If we are going by page object model, the method to enter details and save record should exist on AddUser.java and the method to validate if the record was actually saved and displayed should be on UserList.java

如果我们认为 addUser 和 userList 是两个类的对应对象,则如下所示:

If we consider addUser and userList are the corresponding objects for both classes it will be something like below :

addUser.enterDetailsSaveRecord();

userList.validateSavedRecord();

所以在我的测试用例中,我需要调用 2 个单独的方法,一个用于操作,另一个用于验证.

So in my Test case i would need to call 2 separate methods, one for the action and other to validate.

AddUser.javaUserList.java 都有 BasePage.java 作为超类.有没有办法将它们合并为一种方法,或者我是否以错误的方式进行了某些操作,是否有更好的方法?

Both AddUser.java and UserList.java have BasePage.java as the superclass. Is there a way to club them both into a single method or is there something I'm going about in a wrong way and is there a better approach?

谢谢

推荐答案

使用 PageFactory 你有 2 个 PageObjects 作为 AddUser.javaUserList.java.因此,假设您在调用方法时传递了适当的参数,以下内容对您有用:

Using PageFactory you are having 2 PageObjects as AddUser.java and UserList.java. So assuming you are passing the appropriate arguments while invoking the methods, the following works for you:

addUser.enterDetailsSaveRecord();
userList.validateSavedRecord();

但是来自最佳实践的一句话,断言应该在单独的实用程序/包/类中完成,这与@JeffC 评论类似:

But a word from Best Practices, Assertions should be done in a seperate utility/package/class which is in similar line with @JeffC comment:

最佳实践是将验证代码保留在页面对象之外

因此,您应该创建一个单独的通用实用程序/包/类来处理所有断言.您也可以从 PageObject 类调用包含 Assertionsclass.

Hence, you should be creating a seperate common utility/package/class which will handle all the Assertions. You can call the class containing the Assertions from your PageObject class as well.

所以你的整个测试环境将包含 3 个 Packages.一个包含 main()/@Test 类的包,一个包含 PageObjects 的包,例如AddUser.java 和一个 Utility 包,其中包含用于包含 Assertions 的类,例如 validateSavedRecord().

So your entire Test Environment will contain 3 Packages. One package containing the main()/@Test class, one package containing the PageObjects e.g. AddUser.java and one Utility package with the class for containing the Assertions e.g validateSavedRecord().

这篇关于Selenium Java - 页面对象模型查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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