Appium是一個開源的,適用於原生或混合移動應用應用( hybrid mobile apps)的自動化測試平臺,能夠很是快捷的爲iOS和Android移動平臺建立功能自動化測試用例。相比其餘的移動自動化測試工具,Appium測試因爲調用了Selenium的client庫使其能夠使用任意的語言,包括Python、Ruby、Node.js,Objective,java等。java
官方地址:http://appium.io/android
Mac OSX 10.7+
XCode 4.5+ w/ Command Line Toolsios
Mac OSX 10.7+ or Windows 7+ or Linuxweb
Android SDK ≥ 16 (SDK < 16 in Selendroid mode)chrome
iOS: Apple's UIAutomation
Android 4.2+: Google's UiAutomator
Android 2.3+: Google's Instrumentation瀏覽器
import java.net.MalformedURLException; import java.net.URL; import org.junit.After; import org.junit.Before; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import com.tmall.app.search.monkey.page.TMGuideActivityPage; import io.appium.java_client.AppiumDriver; public class BaseTest { protected AppiumDriver driver; //打開app,進行一些初始化工做。如進入目標頁面等... @Before public void setUp() throws Exception { setUpDriver(); //TMGuideActivityPage page = new TMGuideActivityPage(driver); //if(page.isReady()){ // page.splash(); //} } @After public void tearDown() throws Exception { driver.quit(); } //啓動appium Driver public void setUpDriver() throws MalformedURLException{ // final File appDir = new File("D:\\TMApp"); // final File app = new File(appDir, "10002119.apk"); final DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("deviceName", "Android"); capabilities.setCapability("platformVersion", "4.3"); capabilities.setCapability("platformName", "Android"); // capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.tmall.wireless"); capabilities.setCapability("appActivity",//".module.main.TMMainTabActivity"); ".module.launchalert.TMLaunchAlertActivity"); capabilities.setCapability("appWaitActivity", ".module.main.TMMainTabActivity"); capabilities.setCapability("newCommandTimeout",120); driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } } public class DetailTest extends BaseTest{ @Test public void MyDetailTest() { Search s = new Search(); s.doAction(driver); //assert(xxxxx); }
}ruby
DesiredCapabilities 負責啓動服務端時的參數設置。實際使用時根據本身的須要,可自行修改一些參數。session
好比,應用程序在查找某個頁面的元素時,定位可能會時間超長。默認的命令間隔時間是60s,若是在60s內沒有找到,就會自動退出。能夠使用newCommandTimeout
設置爲更大的數值。app
capabilities.setCapability("newCommandTimeout",240);
好比,最開始使用appium時,設置了上面的安裝apk的路徑,結果安裝後調試程序發現接口無返回數據。後來定位問題是由於安裝時進行了重簽名。程序的保護機制讓數據無返回了。能夠使用noSign
設置來避免重簽名。less
capabilities.setCapability("noSign","true");
固然,後來發現不在程序裏寫文件路徑,而是提早安裝好測試包,這樣就避免了每次都要從新安裝。
http://appium.io/slate/en/master/?ruby#appium-server-capabilities
**Server capabilities** Capability Appium 、Selendroid platformName 平臺的名稱:iOS, Android, or FirefoxOS platformVersion 移動設備的系統版本號,7.1, 4.4 deviceName IOS:instruments -s devices,Android:隨便寫 app 安裝文件路徑:/abs/path/to/my.apk or http://myapp.com/app.ipa browserName 測試的web瀏覽器,若是是測app則忽略 newCommandTimeout 等待新命令的最長時間,超時後退出。默認是60s autoLaunch 是否自動安裝和啓動,默認true language 模擬器的語言設置 locale 模擬器的地區設置 udid 設備號 orientation 模擬器的橫豎屏設置 autoWebview Move directly into Webview context noReset 在當前session前不重置app狀態 fullReset ios刪除文件夾,Android刪除app數據。 **android only** appActivity 要啓動的Activity appPackage 要啓動的包 appWaitActivity 等待的Activity appWaitPackage 等待的包 deviceReadyTimeout 等待設備就緒的時間 androidCoverage enablePerformanceLogging (Chrome and webview only)default=false androidDeviceReadyTimeout androidDeviceSocket avd avdLaunchTimeout avdReadyTimeout avdArgs useKeystore keystorePath keystorePassword keyAlias keyPassword chromedriverExecutable autoWebviewTimeout intentAction intentCategory intentFlags optionalIntentArguments unicodeKeyboard resetKeyboard noSign Skip checking and signing,work only with UiAutomator and not with selendroid ignoreUnimportantViews **ios only** calendarFormat bundleId udid launchTimeout locationServicesEnabled locationServicesAuthorized autoAcceptAlerts nativeInstrumentsLib nativeWebTap safariAllowPopups safariIgnoreFraudWarning safariOpenLinksInBackground keepKeyChains localizableStringsDir processArguments interKeyDelay showIOSLog