In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the Android UI testing framework zinc30, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Zinc30 is a powerful Android UI automated testing framework that supports the establishment of robust and maintainable black box test cases. RD or QA can design functional and system-level tests based on scenarios. Zinc30 conforms to the API specification of Webdriver, operates Android controls in a better object-oriented programming way, and fully supports the popular PageFactory pattern in Web UI testing.
Project address: https://code.google.com/p/zinc30/
GettingStart
To use Zinc30, you need to put the zinc.jar package into Android Test Project and add it to build path, and you need to add it under the manifest element of AndroidManifest.xml:
For the sample project using Zinc30, please download the zinc30-sample.zip package in the downloads area, which contains two projects. Zinc30-sample is the tested project, which is written in mvp mode, and zinc30-sample- test is the test project, which uses PageFactory mode to write test cases. Two projects can be run directly after they are imported into eclipse.
Sample demonstration
Here to test the login function as an example, if there are two Activity, one of which is LoginView, mainly the landing page, and the other is MainView, which is mainly the page that jumps after landing successfully. Here, we also use 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 page mainly includes the elements and actions that need to be operated during the test, in which there are three methods to find the elements:
1. Find it according to id, that is, the id value in the automatically generated R file
2. To find according to the text, you need to take the element type with you. For example, @ FindBy (type = AndroidElementType.Button, text = "login") is to find the Button control with the login text written on it. If the element type is uncertain, you can use the Unkown type
3. To look up according to the index, you need to take the element type. For example, @ FindBy (type = AndroidElementType.EditText, index = 1) is to find the second EditText control. Here index identifies * * elements with 0.
Next, let's take a look at how Test Case writes. In fact, Test case mainly combines existing ActivityPage classes:
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));}
When we write test cases, we need to inherit ZincTestCase, which mainly completes the initialization of zinc objects. Although zinc objects can be used in the Test Case layer, we encourage operations to be encapsulated in the ActivityPage layer.
Zinc30 fully supports the PageFactory pattern because it has three advantages:
1) reduce repetitive code and encapsulate the change and migration of page state in the page object
2) the change of UI will only affect the corresponding page object, but not the upper test case.
3) be able to reuse page objects in different test case.
For some operations that are not in WebDriver's API, such as swiping the screen, clicking on a line in Listview, or returning to the previous page, we directly zinc the object in the ActivityPage layer, which is fully compatible with all the actions of Robotium.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.