Using Appium to do Android mobile Web Automation test real-Computer demo

Source: Internet
Author: User
Tags appium testng

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

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.