1. Create a MAVEN project
Successful new project:
Edit Pom.xml, add appium dependent dependencies under <dependencies></dependencies>:
<Dependency><groupId>Org.testng</groupId><Artifactid>Testng</Artifactid><version>6.9.10</version><Scope>Test</Scope></Dependency><Dependency><groupId>Io.appium</groupId><Artifactid>Java-client</Artifactid><version>LATEST</version><Exclusions><exclusion><groupId>Org.seleniumhq.selenium</groupId><Artifactid>Selenium-java</Artifactid></exclusion></Exclusions></Dependency><Dependency><groupId>Com.saucelabs</groupId><Artifactid>Sauce_junit</Artifactid><version>LATEST</version><Scope>Test</Scope></Dependency><Dependency><groupId>Org.seleniumhq.selenium</groupId><Artifactid>Selenium-java</Artifactid><version>2.53.0</version></Dependency><Dependency><groupId>Org.seleniumhq.selenium</groupId><Artifactid>Selenium-remote-driver</Artifactid><version>2.53.0</version></Dependency>
Then add the Appium Special library after <dependencies></dependencies>:
<repositories><Repository><ID>Saucelabs-repository</ID><URL>Https://repository-saucelabs.forge.cloudbees.com/release</URL><releases><enabled>True</enabled></releases><Snapshots><enabled>True</enabled></Snapshots></Repository></repositories>
MAVEN dependencies related jar packages are automatically downloaded after saving
2. Create a new testng class
Right-click to select Com.sun.appiumdemo
Testng->create TestNG Class
The specific code is as follows:
PackageCom.sun.appiumdemo;ImportJava.io.File;Importjava.net.MalformedURLException;ImportJava.net.URL;Importjava.util.List;Importorg.openqa.selenium.By;Importorg.openqa.selenium.WebElement;Importorg.openqa.selenium.remote.DesiredCapabilities;ImportOrg.testng.annotations.AfterClass;ImportOrg.testng.annotations.BeforeClass;Importorg.testng.annotations.Test;Importio.appium.java_client. Appiumdriver;ImportIo.appium.java_client.android.AndroidDriver; Public classAppiumtest { PublicAppiumdriver<webelement>driver; @BeforeClass Public voidStarttest ()throwsmalformedurlexception {File classpathroot=NewFile (System.getproperty ("User.dir")); File Appdir=NewFile (Classpathroot, "Res/app"); File app=NewFile (Appdir, "contactmanager.apk"); Desiredcapabilities Capabilities=Newdesiredcapabilities (); Capabilities.setcapability ("Automationname", "Appium"); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "Android Emulator"); Capabilities.setcapability ("Platformversion", "4.4.2"); Capabilities.setcapability ("App", App.getabsolutepath ()); Capabilities.setcapability ("Apppackage", "Com.example.android.contactmanager"); Capabilities.setcapability ("Appactivity", ". Contactmanager "); Driver=NewAndroiddriver<webelement> (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); } @Test Public voidaddcontact () {webelement El= Driver.findelement (By.xpath (".//*[@text = ' Add contact ']")); El.click (); List<WebElement> textfieldslist = Driver.findelementsbyclassname ("Android.widget.EditText"); Textfieldslist.get (0). SendKeys ("Some Name")); Textfieldslist.get (2). SendKeys ("[Email protected]"); Driver.swipe (100, 500, 100, 100, 2); Driver.findelementbyxpath (".//*[@text = ' Save ']"). Click (); } @AfterClass Public voidAfterclass () {driver.quit (); }}
Create a new Res/app directory under the root of the MAVEN project and place the Android test app in this directory.
Test your application:
Link: Http://pan.baidu.com/s/1skPrdVJ Password: BKVH
3. Create a new virtual machine or run a real machine
The simulator recommends using Genymotion, download the. exe directly, and double-click Install.
Website address: https://www.genymotion.com/download/
:
Link: http://pan.baidu.com/s/1nv3YXZz Password: 3u93
If you want to test with a real machine, then you need to turn on the USB debug mode of the real machine, open the cmd input adb devices command, and return to the device information indicating that the device turned on debugging mode successfully.
4. Start Appium Server
Starts Appium Server, which is used to receive and process requests from the client. Double-click the Appium already installed
Indicates a successful start
5. Execute the test case
Before performing the test use case, make sure that your Android emulator is turned on or that the real machine has turned on USB debugging and connected to the computer and Appium server started successfully. Open Eclipse and open Appiumtest.java, right-click to execute Run as TestNG test, the use case begins to execute
The Appium server will output relevant information
The use case finishes executing.
Three APPIUM Android automated Test experience