在使用AppiumLibrary库时,需要预先安装好Appium自动化工具,Appium官网地址为:http://appium.io/
Appium的GitHub地址为:https://github.com/appium
Appium的下载地址:http://appium.io/downloads.html,可以下载最新的安装版本和响应的Library库
Appium的相关介绍文档:http://appium.io/slate/cn/master/
Appium的RobotFramework-appiumlibrary地址:https://github.com/serhatbolsu/robotframework-appiumlibrary,library的安装方式,可以通过pip在线安装,也可以使用下载好library库后,采用python setup.py install的方式来进行安装,
1) 使用pip安装
pip install robotframework-appiumlibrary
2) 使用setup.py安装
git clone https://github.com/jollychang/robotframework-appiumlibrary.git
cd robotframework-appiumlibrary
python setup.py install
Appium介绍
Appium 真正的工作引擎其实是第三方自动化框架,共使用以下的第三方框架:
iOS: 苹果的 UIAutomation
Android 4.2+: Google’s UiAutomator
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自动化测试框架-移动手机自动化测试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
RobotFramework自动化测试框架-MongoDBLibrary库的使用
来源:https://www.cnblogs.com/laoqing/p/7355274.html