Background
The company's products business has developed to the mobile side, the development of the selection has ended, decided to use PHONEGAP Mobile Web application development platform. Considering the complexity and diversity of the business, mobile-side testing also needs to be automated. Read a lot on the net, finally locked up 3 Mobile test tools: Selendroid,appium,robotium. 3 of them are chosen because the team already has a selenium-based testing framework, and these three tools and selenium can be said to be same strain.
Goal
PhoneGap-based hybrid app (hybrid app) Web application mobile End Automation test
Selection process
Selendroid (Abort)
Give up selendroid reason is in accordance with the official website of the tutorial operation, run the test, error, take the error in the online query, the results are not resolved. The poor data, and later saw Appium integrated selendroid, decisively give up.
Robotium (Abort)
In fact robotium in the process of trying is the most smooth one, the function is also powerful.
But it only supports Android devices, and it's hard to integrate it into the existing framework of the company's team in the way Android test works, so it's abandoned.
But still will pay attention to its development, the community is active, the work can be profound have a lot of place that can learn from. It also played a great role in the study of Appium.
Appium (selected)
Appium supports iOS and Android devices, supports the hybrid app, integrates selendroid, is easy to integrate into the company's existing framework, the community is forming, and documentation is plentiful.
Although there are twists and turns in the course of the experiment, it has also been successfully implemented in the end.
Hybrid app builds an automated test development environment with Appium
Appium
Official website: http://appium.io/
Chinese community: http://testerhome.com/
(provided by Testerhome Community): Http://pan.baidu.com/s/1jGvAISu#dir
1. Download the latest version Appiumserver 1.2.0, after decompression, enter the directory to find Appium.exe, run can, this program as Appnium and the device under test communication between the server
The following interface is shown to start successfully
2. Connect the real machine to the PC side
3. I use eclipse as a development IDE to create a MAVEN engineering Appium-demo that references the Selenium core project in the company framework in Pom, which eliminates the process of adding selenium dependencies
, and find the Appium package in the central repository of MAVEN, and reference
Appium's MAVEN reference
GroupId:io.appium
Artifactid:java-client
version:1.5.0
4. Once the project is established, it is possible to write the test code and create a JUnit test class Test1.java in the project with the following code:
PackageCom.example.hello;Importio.appium.java_client. Appiumdriver;ImportJava.io.File;Importjava.net.MalformedURLException;ImportJava.net.URL;ImportJava.util.Set;Importjunit.framework.TestCase;ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;ImportOrg.junit.runners.BlockJUnit4ClassRunner;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.JavascriptExecutor;Importorg.openqa.selenium.WebElement;Importorg.openqa.selenium.remote.DesiredCapabilities; the @RunWith (Blockjunit4classrunner.class) Public classTest1extendsTestCase {PrivateAppiumdriver driver; @Before Public voidStart ()throwsmalformedurlexception {//Hybrid app path packaged with PhoneGapString AppPath = "d:\\work\\codes\\hands\\hands-hello-phonegap\\platforms\\android\\bin\\helloworld.apk"; //Initialize AppniumdriverDesiredcapabilities capabilities =Newdesiredcapabilities (); Capabilities.setcapability ("DeviceName", "nx403a");//real-machine test Android deviceCapabilities.setcapability ("Platformversion", "4.2.2");//Real Android version for 4.2.2Capabilities.setcapability ("PlatformName", "Android");//Real machine for Android systemCapabilities.setcapability ("App", AppPath);//the location of the app under test APK packageCapabilities.setcapability ("Apppackage", "Com.example.hello");//package of activity class for the app under testCapabilities.setcapability ("Appactivity", ". HelloWorld ");//activity class of the app under testCapabilities.setcapability ("Automationname", "selendroid");//because the real machine is version 4.2, use selendroid// http://127.0.0.1: 4723/wd/hub address is the address of AppiumserverDriver =NewAppiumdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); } @Test Public voidMain () {Try{Set<String> Contextnames =Driver.getcontexthandles (); for(String contextname:contextnames) {System.out.println (contextname);//used to return the app being tested is Native_app or webview, if both have a hybrid app} thread.sleep (5000);//wait for it for a while .Driver.context ("Webview_0");//let Appium switch to WebView mode to find web elementsWebelement Text_baidusearch = driver.findelement (By.id ("word")); Text_baidusearch.click ();//Click on Baidu's Search input box (web Element) /** Appium does not support the Chinese input reference robotium the method of setting value directly for the element in JS * * using selenium Webdriver Execution JS methods to achieve Chinese input */javascriptexecutor JSE=(javascriptexecutor) driver; Jse.executescript ("document.getElementById (' word '). Value= ' Input method '"); Thread.Sleep (10000);//wait a minute, watch the effect .}Catch(interruptedexception e) {e.printstacktrace (); }} @After Public voidStop () {driver.quit (); }}
The engineering structure is as follows
5. Keep the device under test unlocked, although Appium has a unlock function, but sometimes it doesn't work, so it's best to turn the lock screen off. Run Test1.java to get the following results