com.appium.driver包下建立InitDriver.java類:java
package com.appium.driver; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import io.appium.java_client.remote.AndroidMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; public class InitDriver { public static AndroidDriver<AndroidElement> initDriverWebapp() throws MalformedURLException{ DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "chinablue"); caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); caps.setCapability(MobileCapabilityType.UDID, "DU3ADH154V007404"); caps.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true); caps.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.2"); URL url = new URL("http://127.0.0.1:4723/wd/hub"); AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(url,caps); return driver; } public static AndroidDriver<AndroidElement> initDriver() throws MalformedURLException{ File apk_path = new File("apps/zhihu.apk"); DesiredCapabilities caps = new DesiredCapabilities(); // 與appium服務器相關的caps caps.setCapability(MobileCapabilityType.DEVICE_NAME, "chinablue"); caps.setCapability(MobileCapabilityType.APP, apk_path.getAbsolutePath()); // 手機網頁測試 // caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chinablue"); // caps.setCapability(MobileCapabilityType.UDID, "127.0.0.1:62001"); // 服務端等待客戶端發送腳本命令時間 caps.setCapability(MobileCapabilityType