Martin Fowler Basic rules of thumb for using page objects for Web testing

Source: Internet
Author: User
Tags html page

From Martin Fowler, the article was originally translated by ThoughtWorks engineer Bowen on his blog and recommended by the translator to the Infoq Chinese station blog for a column. With the permission of Martin Fowler himself, the Infoq Chinese language station has been revised and is here to share.

When you are writing a test for a Web page, you need to manipulate the elements on the Web page to click on the link or validate the displayed content. However, if you manipulate HTML elements directly in your test code, your code is vulnerable because the UI changes frequently. A Page object can encapsulate an HTML page or part of a page, and you can manipulate page elements with the application-specific APIs provided, without the need to search around in HTML.

A basic rule of thumb for the Page object is that the Page object can be done by the software client, whatever the human could do. It should also provide an easily programmable interface and hide the lower parts of the window. So accessing a text box should be done using an access method (accessor methods) to get and return the string, the checkbox should use a Boolean value, and the button should be represented as a behavior-oriented method name. The Page object should encapsulate the behavior of all query and manipulation data on a GUI control as a method. A good rule of thumb is that even if you change the control, the Page object's interface should not change.

Although the term is a "page" object, it does not mean creating an object for each page, such as a page with significant elements that can be independent of a Page object [1]. So, a page that displays multiple albums can have an album page object that contains several photo album page objects. There may also be a header Page object and a Footer Page object. That is, if the hierarchy of some complex UI is used to organize the UI, then it should not be related to the Page object. The rule of thumb is to make it meaningful to the users of the application by modeling the page.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.