Appium for mobile web use Chromedriver

Source: Internet
Author: User

Android Client Login: http://www.cnblogs.com/tobecrazy/p/4579631.html

Appium implementation and emptying edittext:http://www.cnblogs.com/tobecrazy/p/4592405.html

Appium Slide Handling: http://www.cnblogs.com/tobecrazy/p/4612133.html

Recently someone asked me how to use Web driver, so I'm going to look into

Preparatory work: 1. Install Chrome

Writing code

 PackageCom.dbyl.core;Importorg.apache.commons.io.FileUtils;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.OutputType;ImportOrg.openqa.selenium.TakesScreenshot;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.remote.CapabilityType;Importorg.openqa.selenium.remote.DesiredCapabilities;ImportOrg.testng.Assert;ImportOrg.testng.annotations.AfterClass;ImportOrg.testng.annotations.BeforeClass;Importorg.testng.annotations.Test;ImportIo.appium.java_client.android.AndroidDriver;ImportJava.io.File;Importjava.io.IOException;ImportJava.net.URL;ImportJava.util.concurrent.TimeUnit; Public classBaidu {Androiddriver<WebElement>driver; /**     * @authorYoung *@throwsIOException*/     Public voidStartrecord ()throwsIOException {Runtime rt=Runtime.getruntime (); //This code for record the screen of your deviceRt.exec ("cmd.exe/c adb shell Screenrecord/sdcard/runcase.mp4"); } @BeforeClass (Alwaysrun=true)     Public voidSetUp ()throwsException {//Set up AppiumDesiredcapabilities Capabilities=Newdesiredcapabilities (); Capabilities.setcapability (Capabilitytype.browser_name,"Chrome"); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "Android Emulator"); Capabilities.setcapability ("Platformversion", "4.4"); Driver=NewAndroiddriver<webelement> (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities);    Startrecord (); } @Test Public voidRunchromewebbrowser () {Driver.get ("Http://www.baidu.com"); Driver.manage (). Timeouts (). Implicitlywait (20, Timeunit.seconds); Driver.manage (). Timeouts (). Pageloadtimeout (20, Timeunit.seconds);        System.out.println (Driver.gettitle ()); Snapshot (takesscreenshot) driver,"Before_search.png"); Driver.findelementbyxpath ("//textarea[@id = ' index-kw ']"). SendKeys ("Appium"); Driver.findelement (By.xpath ("//button[@id = ' index-bn ']") . Click (); Driver.manage (). Timeouts (). Pageloadtimeout (20, Timeunit.seconds);        System.out.println (Driver.gettitle ()); Snapshot (takesscreenshot) driver,"After_search.png"); Assert.asserttrue (Driver.gettitle (). Contains ("Appium")); }    /*** This Method of Create for Take screenshot * *@authorYoung *@paramdrivername *@paramfilename*/     Public Static voidSnapshot (takesscreenshot drivername, String filename) {//This method would take the screen shot, require, and parameters, one is//driver name, another is file nameString Currentpath= System.getproperty ("User.dir");//Get Current work//folderFile Scrfile =Drivername.getscreenshotas (Outputtype.file); //Now you can do whatever need to do with it, for example copy//somewhere        Try{System.out.println ("Save Snapshot Path is:" + Currentpath + "/" +filename); FileUtils. CopyFile (Scrfile,NewFile (Currentpath + "\ \" +filename)); } Catch(IOException e) {System.out.println ("Can ' t Save screenshot");        E.printstacktrace (); } finally{System.out.println ("Screen shot finished, it's in" +Currentpath+ "Folder"); }} @AfterClass Public voidAfterteststopdriver () {driver.quit (); }}

In this case, encountered the input box recognition problem, the first is to use Uiautomator

The element that found the web was not recognized at all, and finally thought it should be the same as selenium webdriver.

So in the recognition Baidu input box, by XPath

"//textarea[@id = ' index-kw ']"

Appium for mobile web use Chromedriver

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.