appium自动化测试环境搭建

搭建服务环境

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 -version

5.安装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

CapabilityDescriptionValues
automationNameWhich automation engine to useAppium (default) or Selendroid
platformNameWhich mobile OS platform to useiOSAndroid, or FirefoxOS
platformVersionMobile OS versione.g., 7.14.4
deviceNameThe kind of mobile device or emulator to useiPhone SimulatoriPad Simulator,iPhone Retina 4-inchAndroid 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.
appThe 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
browserNameName 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
newCommandTimeoutHow long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the sessione.g. 60
language(Sim/Emu-only) Language to set for the simulator / emulatore.g. fr
locale(Sim/Emu-only) Locale to set for the simulator / emulatore.g. fr_CA
udidUnique device identifier of the connected physical devicee.g. 1ae203187fc012g
orientation(Sim/Emu-only) start in a certain orientationLANDSCAPE or PORTRAIT
autoWebviewMove directly into Webview context. Default falsetruefalse
noResetDon't reset app state before this session. Defaultfalsetruefalse
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. Defaultfalsetruefalse

Android Only

CapabilityDescriptionValues
appActivityActivity 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
appPackageJava package of the Android app you want to runcom.example.android.myAppcom.android.settings
appWaitActivityActivity name for the Android activity you want to wait forSplashActivity
appWaitPackageJava package of the Android app you want to wait forcom.example.android.myAppcom.android.settings
appWaitDurationTimeout in milliseconds used to wait for the appWaitActivity to launch (default 20000)30000
deviceReadyTimeoutTimeout in seconds while waiting for device to become ready5
androidCoverageFully qualified instrumentation class. Passed to -w in adb shell am instrument -e coverage true -wcom.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation
enablePerformanceLogging(Chrome and webview only) Enable Chromedriver's performance logging (default false)truefalse
androidDeviceReadyTimeoutTimeout in seconds used to wait for a device to become ready after bootinge.g., 30
androidInstallTimeoutTimeout in milliseconds used to wait for an apk to install to the device. Defaults to 90000e.g., 90000
adbPortPort used to connect to the ADB server (default 5037)5037
androidDeviceSocketDevtools 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
avdName of avd to launche.g., api19
avdLaunchTimeoutHow long to wait in milliseconds for an avd to launch and connect to ADB (default 120000)300000
avdReadyTimeoutHow long to wait in milliseconds for an avd to finish its boot animations (default 120000)300000
avdArgsAdditional emulator arguments used when launching an avde.g., -netfast
useKeystoreUse a custom keystore to sign apks, default falsetrue or false
keystorePathPath to custom keystore, default ~/.android/debug.keystoree.g., /path/to.keystore
keystorePasswordPassword for custom keystoree.g., foo
keyAliasAlias for keye.g., androiddebugkey
keyPasswordPassword for keye.g., foo
chromedriverExecutableThe 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
autoWebviewTimeoutAmount of time to wait for Webview context to become active, in ms. Defaults to 2000e.g. 4
intentActionIntent action which will be used to start activity (defaultandroid.intent.action.MAIN)e.g.android.intent.action.MAIN,android.intent.action.VIEW
intentCategoryIntent category which will be used to start activity (defaultandroid.intent.category.LAUNCHER)e.g. android.intent.category.LAUNCHER,android.intent.category.APP_CONTACTS
intentFlagsFlags that will be used to start activity (default 0x10200000)e.g. 0x10200000
optionalIntentArgumentsAdditional intent arguments that will be used to start activity. SeeIntent argumentse.g. --esn <EXTRA_KEY>--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>, etc.
dontStopAppOnResetDoesn'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 falsetrue or false
unicodeKeyboardEnable Unicode input, defaultfalsetrue or false
resetKeyboardReset keyboard to its original state, after running Unicode tests withunicodeKeyboard capability. Ignored if used alone. Defaultfalsetrue or false
noSignSkip checking and signing of app with debug keys, will work only with UiAutomator and not with selendroid, default falsetrue or false
ignoreUnimportantViewsCalls 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 falsetrue or false
disableAndroidWatchersDisables 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 falsetrue or false
chromeOptionsAllows passing chromeOptions capability for ChromeDriver. For more information seechromeOptionschromeOptions: {args: ['--disable-popup-blocking']}
recreateChromeDriverSessionsKill ChromeDriver session when moving to a non-ChromeDriver webview. Defaults to falsetrue or false
nativeWebScreenshotIn a web context, use native (adb) method for taking a screenshot, rather than proxying to ChromeDriver. Defaults to falsetrue or false
androidScreenshotPathThe name of the directory on the device in which the screenshot will be put. Defaults to/data/local/tmpe.g. /sdcard/screenshots/
autoGrantPermissionsHave Appium automatically determine which permissions your app requires and grant them to the app on install. Defaults to falsetrue or false

