Zinc30 is a powerful Android UI automated testing framework that supports the establishment of robust and maintainable black box testing cases. RD or QA can design function-level and system-level tests based on scenarios. Zinc30 complies with the Webdriver API specification and operates Android controls in a better way to program objects on the ground. It also fully supports the PageFactory mode popular in Web UI testing.
Project address: https://code.google.com/p/zinc30/
GettingStart
To use Zinc30, you need to add the zinc. jar package to the Android Test Project and build path, and add it to the manifest element of AndroidManifest. xml:
For sample projects that use Zinc30, download the zinc30-sample.zip package in the downloads area, which contains two items, the zinc30-sample is the tested project, written in mvp mode; The zinc30-sample-test is the test project, use PageFactory mode to write test cases. Import the two projects to eclipse to run them directly.
Example
Here, we take the test login function as an example. Assume that there are two activities, one of which is LoginView, mainly logon page, and the other is MainView, which is the page to jump to after successful login. Here we also use the PageFactory mode to write, first write ActivityPage:
- Public class LoginViewPage extends BaseActivityPage {
-
- Public LoginViewPage (Zinc zinc ){
- Super (zinc );
- }
-
- @ FindBy (id = R. id. username)
- Private AndroidElement usernameEdit;
-
- @ FindBy (type = AndroidElementType. EditText, index = 1)
- Private AndroidElement passwordEdit;
-
- @ FindBy (type = AndroidElementType. Button, text = "login ")
- Private AndroidElement loginButton;
-
- Public MainViewPage login (String username, String password ){
- UsernameEdit. clear ();
- UsernameEdit. sendKeys (username );
-
- PasswordEdit. clear ();
- PasswordEdit. sendKeys (password );
-
- LoginButton. click ();
- Return new MainViewPage (zinc );
- }
-
- }
As you can see, this Page mainly includes the elements and actions that need to be operated during the test. Element search has three methods:
1. Search by id, that is, the id value in the automatically generated R file;
2. Search by text. The element type must be included. For example, @ FindBy (type = AndroidElementType. Button, text = "login") is the Button control for searching and writing login text. If the element type is unknown, the Unkown type can be used;
3. Search by index. The element type must be included. For example, @ FindBy (type = AndroidElementType. EditText, index = 1) is used to find the second EditText control. Here, index marks the first element with 0.
Next let's look at how to write Test Case. In fact, Test case mainly combines the existing ActivityPage class:
- public class LoginViewTest extends ZincTestCase {
-
- public LoginViewTest() {
- super("com.baidu.zinc30.sample", LoginView.class);
- }
-
- public void testLoginSuccess() {
- LoginViewPage loginViewPage = new LoginViewPage(zinc);
- MainViewPage mainViewPage = loginViewPage.login("zinc", "zinc");
-
- Assert.assertTrue("should login success",
- mainViewPage.isActivityPresent(MainView.class));
- }
- }
We need to inherit ZincTestCase when writing test cases, which mainly completes zinc object initialization. Although zinc objects can be used on the Test Case layer, we encourage you to encapsulate operations in the ActivityPage layer.
Summary
Zinc30 is fully supporting PageFactory mode can be referred to: http://chon.techliminal.com/page_object/#/intro), because it has three advantages:
1) reduce repeated code, and encapsulate changes and migration of Page Status in page objects;
2) changes to the UI will only affect the corresponding page object, but will not affect the test case of the upper layer;
3) page objects can be reused in different test cases.
Some operations are not in the WebDriver API, such as sliding the screen, clicking a row in the Listview, or returning to the previous page. We directly use the zinc object on the ActivityPage layer, which is fully compatible with all actions of Robotium.