在使用AppiumLibrary庫時,須要預先安裝好Appium自動化工具,Appium官網地址爲:http://appium.io/javascript
Appium的GitHub地址爲:https://github.com/appiumhtml
Appium的下載地址:http://appium.io/downloads.html,能夠下載最新的安裝版本和響應的Library庫java
Appium的相關介紹文檔:http://appium.io/slate/cn/master/node
Appium的RobotFramework-appiumlibrary地址:https://github.com/serhatbolsu/robotframework-appiumlibrary,library的安裝方式,能夠經過pip在線安裝,也可使用下載好library庫後,採用python setup.py install的方式來進行安裝,python
1) 使用pip安裝android
pip install robotframework-appiumlibrary
2) 使用setup.py安裝ios
git clone https://github.com/jollychang/robotframework-appiumlibrary.git
cd robotframework-appiumlibrary
python setup.py install
Appium 真正的工做引擎實際上是第三方自動化框架,共使用如下的第三方框架:git
iOS: 蘋果的 UIAutomationgithub
Android 4.2+: Google’s UiAutomatorweb
Android 2.3+: Google’s Instrumentation. (Instrumentation由單獨的項目Selendroid提供支持 )
Appium爲了實現自身提出的理念你沒必要侷限於某種語言或者框架來寫和運行測試腳本和一個移動自動化的框架不該該在接口上重複造輪子,把上面提到的第三方框架都封裝成了一套API,即WebDriver,API.WebDriver( 「Selenium WebDriver",Appium對此進行了擴展) 指定了客戶端到服務端的協議,使用這種客戶端-服務端的架構可使用任何語言來編寫客戶端,向服務端發送恰當的 HTTP 請求。
Appium 的核心是一個 web 服務器,它提供了一套 REST 的接口。它收到客戶端的鏈接,監聽到命令,接着在移動設備上執行這些命令,而後將執行結果放在 HTTP響應中返還給客戶端。
Appium中的經常使用術語
1) Session
Appium自動化創建在一個session上運行,Client端初始化一個seesion來與服務端進行請求和交互,客戶端會發送爲一個POST請求給服務端,請求中包含一個JSON對象,被稱做「desired capabilities」。而後,服務端就會開啓一個自動化的 session,而且返回一個 session ID給客戶端,客戶端的後續請求都會帶上該session ID給服務端作識別。
2) Desired Capabilities
Desired capabilities 是一些鍵值對的集合 (好比,一個 map 或者 hashmap),客戶端將這些鍵值對發給服務端,告訴服務端須要怎麼執行測試。好比,咱們能夠把platformName
capability 設置爲 Android
,告訴 Appium 服務端,咱們想要一個Android
的 session,而不是一個 iOS 的。咱們也能夠設置 safariAllowPopups
capability 爲 true
,確保在 Safari 自動化 session 中,咱們可使用 javascript 來打開新窗口。
3) Appium Server
Appium server 是基於 Node.js 實現的,可使用NPM 直接安裝。
4) Appium 服務關鍵字
usage: appium.js [-h] [-v] [--shell]
[--localizable-strings-dir LOCALIZABLESTRINGSDIR] [--app APP]
[--ipa IPA] [-U UDID] [-a ADDRESS] [-p PORT]
[-ca CALLBACKADDRESS] [-cp CALLBACKPORT] [-bp BOOTSTRAPPORT]
[-k] [-r BACKENDRETRIES] [--session-override] [--full-reset]
[--no-reset] [-l] [-lt LAUNCHTIMEOUT] [-g LOG]
[--log-level {info,info:debug,info:info,info:warn,info:error,wa
rn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:
warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}]
[--log-timestamp] [--local-timezone] [--log-no-colors]
[-G WEBHOOK] [--native-instruments-lib]
[--app-pkg ANDROIDPACKAGE] [--app-activity ANDROIDACTIVITY]
[--app-wait-package ANDROIDWAITPACKAGE]
[--app-wait-activity ANDROIDWAITACTIVITY]
[--android-coverage ANDROIDCOVERAGE] [--avd AVD]
[--avd-args AVDARGS]
[--device-ready-timeout ANDROIDDEVICEREADYTIMEOUT] [--safari]
[--device-name DEVICENAME] [--platform-name PLATFORMNAME]
[--platform-version PLATFORMVERSION]
[--automation-name AUTOMATIONNAME]
[--browser-name BROWSERNAME] [--default-device]
[--force-iphone] [--force-ipad] [--language LANGUAGE]
[--locale LOCALE] [--calendar-format CALENDARFORMAT]
[--orientation ORIENTATION]
[--tracetemplate AUTOMATIONTRACETEMPLATEPATH]
[--instruments INSTRUMENTSPATH] [--show-sim-log]
[--show-ios-log] [--nodeconfig NODECONFIG] [-ra ROBOTADDRESS]
[-rp ROBOTPORT] [--selendroid-port SELENDROIDPORT]
[--chromedriver-port CHROMEDRIVERPORT]
[--chromedriver-executable CHROMEDRIVEREXECUTABLE]
[--use-keystore] [--keystore-path KEYSTOREPATH]
[--keystore-password KEYSTOREPASSWORD] [--key-alias KEYALIAS]
[--key-password KEYPASSWORD] [--show-config]
[--no-perms-check] [--command-timeout DEFAULTCOMMANDTIMEOUT]
[--keep-keychains] [--strict-caps] [--isolate-sim-device]
[--tmp TMPDIR] [--trace-dir TRACEDIR]
[--intent-action INTENTACTION]
[--intent-category INTENTCATEGORY]
[--intent-flags INTENTFLAGS]
[--intent-args OPTIONALINTENTARGUMENTS]
[--dont-stop-app-on-reset] [--debug-log-spacing]
[--suppress-adb-kill-server] [--async-trace]
A webdriver-compatible server for use with native and hybrid iOS and Android
applications.
Optional arguments:
-h, --help Show this help message and exit.
-v, --version Show program's version number and exit.
--shell Enter REPL mode
--localizable-strings-dir LOCALIZABLESTRINGSDIR
IOS only: the relative path of the dir where
Localizable.strings file resides
--app APP IOS: abs path to simulator-compiled .app file or the
bundle_id of the desired target on device; Android:
abs path to .apk file
--ipa IPA (IOS-only) abs path to compiled .ipa file
-U UDID, --udid UDID Unique device identifier of the connected physical
device
-a ADDRESS, --address ADDRESS
IP Address to listen on
-p PORT, --port PORT port to listen on
-ca CALLBACKADDRESS, --callback-address CALLBACKADDRESS
callback IP Address (default: same as --address)
-cp CALLBACKPORT, --callback-port CALLBACKPORT
callback port (default: same as port)
-bp BOOTSTRAPPORT, --bootstrap-port BOOTSTRAPPORT
(Android-only) port to use on device to talk to Appium
-k, --keep-artifacts [DEPRECATED] no effect, trace is now in tmp dir by
default and is cleared before each run. Please also
refer to the --trace-dir flag.
-r BACKENDRETRIES, --backend-retries BACKENDRETRIES
(iOS-only) How many times to retry launching
Instruments before saying it crashed or timed out
--session-override Enables session override (clobbering)
--full-reset (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.
--no-reset Don't reset app state between sessions (IOS: don't
delete app plist files; Android: don't uninstall app
before new session)
-l, --pre-launch Pre-launch the application before allowing the first
session (Requires --app and, for Android, --app-pkg
and --app-activity)
-lt LAUNCHTIMEOUT, --launch-timeout LAUNCHTIMEOUT
(iOS-only) how long in ms to wait for Instruments to
launch
-g LOG, --log LOG Also send log output to this file
--log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,wa
rn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error
,debug,debug:debug,debug:info,debug:warn,debug:error}
log level; default (console[:file]): debug[:debug]
--log-timestamp Show timestamps in console output
--local-timezone Use local timezone for timestamps
--log-no-colors Don't use colors in console output
-G WEBHOOK, --webhook WEBHOOK
Also send log output to this HTTP listener
--native-instruments-lib
(IOS-only) IOS has a weird built-in unavoidable delay.
We patch this in appium. If you do not want it
patched, pass in this flag.
--app-pkg ANDROIDPACKAGE
(Android-only) Java package of the Android app you
want to run (e.g., com.example.android.myApp)
--app-activity ANDROIDACTIVITY
(Android-only) Activity name for the Android activity
you want to launch from your package (e.g.,
MainActivity)
--app-wait-package ANDROIDWAITPACKAGE
(Android-only) Package name for the Android activity
you want to wait for (e.g., com.example.android.myApp)
--app-wait-activity ANDROIDWAITACTIVITY
(Android-only) Activity name for the Android activity
you want to wait for (e.g., SplashActivity)
--android-coverage ANDROIDCOVERAGE
(Android-only) Fully qualified instrumentation class.
Passed to -w in adb shell am instrument -e coverage
true -w
--avd AVD (Android-only) Name of the avd to launch
--avd-args AVDARGS (Android-only) Additional emulator arguments to
launch the avd
--device-ready-timeout ANDROIDDEVICEREADYTIMEOUT
(Android-only) Timeout in seconds while waiting for
device to become ready
--safari (IOS-Only) Use the safari app
--device-name DEVICENAME
Name of the mobile device to use
--platform-name PLATFORMNAME
Name of the mobile platform: iOS, Android, or
FirefoxOS
--platform-version PLATFORMVERSION
Version of the mobile platform
--automation-name AUTOMATIONNAME
Name of the automation tool: Appium or Selendroid
--browser-name BROWSERNAME
Name of the mobile browser: Safari or Chrome
--default-device, -dd
(IOS-Simulator-only) use the default simulator that
instruments launches on its own
--force-iphone (IOS-only) Use the iPhone Simulator no matter what
the app wants
--force-ipad (IOS-only) Use the iPad Simulator no matter what the
app wants
--language LANGUAGE Language for the iOS simulator / Android Emulator
--locale LOCALE Locale for the iOS simulator / Android Emulator
--calendar-format CALENDARFORMAT
(IOS-only) calendar format for the iOS simulator
--orientation ORIENTATION
(IOS-only) use LANDSCAPE or PORTRAIT to initialize
all requests to this orientation
--tracetemplate AUTOMATIONTRACETEMPLATEPATH
(IOS-only) .tracetemplate file to use with Instruments
--instruments INSTRUMENTSPATH
(IOS-only) path to instruments binary
--show-sim-log (IOS-only) if set, the iOS simulator log will be
written to the console
--show-ios-log (IOS-only) if set, the iOS system log will be written
to the console
--nodeconfig NODECONFIG
Configuration JSON file to register appium with
selenium grid
-ra ROBOTADDRESS, --robot-address ROBOTADDRESS
IP Address of robot
-rp ROBOTPORT, --robot-port ROBOTPORT
port for robot
--selendroid-port SELENDROIDPORT
Local port used for communication with Selendroid
--chromedriver-port CHROMEDRIVERPORT
Port upon which ChromeDriver will run
--chromedriver-executable CHROMEDRIVEREXECUTABLE
ChromeDriver executable full path
--use-keystore (Android-only) When set the keystore will be used to
sign apks.
--keystore-path KEYSTOREPATH
(Android-only) Path to keystore
--keystore-password KEYSTOREPASSWORD
(Android-only) Password to keystore
--key-alias KEYALIAS (Android-only) Key alias
--key-password KEYPASSWORD
(Android-only) Key password
--show-config Show info about the appium server configuration and
exit
--no-perms-check Bypass Appium's checks to ensure we can read/write
necessary files
--command-timeout DEFAULTCOMMANDTIMEOUT
The default command timeout for the server to use for
all sessions. Will still be overridden by
newCommandTimeout cap
--keep-keychains (iOS) Whether to keep keychains (Library/Keychains)
when reset app between sessions
--strict-caps Cause sessions to fail if desired caps are sent in
that Appium does not recognize as valid for the
selected device
--isolate-sim-device Xcode 6 has a bug on some platforms where a certain
simulator can only be launched without error if all
other simulator devices are first deleted. This
option causes Appium to delete all devices other than
the one being used by Appium. Note that this is a
permanent deletion, and you are responsible for using
simctl or xcode to manage the categories of devices
used with Appium.
--tmp TMPDIR Absolute path to directory Appium can use to manage
temporary files, like built-in iOS apps it needs to
move around. On *nix/Mac defaults to /tmp, on Windows
defaults to C:\Windows\Temp
--trace-dir TRACEDIR Absolute path to directory Appium use to save ios
instruments traces, defaults to <tmp
dir>/appium-instruments
--intent-action INTENTACTION
(Android-only) Intent action which will be used to
start activity
--intent-category INTENTCATEGORY
(Android-only) Intent category which will be used to
start activity
--intent-flags INTENTFLAGS
(Android-only) Flags that will be used to start
activity
--intent-args OPTIONALINTENTARGUMENTS
(Android-only) Additional intent arguments that will
be used to start activity
--dont-stop-app-on-reset
(Android-only) When included, refrains from stopping
the app before restart
--debug-log-spacing Add exaggerated spacing in logs to help with visual
inspection
--suppress-adb-kill-server
(Android-only) If set, prevents Appium from killing
the adb server instance
--async-trace Add long stack traces to log entries. Recommended for
debugging only.
服務關鍵字 |
描述 |
automationName |
自動化測試引擎的名稱,好比 |
platformName |
待測試的手機操做系統,好比 |
platformVersion |
手機操做系統版本 |
deviceName |
手機device或模擬器的device,在安卓上,能夠經過adb devices 來獲得,在ios上,可使用 |
app |
|
browserName |
待自動化測試的手機 的web 瀏覽器名稱,若是是對APP應用進行自動化測試,這個關鍵字的值應該要爲空。 |
newCommandTimeout |
執行命令超時時間,單位:秒。若是達到超時時間仍未接收到新的命令時 Appium 會認爲客戶端退出而後自動結束會話。 |
autoLaunch |
Appium是否須要自動安裝和啓動應用,默認 |
language |
(Sim/Emu-only) 設定模擬器 ( simulator / emulator ) 的語言。 |
locale |
(Sim/Emu-only) 設定模擬器 ( simulator / emulator ) 的區域設置。 |
noReset |
不在會話前重置應用狀態,默認值 |
fullReset |
Android上經過卸載,而不是清空數據重置應用狀態,在 Android 上會話結束後自動清除被測應用,ios上會刪除整個模擬器目錄。 |
udid |
鏈接的物理設備的惟一設備標識 |
orientation |
(Sim/Emu-only) 在一個設定的方向模式中開始測試 |
【原文歸做者全部,歡迎轉載,可是保留版權】
相關博文彙總:
RobotFramework下的http接口自動化Create Http Context關鍵字的使用
RobotFramework下的http接口自動化Get關鍵字的使用
RobotFramework下的http接口自動化post關鍵字的使用
RobotFramework下的http接口自動化Get Response Body關鍵字的使用
RobotFramework下的http接口自動化Get Response Status 關鍵字的使用
RobotFramework下的http接口自動化Get Response header 關鍵字的使用
RobotFramework下的http接口自動化Set Request Header 關鍵字的使用
RobotFramework下HttpLibrary庫其它關鍵字
RobotFramework下的http接口自動化Set Request Body 關鍵字的使用
RobotFramework下的http接口自動化Follow Response關鍵字的使用
RobotFramework自動化測試框架的基礎關鍵字(一)
RobotFramework自動化測試框架的基礎關鍵字(二)
RobotFramework自動化測試框架的基礎關鍵字(三)
RobotFramework自動化測試框架的基礎關鍵字(四)
RobotFramework自動化測試框架的基礎關鍵字(五)
RobotFramework自動化測試框架-移動手機自動化測試AppiumLibrary介紹
RobotFramework自動化測試框架-移動手機自動化測試Open Application關鍵字的使用
RobotFramework自動化測試框架-經常使用斷言關鍵字
RobotFramework自動化測試框架-移動手機自動化測試AppiumLibrary庫其它的常見自動化關鍵字
RobotFramework自動化測試框架-移動手機自動化測試Input Text和Click Button關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Clear Text關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Click Element關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Click A Point關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Click Element At Coordinates關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Get Element Location關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Get Network Connection Status和Set Network Connection Status關鍵字的使用
RobotFramework自動化測試框架-移動手機自動化測試Element Attribute Should Match關鍵字的使用
RobotFramework自動化測試框架-DatabaseLibrary庫的使用(對數據庫的操做)
RobotFramework自動化測試框架-使用Python編寫自定義的RobotFramework Lib
RobotFramework自動化測試框架-Selenium Web自動化(-)-Open Browser和Close Browser