iOS Only

CapabilityDescriptionValues
calendarFormat(Sim-only) Calendar format to set for the iOS Simulatore.g. gregorian
bundleIdBundle 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
udidUnique device identifier of the connected physical devicee.g. 1ae203187fc012g
launchTimeoutAmount of time in ms to wait for instruments before assuming it hung and failing the sessione.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
autoAcceptAlertsAccept 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
autoDismissAlertsDismiss 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
nativeInstrumentsLibUse 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 elementtrue or false
safariInitialUrl(Sim-only) (>= 8.1) Initial safari url, default is a local welcome pagee.g.https://www.github.com
safariAllowPopups(Sim-only) Allow javascript to open new windows in Safari. Default keeps current sim settingtrue 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/finishedtrue or false
localizableStringsDirWhere to look for localizable strings. Default en.lprojen.lproj
processArgumentsArguments to pass to the AUT using instrumentse.g., -myflag
interKeyDelayThe delay, in ms, between keystrokes sent to an element when typing.e.g., 100
showIOSLogWhether to show any logs captured from a device in the appium logs. Default falsetrue or false
sendKeyStrategystrategy to use to type test into a test field. Simulator default: oneByOne. Real device default: groupedoneByOnegrouped orsetValue
screenshotWaitTimeoutMax timeout in sec to wait for a screenshot to be generated. default: 10e.g., 5
waitForAppScriptThe 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 booleane.g. true;,target.elements().length > 0;$.delay(5000); true;
webviewConnectRetriesNumber of times to send connection message to remote debugger, to get webview. Default: 8e.g., 12
appNameThe 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

CapabilityDescriptionValues
processArgumentsProcess 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" }}'
wdaLocalPortThis 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
showXcodeLogWhether 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 falsee.g., true
iosInstallPauseTime in milliseconds to pause between installing the application and starting WebDriverAgent on the device. Used particularly for larger applications. Defaults to 0e.g., 8000
xcodeConfigFileFull 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
keychainPathFull path to the private development key exported from the system keychain. Used in conjunction with keychainPasswordwhen testing on real devices.e.g.,/path/to/MyPrivateKey.p12
keychainPasswordPassword for unlocking keychain specified in keychainPath.e.g., super awesome password
scaleFactorSimulator 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.
preventWDAAttachmentsSets 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
webDriverAgentUrlIf provided, Appium will connect to an existing WebDriverAgent instance at this URL instead of starting a new one.e.g., http://localhost:8100
useNewWDAIf true, forces uninstall of any existing WebDriverAgent app on device. This can provide stability in some situations. Defaults to false.e.g., true
wdaLaunchTimeoutTime, in ms, to wait for WebDriverAgewnt to be pingable. Defaults to 60000ms.e.g., 30000

You.i Engine Only

CapabilityDescriptionValues
youiEngineAppAddressThe IP address of the device on which the app is running. Use localhostfor simulator. 
Use device’s IP address for a real device.e.g. localhost or 192.168.1.203 

WinAppDriver Only

CapabilityDescriptionValues
platformNameWhich platform the test is being done one.g. Windows
deviceNameThe name of the device being tested one.g. WindowsPC
appappID of the windows app for testing or the path to the .exe file. See this page for details on how to find the appIDe.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值