如何在PageObjects模式中使用WebDriver / Selenium 2 LoadComponents? [英] How to use WebDriver / Selenium 2 LoadComponents in PageObjects pattern?

查看:144
本文介绍了如何在PageObjects模式中使用WebDriver / Selenium 2 LoadComponents?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难习惯使用WebDriver PageObject模式。请分享您使用PageObjects pattern和loadableComponents的经验和方式。



由于PageObject通常是一个组件或功能,所以我首先要使用它实际上在load()中做一些事情,看看它是否在isLoaded()中执行它。



然后我意识到它应该仅用于加载对象(可能是初始化),因为它是在网站周围移动的情况下,每个对象都有自己的url。并且使用isLoaded()来测试对象是否准备好进行测试。



但是如果您有一个复杂的JavaScript订单提交程序进行测试,那就是JS文件上传器的组合,基于2个独立部分的JS表单,有三种订单,你不会移动任何地方(关于URL),只是元素的状态正在改变。



考虑get()方法。您可以使用交互式表单进入页面。当页面上存在表单时,它被加载。那么你有form1和form2对象...他们的load()和isLoaded()方法应该是什么样的,他们可以立即准备好采取行动,因为他们不需要任何加载,只是测试他们的服务。



这是一个烂摊子,不知道是否使用isLoaded()方法来检查是否加载了对象,还是加载了对象,并且正确安装了对象。但是我猜想以前的方法是正确的,在测试中应该确保设置的有效性。



场景:

 测试html表单的第一部分 - 测试字段客户端验证工作
测试依赖于第一个的第二个
测试以下文件上传器 - 上传,取消,清算,订单,fileID
测试整体html表单提交 - ServerSide验证错误,结果

文档说:




  • LoadableComponent

  • PageObjects


    1. 公共方法表示页面的服务提供



      验证,上传,上传多个,取消,清除


    2. 尽量不要构成页面的内部



      发生在我身上的唯一的事情是将UnitTests隐藏到Driver实例,并且只使用PageObjects来保留所有的字段名称,css PageObjects中的类名称提供具有输入数据的PageObjects和assert服务/功能的布尔值结果


    3. 方法返回其他PageObjects



      这是最困难的事情习惯。有一个交互式表单的4个页面对象不自然。他们推荐Form1,Form2(Form1),Upload(Form2),Submit(Upload),虽然我发现链接和提交给前面的对象非常混乱。在测试方法中调用所有的get()似乎更好。但是我猜想它背后的想法不是将Driver实例暴露给Tests,而只能使用内部使用Driver实例的PageObjects。


    4. 相同动作的不同结果被建模为不同的方法
      我认为这意味着不应该在页面对象方面决定该动作的有效性,而是在测试方面




解决方案

可加载组件页面对象模式的扩展。 WebDriver库中的LoadableComponent类将帮助测试用例开发人员确保页面或页面的组件成功加载。它大大减少了调试测试用例的努力。页面对象应该扩展此可加载组件抽象类,因此它必须为以下两种方法提供实现:



protected abstract void load )



protected abstract void isLoaded()throws java.lang.Error



必须在load()和isLoaded()方法中加载的页面或组件确定页面是否完全加载。如果没有完全加载,它会引发错误。



https:// code。 google.com/p/selenium/wiki/LoadableComponent


I have a hard time to get used to the WebDriver PageObject pattern. Please share your experience and ways of using PageObjects pattern and loadableComponents.

As PageObject represents usually a component or piece of functionality, it occurred to me at first that I should use it to actually do some things in load() and see if it does what it should in isLoaded().

Then I realized that it should be utilized only for "loading" objects (possibly initialization) as it is in case of moving around a website, each object with its own url. And using isLoaded() to test whether the object IS READY for testing.

But if you have a complex JavaScript order submitter to test, that is compound of JS file uploader, JS form that is based on 2 independent parts and there are three kinds of Orders, you don't move anywhere (regarding URL), just the state of elements is changing.

Consider the get() method. You get into the page with the interactive Form. It is loaded when the form exist on the page. Then you have form1 and form2 objects ... what should their load() and isLoaded() method look like, they are ready for action right away because they don't need any loading, just testing their services.

It's a mess, one doesn't know if the isLoaded() method is used for checking whether object loaded, or whether object loaded and was setup properly. But I guess the former way is correct and that validity of setting it up should be ensured within the tests.

Scenario:

Testing first part of html form - test that field client side validation works
Testing the second one that depends on the first one
Testing the following file uploader - upload, canceling, clearing, order, fileIDs
Testing the overall html form submission - ServerSide validation errors, results

The documentation says :

  • LoadableComponent
  • PageObjects

    1. The public methods represent the services that the page offers

      Validate, upload, upload Multiple, cancel, clear

    2. Try not to expose the internals of the page

      The only thing that occurs to me is having Driver instance hidden to UnitTests and use Only PageObjects to keep all field names, css class names in PageObjects + supply PageObjects with input data and assert boolean result of the services/functionality

    3. Methods return other PageObjects

      This is the most difficult thing to get used to. Having 4 page objects for one interactive form kinda doesn't feel natural. They recommend Form1, Form2(Form1), Upload(Form2), Submit(Upload), although I find the chaining and handing over a reference to the preceding object very chaotic. Calling get() on all of them in a test method seems better. But I guess that the idea behind it is not to expose the Driver instance to the Tests, but use only PageObjects that are using Driver instance internally

    4. Different results for the same action are modelled as different methods I suppose that this means that it shouldn't be decided about validity of that action on the Page object side, but on the Test side

解决方案

The loadable component is an extension to the Page Object pattern. The LoadableComponent class in the WebDriver library will help test case developers make sure that the page or a component of teh page is loaded successfully. It tremendously reduces the efforts to debug your test cases. The page object should extend this Loadable Component abstract class and as a result, it is bound to provide implementation for the following two methods:

protected abstract void load()

protected abstract void isLoaded() throws java.lang.Error

The page or component that has to be loaded in the load() and isLoaded() methods determines whether or not the page is fully loaded. If it is not fully loaded, it throws an error.

https://code.google.com/p/selenium/wiki/LoadableComponent

这篇关于如何在PageObjects模式中使用WebDriver / Selenium 2 LoadComponents?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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