搭建服务环境
1.安装Nodejs
下载nodejs安装包(http://nodejs.org/download/)
验证:运行cmd,输入node -v
安装理由:Appium是使用nodejs实现的,所以node是解释器,运行必不可少。
2.安装android的SDK(https://developer.android.com/sdk/installing/index.html?pkg=tools)
变量:ANDROID_HOME
值:D:\android-sdk
设置:Path
值:%ANT_HOME%\bin
验证:运行cmd,输入android -v
安装理由:系统运行依赖sdk中的工具
3.安装Apache Ant
安装Apache Ant 解压缩文件夹并添加环境变量
变量:ANT_HOME
值:D:\apache-ant-1.9.4
设置:Path
值:%ANT_HOME%\bin
验证:运行cmd,输入ant -v
4.安装jdk
变量:JAVA_HOME
值:C:\Program Files\Java\jdk1.8.0_25
变量:classpath
值:%JAVA_HOME%\lib;
设置:Path
值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
验证:运行cmd,输入java -version5.安装Maven(http://maven.apache.org/download.cgi)
下载解压并配置环境变量
变量:MAVEN_HOME
值:D:\apache-maven-3.1.1
设置:Path
值:%MAVEN_HOME%\bin
验证:mvn -v
6.安装APPIUM运行cmd,执行npm install -g appium命令安装
验证:运行cmd输入appium
配置运行环境
1.配置Maven环境
配置maven仓库存放位置:
maven目录conf下的settings.xml文件
完成localRepository对应内容设置,默认是本地用户的临时文件夹下面的 .m2 文件夹下的 repository 下
运行cmd,执行:mvn help:system
2.eclipse中maven插件安装
分在线安装与离线安装
将下载的插件包解压到eclipse\dropins下之后重启eclipse
window-Preference可以看到maven选项,配置installations:maven目录,UserSettings:maven目录\conf\settings.xml
APPIUM参数设置
1.Android Settings - Android设置按钮,所有和安卓设置的参数都在这个里面
1.1Application:你可以定义APP及APP的行为
ApplicationPath:apk路径
Package:填写android app的包名
Wait for Package:要等待的package
Launch Activity:输入要运行的activity
Use Browser:使用设备内置的浏览器
Full Reset:回话结束后卸载app
No Reset:不会重置设备中的应用
IntentAction:启动activity
IntentCategory:指定想启动的app
Intent Flags:通常用于启动app的activity
Intnet Arguments:传达额外的参数去启动app的activity
1.2LaunchDevice 在这里设置安卓模拟器
Launch AVD:设备名称
Device Ready Timeout:等待设备超过时间
Arguments:传递额外的参数去启动设备
1.3Capabilities
Platform Name:测试平台的名字,一般为Android
AutomationName:测试引擎的名字,默认是appium,api版本小鱼17时请使用selendroid
Platform Version:设备版本号
Device Name:设备名字
Language:模拟器使用的语言
Local:默认即可
1.4Advanced
SDK Path:android sdk路径,无需指定,配置好android sdk环境变量即可
Coverage Class:指定instrumentation class
Bootstrap Port:分布式测试时需要用到,用于和appium通信
Selendroid Port:分布式测试时需要用到,用于和selendroid通信
Chrome Drive Port:分布式测试时需要用到,用于和chromedriver通信
2.General Settings – 通用设置按钮
2.1server
Server Address:Appium server的ip地址,默认即可
Port:端口号,默认4723
Check For Updates:每次启动是否检查appium更新
Pre-Launch Application:勾选后启动server后会先启动app,需要在app path中定义app
Overriding Existing Session:覆盖之前的session,批量测试的时候需要勾选
Selenium Grid Configuration File:配置selenium grid文件,用于并行分布式测试
Developer Settings – 开发人员设置
About – 关于
Inspector – 元素侦测
Launch the Appium node server – 启动server
Clear – 清除日志
Android Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.example.android.contactmanager");
capabilities.setCapability("appActivity", ".ContactManager");
Desired capability 是一个jason对象,包含一组key和value,由客户端发送给服务端,告诉服务端期望的Capabilities
有哪些,然后服务端根据这些capabilities创建自动化会话(session)
1.通用Capabilities
automationName
这个capability主要是定义测试引擎。当你在安卓平台上进行测试的时候,你需要确认你使用的android sdk版本,如果是小于17的话,你需要指定测试引擎为:Selendroid。如果大于等于17,你需要使用的引擎是:Appium
platformName
定义测试平台的名字,通常用于移动设备。值有:Android、iOS和FirefoxOS
deviceName
移动设备的名字,比如iPhone 5s、Google Nexus等
app
苹果app或者安卓app的路径,可以是本地的绝对路径,也可以是远程网络路径,只要有访问权限即可。根据这个app capabilities,Appium会在启动测试之前安装好app到设备
browserName
测试webapp时需要定义browserName,对于android来说一般是Chrome,IOS可能是safari
newCommandTimeout
为了结束appium会话(session),appium会设置一个等待从客户端发送命令超时的时间。默认时间是60秒
autoLaunch
设置设个capability,会自动安装app并且启动app
autoWebview
如果你测试的是混合应用并且想直接进入webview内容中,那么你需要设置设置这个capability的值为true
2.Android独有Capabilities
appPackage
设置安卓app的包名的capability,告诉appium你要运行哪个app
appActivity
设置你想要运行的app的activity(相当于一个界面或者理解成网页),比如:LoginActivity,登录的activity,可以理解为登录界面
appWaitActivity
设置你想要等待的android activity
appWaitPackage
需要等待的app的包
unicodeKeyboard
是否使用unicode键盘输入,如果设置为true,那么可以输入中文和特殊字符,这个很常用,一般设置为true
resetKeyboard
是否重置键盘为原始状态,比如你将键盘设置为了unicode键盘,当用例执行完成之后,将resetKeyboard设置为true,则键盘重置为原始状态
以上为几个代表性的capability
更多请查阅下表
Appium server capabilities
Capability | Description | Values |
---|---|---|
automationName | Which automation engine to use | Appium (default) or Selendroid |
platformName | Which mobile OS platform to use | iOS , Android , or FirefoxOS |
platformVersion | Mobile OS version | e.g., 7.1 , 4.4 |
deviceName | The kind of mobile device or emulator to use | iPhone Simulator , iPad Simulator ,iPhone Retina 4-inch , Android Emulator ,Galaxy S4 , etc.... On iOS, this should be one of the valid devices returned by instruments with instruments -s devices . On Android this capability is currently ignored, though it remains required. |
app | The absolute local path or remote http URL to an.ipa or .apk file, or a .zip containing one of these. Appium will attempt to install this app binary on the appropriate device first. Note that this capability is not required for Android if you specifyappPackage and appActivity capabilities (see below). Incompatible with browserName . | /abs/path/to/my.apk orhttp://myapp.com/app.ipa |
browserName | Name of mobile web browser to automate. Should be an empty string if automating an app instead. | 'Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android |
newCommandTimeout | How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session | e.g. 60 |
language | (Sim/Emu-only) Language to set for the simulator / emulator | e.g. fr |
locale | (Sim/Emu-only) Locale to set for the simulator / emulator | e.g. fr_CA |
udid | Unique device identifier of the connected physical device | e.g. 1ae203187fc012g |
orientation | (Sim/Emu-only) start in a certain orientation | LANDSCAPE or PORTRAIT |
autoWebview | Move directly into Webview context. Default false | true , false |
noReset | Don't reset app state before this session. Defaultfalse | true , false |
fullReset | (iOS) Delete the entire simulator folder. (Android) Reset app state by uninstalling app instead of clearing app data. On Android, this will also remove the app after the session is complete. Defaultfalse | true , false |
Android Only
Capability | Description | Values |
---|---|---|
appActivity | Activity name for the Android activity you want to launch from your package. This often needs to be preceded by a . (e.g.,.MainActivity instead ofMainActivity ) | MainActivity , .Settings |
appPackage | Java package of the Android app you want to run | com.example.android.myApp , com.android.settings |
appWaitActivity | Activity name for the Android activity you want to wait for | SplashActivity |
appWaitPackage | Java package of the Android app you want to wait for | com.example.android.myApp , com.android.settings |
appWaitDuration | Timeout in milliseconds used to wait for the appWaitActivity to launch (default 20000 ) | 30000 |
deviceReadyTimeout | Timeout in seconds while waiting for device to become ready | 5 |
androidCoverage | Fully qualified instrumentation class. Passed to -w in adb shell am instrument -e coverage true -w | com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation |
enablePerformanceLogging | (Chrome and webview only) Enable Chromedriver's performance logging (default false ) | true , false |
androidDeviceReadyTimeout | Timeout in seconds used to wait for a device to become ready after booting | e.g., 30 |
androidInstallTimeout | Timeout in milliseconds used to wait for an apk to install to the device. Defaults to 90000 | e.g., 90000 |
adbPort | Port used to connect to the ADB server (default 5037 ) | 5037 |
androidDeviceSocket | Devtools socket name. Needed only when tested app is a Chromium embedding browser. The socket is open by the browser and Chromedriver connects to it as a devtools client. | e.g., chrome_devtools_remote |
avd | Name of avd to launch | e.g., api19 |
avdLaunchTimeout | How long to wait in milliseconds for an avd to launch and connect to ADB (default 120000 ) | 300000 |
avdReadyTimeout | How long to wait in milliseconds for an avd to finish its boot animations (default 120000 ) | 300000 |
avdArgs | Additional emulator arguments used when launching an avd | e.g., -netfast |
useKeystore | Use a custom keystore to sign apks, default false | true or false |
keystorePath | Path to custom keystore, default ~/.android/debug.keystore | e.g., /path/to.keystore |
keystorePassword | Password for custom keystore | e.g., foo |
keyAlias | Alias for key | e.g., androiddebugkey |
keyPassword | Password for key | e.g., foo |
chromedriverExecutable | The absolute local path to webdriver executable (if Chromium embedder provides its own webdriver, it should be used instead of original chromedriver bundled with Appium) | /abs/path/to/webdriver |
autoWebviewTimeout | Amount of time to wait for Webview context to become active, in ms. Defaults to 2000 | e.g. 4 |
intentAction | Intent action which will be used to start activity (defaultandroid.intent.action.MAIN ) | e.g.android.intent.action.MAIN ,android.intent.action.VIEW |
intentCategory | Intent category which will be used to start activity (defaultandroid.intent.category.LAUNCHER ) | e.g. android.intent.category.LAUNCHER ,android.intent.category.APP_CONTACTS |
intentFlags | Flags that will be used to start activity (default 0x10200000 ) | e.g. 0x10200000 |
optionalIntentArguments | Additional intent arguments that will be used to start activity. SeeIntent arguments | e.g. --esn <EXTRA_KEY> , --ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> , etc. |
dontStopAppOnReset | Doesn't stop the process of the app under test, before starting the app using adb. If the app under test is created by another anchor app, setting this false, allows the process of the anchor app to be still alive, during the start of the test app using adb. In other words, withdontStopAppOnReset set to true , we will not include the -S flag in the adb shell am start call. With this capability omitted or set tofalse , we include the -S flag. Default false | true or false |
unicodeKeyboard | Enable Unicode input, defaultfalse | true or false |
resetKeyboard | Reset keyboard to its original state, after running Unicode tests withunicodeKeyboard capability. Ignored if used alone. Defaultfalse | true or false |
noSign | Skip checking and signing of app with debug keys, will work only with UiAutomator and not with selendroid, default false | true or false |
ignoreUnimportantViews | Calls thesetCompressedLayoutHierarchy() uiautomator function. This capability can speed up test execution, since Accessibility commands will run faster ignoring some elements. The ignored elements will not be findable, which is why this capability has also been implemented as a toggle-ablesetting as well as a capability. Defaults to false | true or false |
disableAndroidWatchers | Disables android watchers that watch for application not responding and application crash, this will reduce cpu usage on android device/emulator. This capability will work only with UiAutomator and not with selendroid, default false | true or false |
chromeOptions | Allows passing chromeOptions capability for ChromeDriver. For more information seechromeOptions | chromeOptions: {args: ['--disable-popup-blocking']} |
recreateChromeDriverSessions | Kill ChromeDriver session when moving to a non-ChromeDriver webview. Defaults to false | true or false |
nativeWebScreenshot | In a web context, use native (adb) method for taking a screenshot, rather than proxying to ChromeDriver. Defaults to false | true or false |
androidScreenshotPath | The name of the directory on the device in which the screenshot will be put. Defaults to/data/local/tmp | e.g. /sdcard/screenshots/ |
autoGrantPermissions | Have Appium automatically determine which permissions your app requires and grant them to the app on install. Defaults to false | true or false |
iOS Only
Capability | Description | Values |
---|---|---|
calendarFormat | (Sim-only) Calendar format to set for the iOS Simulator | e.g. gregorian |
bundleId | Bundle ID of the app under test. Useful for starting an app on a real device or for using other caps which require the bundle ID during test startup. To run a test on a real device using the bundle ID, you may omit the 'app' capability, but you must provide 'udid'. | e.g. io.appium.TestApp |
udid | Unique device identifier of the connected physical device | e.g. 1ae203187fc012g |
launchTimeout | Amount of time in ms to wait for instruments before assuming it hung and failing the session | e.g. 20000 |
locationServicesEnabled | (Sim-only) Force location services to be either on or off. Default is to keep current sim setting. | true or false |
locationServicesAuthorized | (Sim-only) Set location services to be authorized or not authorized for app via plist, so that location services alert doesn't pop up. Default is to keep current sim setting. Note that if you use this setting you MUST also use thebundleId capability to send in your app's bundle ID. | true or false |
autoAcceptAlerts | Accept all iOS alerts automatically if they pop up. This includes privacy access permission alerts (e.g., location, contacts, photos). Default is false. Does not work onXCUITest -based tests. | true or false |
autoDismissAlerts | Dismiss all iOS alerts automatically if they pop up. This includes privacy access permission alerts (e.g., location, contacts, photos). Default is false. Does not work onXCUITest -based tests. | true or false |
nativeInstrumentsLib | Use native intruments lib (ie disable instruments-without-delay). | true or false |
nativeWebTap | (Sim-only) Enable "real", non-javascript-based web taps in Safari. Default: false . Warning: depending on viewport size/ratio this might not accurately tap an element | true or false |
safariInitialUrl | (Sim-only) (>= 8.1) Initial safari url, default is a local welcome page | e.g.https://www.github.com |
safariAllowPopups | (Sim-only) Allow javascript to open new windows in Safari. Default keeps current sim setting | true or false |
safariIgnoreFraudWarning | (Sim-only) Prevent Safari from showing a fraudulent website warning. Default keeps current sim setting. | true or false |
safariOpenLinksInBackground | (Sim-only) Whether Safari should allow links to open in new windows. Default keeps current sim setting. | true or false |
keepKeyChains | (Sim-only) Whether to keep keychains (Library/Keychains) when appium session is started/finished | true or false |
localizableStringsDir | Where to look for localizable strings. Default en.lproj | en.lproj |
processArguments | Arguments to pass to the AUT using instruments | e.g., -myflag |
interKeyDelay | The delay, in ms, between keystrokes sent to an element when typing. | e.g., 100 |
showIOSLog | Whether to show any logs captured from a device in the appium logs. Default false | true or false |
sendKeyStrategy | strategy to use to type test into a test field. Simulator default: oneByOne . Real device default: grouped | oneByOne , grouped orsetValue |
screenshotWaitTimeout | Max timeout in sec to wait for a screenshot to be generated. default: 10 | e.g., 5 |
waitForAppScript | The ios automation script used to determined if the app has been launched, by default the system wait for the page source not to be empty. The result must be a boolean | e.g. true; ,target.elements().length > 0; , $.delay(5000); true; |
webviewConnectRetries | Number of times to send connection message to remote debugger, to get webview. Default: 8 | e.g., 12 |
appName | The display name of the application under test. Used to automate backgrounding the app in iOS 9+. | e.g., UICatalog |
customSSLCert | (Sim/Emu-only) Add an SSL certificate to simulator. | e.g. -----BEGIN CERTIFICATE-----MIIFWjCCBEKg... -----END CERTIFICATE----- |
iOS Only, using XCUITest
Capability | Description | Values |
---|---|---|
processArguments | Process arguments and environment which will be sent to the WebDriverAgent server. | { args: ["a", "b", "c"] , env: { "a": "b", "c": "d" } } or '{"args": ["a", "b", "c"], "env": { "a": "b", "c": "d" }}' |
wdaLocalPort | This value if specified, will be used to forward traffic from Mac host to real ios devices over USB. Default value is same as port number used by WDA on device. | e.g., 8100 |
showXcodeLog | Whether to display the output of the Xcode command used to run the tests. If this is true , there will be lots of extra logging at startup. Defaults to false | e.g., true |
iosInstallPause | Time in milliseconds to pause between installing the application and starting WebDriverAgent on the device. Used particularly for larger applications. Defaults to 0 | e.g., 8000 |
xcodeConfigFile | Full path to an optional Xcode configuration file that specifies the code signing identity and team for running the WebDriverAgent on the real device. | e.g.,/path/to/myconfig.xcconfig |
keychainPath | Full path to the private development key exported from the system keychain. Used in conjunction with keychainPassword when testing on real devices. | e.g.,/path/to/MyPrivateKey.p12 |
keychainPassword | Password for unlocking keychain specified in keychainPath . | e.g., super awesome password |
scaleFactor | Simulator scale factor. This is useful to have if the default resolution of simulated device is greater than the actual display resolution. So you can scale the simulator to see the whole device screen without scrolling. | Acceptable values are:'1.0', '0.75', '0.5', '0.33' and '0.25' . The value should be a string. |
preventWDAAttachments | Sets read only permissons to Attachments subfolder of WebDriverAgent root inside Xcode's DerivedData. This is necessary to prevent XCTest framework from creating tons of unnecessary screenshots and logs, which are impossible to shutdown using programming interfaces provided by Apple. | Setting the capability totrue will set Posix permissions of the folder to555 and false will reset them back to 755 |
webDriverAgentUrl | If provided, Appium will connect to an existing WebDriverAgent instance at this URL instead of starting a new one. | e.g., http://localhost:8100 |
useNewWDA | If true , forces uninstall of any existing WebDriverAgent app on device. This can provide stability in some situations. Defaults to false . | e.g., true |
wdaLaunchTimeout | Time, in ms, to wait for WebDriverAgewnt to be pingable. Defaults to 60000ms. | e.g., 30000 |
You.i Engine Only
Capability | Description | Values |
---|---|---|
youiEngineAppAddress | The IP address of the device on which the app is running. Use localhost for simulator. | |
Use device’s IP address for a real device. | e.g. localhost or 192.168.1.203 |
WinAppDriver Only
Capability | Description | Values |
---|---|---|
platformName | Which platform the test is being done on | e.g. Windows |
deviceName | The name of the device being tested on | e.g. WindowsPC |
app | appID of the windows app for testing or the path to the .exe file. See this page for details on how to find the appID | e.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App |