Android UI testing framework zinc30

Source: Internet
Author: User

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:

 
 
  1. Public class LoginViewPage extends BaseActivityPage {
  2.  
  3. Public LoginViewPage (Zinc zinc ){
  4. Super (zinc );
  5. }
  6.  
  7. @ FindBy (id = R. id. username)
  8. Private AndroidElement usernameEdit;
  9.  
  10. @ FindBy (type = AndroidElementType. EditText, index = 1)
  11. Private AndroidElement passwordEdit;
  12.  
  13. @ FindBy (type = AndroidElementType. Button, text = "login ")
  14. Private AndroidElement loginButton;
  15.  
  16. Public MainViewPage login (String username, String password ){
  17. UsernameEdit. clear ();
  18. UsernameEdit. sendKeys (username );
  19.  
  20. PasswordEdit. clear ();
  21. PasswordEdit. sendKeys (password );
  22.  
  23. LoginButton. click ();
  24. Return new MainViewPage (zinc );
  25. }
  26.  
  27. }

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:

 
 
  1. public class LoginViewTest extends ZincTestCase  { 
  2.  
  3.         public LoginViewTest() { 
  4.                 super("com.baidu.zinc30.sample", LoginView.class); 
  5.         } 
  6.  
  7.         public void testLoginSuccess() { 
  8.                 LoginViewPage loginViewPage = new LoginViewPage(zinc); 
  9.                 MainViewPage mainViewPage = loginViewPage.login("zinc", "zinc"); 
  10.  
  11.                 Assert.assertTrue("should login success", 
  12.                                 mainViewPage.isActivityPresent(MainView.class)); 
  13.         } 

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.

Related Article

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.