A: Appium related environment construction process slightly.
Two: Connect the real machine:
1. Phone (andriod 4.2.2) connect the computer, turn on USB debug mode.
2. Run cmd input adb devices-l view Udid,
3. Enter Appium-a 127.0.0.1-p4723-u4d007e9a1b0050d1 in cmd again (-a means that the ip,-p represents the port,-u means the udid of the device can view more commands by Appium-h)
4. If the Appium service has been successfully started as shown, note that this window is not closed because the service is closed by Appium service, the subsequent process cannot be executed, and this window is also the Log Output window for troubleshooting.
Or, although it is debug, it does not affect the operation of the latter case.
Three: Sample code:
PackageAppdemo.mkws;ImportJava.net.URL;ImportJava.util.concurrent.TimeUnit;ImportJunit.framework.Assert;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.remote.DesiredCapabilities;ImportOrg.openqa.selenium.remote.RemoteWebDriver;ImportOrg.testng.annotations.AfterMethod;ImportOrg.testng.annotations.BeforeMethod;Importorg.testng.annotations.Test; Public classXXXX {PrivateWebdriver Driver; @BeforeMethod Public voidSetUp ()throwsException {//Set up Appium//file Classpathroot = new file (System.getproperty ("User.dir")); //file Appdir = new file (classpathroot, "Apps/contactmanager"); //file app = new file (appdir, "contactmanager.apk");Desiredcapabilities capabilities =Newdesiredcapabilities (); Capabilities.setcapability ("DeviceName", "XX");//xx can be the model of the mobile phone capabilities.setcapability ("Browsername", "Chrome"); Capabilities.setcapability ("Platformversion", "4.2.2"); Capabilities.setcapability ("PlatformName", "Android"); Driver=NewRemotewebdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); Driver.manage (). Timeouts (). Pageloadtimeout (2, timeunit.minutes);//page load time-outDriver.manage (). Timeouts (). implicitlywait (2, timeunit.minutes); } @AfterMethod Public voidTearDown ()throwsException {System.out.println ("End"); Driver.quit (); } @Test Public voidget () {Driver.get ("url");//Enter the URL to go to Driver.findelement (By.id ("Ctl00_tkshared_header_txtheadersearchbox")). SendKeys ("Fan")); Driver.findelement (By.xpath ("//a[@class = ' tk_searchbtn btn btn-default ']") . Click (); String a=driver.findelement (By.id ("ctl00_maincontentarea_ctl00_ctl00_ctl00_ucsearchcontrol_myresults_entrieslist_ctrl0 _ctl00_hlnkproductname ") . GetText (); Assert.assertequals ("Sandalwood Fan", a); } }
Using Appium to do Android mobile Web Automation test real-Computer demo