上次问也没人回答 自己摸索的,先自己安装下 chrome,此用例是在安卓手机上用 chorme 打开好搜主页,并输入 java 点击搜索

package ipsa_wap;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestWap {
     AppiumDriver<WebElement> driver;
    @BeforeTest
    public void startTest() throws MalformedURLException{
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.3.1");
        desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "LD-100");
        desiredCapabilities.setCapability("appPackage", "com.android.chrome");
        desiredCapabilities.setCapability("appActivity", "com.android.chromecom.google.apps.chrome.Main");
        driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),desiredCapabilities);



    }


    @Test
    public void doTest() throws InterruptedException{

        driver.get("http://www.haosou.com/");
        Thread.sleep(1000);
        driver.findElement(By.id("q")).sendKeys("Java");
        driver.findElement(By.className("search-btn")).click();;
        Thread.sleep(5000);
    }

    @AfterTest
    public void endTest(){

        driver.quit();
    }
}


↙↙↙阅读原文可查看相关链接,并与作者交流