Author: Zhou Hongfei, Han Jun.
1. Background: challenge we met during test automation, based on the design pattern of page object.
Currently design pattern of page object is commonly used in Web UI automation. Page object is considered as the atomic element in UI test cases, which contains static web elements in the page, along with the internal page behavior.
As is shown in Figure 1, there is a UI TestPlan (test suite), which is composed of three different test methods. In each test method, there are flows and internal page behaviors. Internal page behavior is a part of page object and defines the concise steps user made in the very page. Since these steps can be re-used, they’re encapsulated in the internal page behavior.
Flow contains a series internal page behavior and some other steps, triggered by web element method directly.
Figure 1 Test Plan component in Web Automation
No assertions will be written in flow or internal page behaviors, for the purpose of making them more re-usable. Assertion is written according to the verification points, mentioned in the test case doc. Assertion needs to be changed when there’s any change in the test case.
If putting assertion into flows or internal page behaviors, it requires a large amount of effort for automation code maintain later on. If not, here comes the challenge how to deal with the situation when QA want to test some verification points during steps in flow. Action mechanism is designed to address the challenge.
2. Solutions: utilize Action mechanism to address the challenge.
As described in Figure 2, there is a single flow, which covers the steps through Page 1, Page2 to Page 3. Some assertions need to be made on each page respectively. But for the sake of code re-use, assertions are not provided in either internal page behavior or flow itself.
To address the requirement, two Actions are created with relative assertions and customized steps for specific pages. When flow goes to Page 1, assertions and customized steps in Action 1 will be invoked. When it goes to Page 3, extra actions in both Action 1 and 2 will be invoked automatically.
When verification points (VP) in test cases are changed, what QA need to modify is just Action class (Action1, 2, etc.). As for Flow, internal page behavior in page object keeps the same. This dramatically saves the effort for code change when there are VP changes in test case.
Figure 2 Internal Page Behavior and external Action in one Single Flow
3. How to implement Action mechanism?
Action mechanism is implemented by adopting Java Reflection feature. As is described in Figure 3, Action class and Action Invoker are the two important components in Action mechanism system.
Figure 3 implementation of Action Mechanism
Assertions and customized steps are designed and encapsulated into different Action class, defined by QA. All of them extend to the super class as ‘Action’.
As for the definition of Assertions and customized steps, take the test scenario below for example.
User need to click a button, which triggers a pop up window. And then the text field and dropdown list in the pop up window need to be verified.
In this case, Assertions are referred to the verification of text field and dropdown list in the pop up window.
Customized steps are referred to the steps made by user to click the button.
Different action method is written by QA for different pages, and the input parameter (PageObject) defines which page the assertions and customized steps happen on.
Action Invoker is the other important component in Action mechanism system. Java reflection is applied to implement the listener feature. In this case, Action Invoker knows which action method to invoke, according to the input parameter as PageObject type.
Detailed algorithm is described as below,
- Firstly Action Invoker get the input class types.
- Action Invoker takes an array of Action classed and does ‘for loop’ iteration.
- During the iteration of all Action classes, it looks for the method whose method name = ‘Actions’, and parameter type=’Object’.
- If ‘void action (PageObject)’ is found, invoke it to make proper assertions with customized steps.
4. Conclusion: future benefits of adopting Action mechanism in test automation.
Web UI Automation is commonly used in a lot of online commerce companies to save efforts made by manual test. With frequent test case changes, it is always a challenge about how to deal with the automation code change.
Action mechanism is an innovated approach to address the challenge. By adopting it, stable steps in the pages (internal page behavior) can be separated with assertions and customized steps (Action class). It dramatically saves the code change effort.
* 本文版权和/或知识产权归eBay Inc所有。如需引述,请和联系我们DL-eBay-CCOE-Tech@ebay.com。本文旨在进行学术探讨交流,如您认为某些信息侵犯您的合法权益,请联系我们DL-eBay-CCOE-Tech@ebay.com,并在通知中列明国家法律法规要求的必要信息,我们在收到您的通知后将根据国家法律法规尽快采取措施。