在1.4版本的AppiumLibrary, id和xpath 不需要特别的区分,但是xpath应该以 // 开头,否则,只能用xpath定位器,像下面这样:
例如:
Click Element my_element
Wait Until Page Contains Element //*[@type="android.widget.EditText"]
Strategy | Example | Description | Note |
identifier | Click Element | identifier=my_element | Matches by @id attribute |
|
id | Click Element | id=my_element | Matches by @resource-id attribute |
|
accessibility_id | Click Element | accessibility_id=button3 | Accessibility options utilize. |
|
xpath | Click Element | xpath=//UIATableView/UIATableCell/UIAButton | Matches with arbitrary XPath |
|
class | Click Element | class=UIAPickerWheel | Matches by class |
|
android | Click Element | android=UiSelector().description('Apps') | Matches by Android UI Automator |
|
ios | Click Element | ios=.buttons().withName('Apps') | Matches by iOS UI Automation |
|
nsp | Click Element | nsp=name=="login" | Matches by iOSNsPredicate | Check PR: #196 |
css | Click Element | css=.green_button | Matches by css in webview |
|
name | Click Element | name=my_element | Matches by @name attribute | Only valid for Selendroid |
引入包
Arguments(参数) | Documentation(说明) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
timeout=5, run_on_failure=Capture Page Screenshot | 可以使用可选参数导入AppiumLibrary。 超时时间是用于等待所有等待操作的默认超时,后面可以用Set Appium Timeout 来设置
默认情况下Capture Page Screenshot 用来对当前页面进行截图。当其值为No Operation 的时候,该功能被完全禁用。有关此功能的更多信息,请查看Register Keyword To Run On Failure 关键字。 实例:
|
Background App · Capture Page Screenshot · Clear Text · Click A Point · Click Button · Click Element · Click Element At Coordinates · Click Text · Close All Applications · Close Application ·Element Attribute Should Match · Element Name Should Be · Element Should Be Disabled · Element Should Be Enabled · Element Should Be Visible · Element Should Contain Text · Element Should Not Contain Text ·Element Text Should Be · Element Value Should Be · Execute Async Script · Execute Script · Get Activity · Get Appium SessionId · Get Appium Timeout · Get Capability · Get Contexts · Get Current Context ·Get Element Attribute · Get Element Location · Get Element Size · Get Matching Xpath Count · Get Network Connection Status · Get Source · Get Text · Get Webelement · Get Webelements · Get Window Height ·Get Window Width · Go Back · Go To Url · Hide Keyboard · Input Password · Input Text · Input Value · Install App · Landscape · Launch Application · Lock · Log Source · Long Press · Long Press Keycode ·Open Application · Page Should Contain Element · Page Should Contain Text · Page Should Not Contain Element · Page Should Not Contain Text · Pinch · Portrait · Press Keycode · Pull File · Pull Folder · Push File· Quit Application · Register Keyword To Run On Failure · Remove Application · Reset Application · Scroll · Scroll Down · Scroll Up · Set Appium Timeout · Set Location · Set Network Connection Status · Shake ·Start Activity · Swipe · Swipe By Direction · Swipe By Percent · Switch Application · Switch To Context · Tap · Text Should Be Visible · Toggle Touch Id Enrollment · Touch Id · Wait Activity ·Wait Until Element Is Visible · Wait Until Page Contains · Wait Until Page Contains Element · Wait Until Page Does Not Contain · Wait Until Page Does Not Contain Element · Xpath Should Match X Times · Zoom
关键字
Keyword(关键字) | Arguments(参数) | 实例 | Documentation |
---|---|---|---|
Background App | seconds=5 | 把应用置于设备后台一段固定的时间 | |
Capture Page Screenshot | filename=None | 获取当前页面的屏幕截图并将其嵌入日志中。
filename参数指定要写入屏幕截图的文件名。如果没有给出文件名,屏幕截图将保存在Robot Framework日志文件写入目录下的文件appium screenshot-<counter>.png中。如果没有以绝对路径给出,文件名也被认为是在同一目录下的。 css可以用来修改截图的方式。默认情况下,当页面布局被某种方式破坏时,bakground颜色会被更改,以避免可能的后台泄漏问题。 | |
Clear Text | locator | clear text xpath=//android.widget.TextView[@text='转到账户'] | 清除对应文本框的文字 关于定位元素,查看 introduction |
Click A Point | x=0, y=0,duration=100 | click a point 10 20 | 点击坐标 |
Click Button | index_or_name | click button 登录 | 点击按钮 (这里“登录”的class属性,必须是Button) |
Click Element | locator | click element id=com.paic.zhifu.wallet.activity:id/edt_phonenum_v6
click element //android.widget.TextView[@text='任务']/.. | 点击元素, |
Click Element At Coordinates | coordinate_X,coordinate_Y | click element at coordinates 100 200 | 使用固定的坐标点击元素 |
Click Text | text,exact_match=False | click text 我的 |
默认情况下,尝试单击第一个文本涉及给定的文本,如果要单击完全匹配的文本,则将exact_match设置为True。 |
Close All Applications | 关闭所有打开的应用。 此关键字用于测试或套件teardown,以确保在测试执行完成之前关闭所有应用程序。 在此关键字之后,open application返回的应用程序索引将被重置并从1开始。
| ||
Close Application | Closes the current application and also close webdriver session. |
Element Attribute Should Match | locator, attr_name, match_pattern, regexp=False | 验证元素的属性是否符合预期条件。 元素由定位器标识。有关定位元素的详细信息,请参见简介。如果有多个元素匹配,则选择第一个元素。 attr_name是所选元素中属性的名称。
例如:
NOTE: On Android the supported attribute names are hard-coded in the AndroidElement Class's getBoolAttribute() and getStringAttribute() methods. Currently supported (appium v1.4.11): contentDescription, text, className, resourceId, enabled, checkable, checked, clickable, focusable, focused, longClickable, scrollable, selected, displayed NOTE: Some attributes can be evaluated in two different ways e.g. these evaluate the same thing:
| ||||||||||||||||||||||||
Element Name Should Be | locator, expected | 元素名称应该是。 element name should be [locator] 登录 | ||||||||||||||||||||||||
Element Should Be Disabled | locator,loglevel=INFO | 验证元素是否是被禁用的状态 任意元素的关键属性是id和name。有关定位元素的详细信息,请参见简介。 element should be disabled id=com.paic.zhifu.wallet.activity:id/close_btn | ||||||||||||||||||||||||
Element Should Be Enabled | locator,loglevel=INFO | 验证元素是否是可用的状态
| ||||||||||||||||||||||||
Element Should Be Visible | locator,loglevel=INFO | 元素是可见的
| ||||||||||||||||||||||||
Element Should Contain Text | locator, expected,message= | 验证 element should contain text [locator] ${text } 如果希望对元素的文本断言精确匹配(而不是子字符串),则应使用元素文本。
| ||||||||||||||||||||||||
Element Should Not Contain Text | locator, expected,message= | 验证 element should not contain text [locator] ${text } message可以用来覆盖默认的报错信息。
| ||||||||||||||||||||||||
Element Text Should Be | locator, expected,message= | 验证 element text should be [locator] ${text }
| ||||||||||||||||||||||||
Element Value Should Be | locator, expected | 验证 element value should be [locator] ${text } |
Execute Async Script | script | Inject a snippet of Async-JavaScript into the page for execution in the context of the currently selected frame (Web context only). The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, which is always provided as the final argument to the function. The value to this callback will be returned to the client. New in AppiumLibrary 1.5 | |||||||
Execute Script | script | Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame (Web context only). The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client. New in AppiumLibrary 1.5 | |||||||
Get Activity | Retrieves the current activity on the device. Android only. | ||||||||
Get Appium SessionId | Returns the current session ID as a reference | ||||||||
Get Appium Timeout | Gets the timeout in seconds that is used by various keywords. See Set Appium Timeout for an explanation. | ||||||||
Get Capability | capability_name | Return the desired capability value by desired capability name | |||||||
Get Contexts | Get available contexts. | ||||||||
Get Current Context | Get current context. | ||||||||
Get Element Attribute | locator, attribute | Get element attribute using given attribute: name, value,... Examples:
| |||||||
Get Element Location | locator | Get element location Key attributes for arbitrary elements are id and name. See introduction for details about locating elements. | |||||||
Get Element Size | locator | Get element size |