AppiumLibrary 关键字

在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 来设置

run_on_failure 用来指定当AppiumLibrary关键字失败时要执行的关键字(来自任何可用库)的名称。

默认情况下Capture Page Screenshot 用来对当前页面进行截图。当其值为No Operation 的时候,该功能被完全禁用。有关此功能的更多信息,请查看Register Keyword To Run On Failure  关键字。

实例:

LibraryAppiumLibrary10

#设置默认超时时间为10s 

 

 
LibraryAppiumLibrarytimeout=10run_on_failure=No Operation

# 设置默认超时时间为10s ,并且在失败的时候不做任何操作

 

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 Appseconds=5 

把应用置于设备后台一段固定的时间

Capture Page Screenshotfilename=None 

获取当前页面的屏幕截图并将其嵌入日志中。

 

filename参数指定要写入屏幕截图的文件名。如果没有给出文件名,屏幕截图将保存在Robot Framework日志文件写入目录下的文件appium screenshot-<counter>.png中。如果没有以绝对路径给出,文件名也被认为是在同一目录下的。

css可以用来修改截图的方式。默认情况下,当页面布局被某种方式破坏时,bakground颜色会被更改,以避免可能的后台泄漏问题。

Clear Textlocator

clear   text  

xpath=//android.widget.TextView[@text='转到账户']

清除对应文本框的文字

关于定位元素,查看 introduction 

Click A Pointx=0, y=0,duration=100click  a  point   10   20  

点击坐标  

Click Buttonindex_or_nameclick button  登录

点击按钮  (这里“登录”的class属性,必须是Button)

Click Elementlocator

click  element 

 id=com.paic.zhifu.wallet.activity:id/edt_phonenum_v6

 

click  element      //android.widget.TextView[@text='任务']/..

点击元素,

Click Element At Coordinatescoordinate_X,coordinate_Yclick  element  at  coordinates  100    200  

使用固定的坐标点击元素

Click Texttext,exact_match=Falseclick  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是所选元素中属性的名称。

 

例如:

Element Attribute Should Matchxpath = //*[contains(@text,'foo')]text*foobar 
Element Attribute Should Matchxpath = //*[contains(@text,'foo')]textf.*arregexp = True
Element Attribute Should Matchxpath = //*[contains(@text,'foo')]enabledTrue 
1. is a string pattern match i.e. the 'text' attribute should end with the string 'foobar'
2. is a regular expression match i.e. the regexp 'f.*ar' should be within the 'text' attribute
3. is a boolead match i.e. the 'enabled' attribute should be True

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 Attribute Should Matchxpath = //*[contains(@text,'example text')]nametxt_field_name
Element Name Should Bexpath = //*[contains(@text,'example text')]txt_field_name 
Element Name Should Belocator, expected 

元素名称应该是。

element  name  should  be   [locator]    登录

Element Should Be Disabledlocator,loglevel=INFO 

验证元素是否是被禁用的状态

任意元素的关键属性是id和name。有关定位元素的详细信息,请参见简介。

element  should  be disabled     id=com.paic.zhifu.wallet.activity:id/close_btn

Element Should Be Enabledlocator,loglevel=INFO 

验证元素是否是可用的状态

 

Element Should Be Visiblelocator,loglevel=INFO 

元素是可见的

 

Element Should Contain Textlocator, expected,message= 

验证locator包含text

element should  contain  text    [locator]     ${text }

如果希望对元素的文本断言精确匹配(而不是子字符串),则应使用元素文本。

 

Element Should Not Contain Textlocator, expected,message= 

验证locator不包含text

element should  not  contain  text    [locator]     ${text }

message可以用来覆盖默认的报错信息。

 

Element Text Should Belocator, expected,message= 

验证locator 的text 应该是

element  text  should  be    [locator]     ${text }

 

Element Value Should Belocator, expected 

验证locator 的value 应该是

element  value  should  be    [locator]     ${text }

 

Execute Async Scriptscript 

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 Scriptscript 

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 Capabilitycapability_name 

Return the desired capability value by desired capability name

Get Contexts  

Get available contexts.

Get Current Context  

Get current context.

Get Element Attributelocator, attribute 

Get element attribute using given attribute: name, value,...

Examples:

Get Element Attributelocatorname
Get Element Attributelocatorvalue
Get Element Locationlocator 

Get element location

Key attributes for arbitrary elements are id and name. See introduction for details about locating elements.

Get Element Sizelocator 

Get element size

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值