AppiumLibrary 1.3.5英文api文档

Opening library documentation failed

  • Verify that you have JavaScript enabled in your browser.
  • Make sure you are using a modern enough browser. Firefox 3.5, IE 8, or equivalent is required, newer browsers are recommended.
  • Check are there messages in your browser's JavaScript error log. Please report the problem if you suspect you have encountered a bug.

AppiumLibrary

Introduction

AppiumLibrary is a App testing library for Robot Framework.

Locating elements

All keywords in AppiumLibrary that need to find an element on the app take an argument,locator. By default, when a locator value is provided, it is matched against the key attributes of the particular element type. For example,id and name are key attributes to all elements, and locating elements is easy using just theid as a locator. For example:

Click Element my_element

Appium additionally supports some of the Mobile JSON Wire Protocol (https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile) locator strategies It is also possible to specify the approach AppiumLibrary should take to find an element by specifying a lookup strategy with a locator prefix. Supported strategies are:

StrategyExampleDescription
identifierClick Element | identifier=my_elementMatches by @id or @name attribute
idClick Element | id=my_elementMatches by @id attribute
nameClick Element | name=my_elementMatches by @name attribute
xpathClick Element | xpath=//UIATableView/UIATableCell/UIAButtonMatches with arbitrary XPath
classClick Element | class=UIAPickerWheelMatches by class
accessibility_idClick Element | accessibility_id=tAccessibility options utilize.
androidClick Element | android=UiSelector().description('Apps')Matches by Android UI Automator
iosClick Element | ios=.buttons().withName('Apps')Matches by iOS UI Automation
cssClick Element | css=.green_buttonMatches by css in webview

Importing

ArgumentsDocumentation
timeout=5, run_on_failure=Capture Page Screenshot

AppiumLibrary can be imported with optional arguments.

timeout is the default timeout used to wait for all waiting actions. It can be later set withSet Appium Timeout.

run_on_failure specifies the name of a keyword (from any available libraries) to execute when a AppiumLibrary keyword fails. By defaultCapture Page Screenshot will be used to take a screenshot of the current page. Using the valueNo Operation will disable this feature altogether. See Register Keyword To Run On Failure keyword for more information about this functionality.

Examples:

LibraryAppiumLibrary10# Sets default timeout to 10 seconds 
LibraryAppiumLibrarytimeout=10run_on_failure=No Operation# Sets default timeout to 10 seconds and does nothing on failure

Keywords

KeywordArgumentsDocumentation
Background Appseconds=5

Puts the application in the background on the device for a certain duration.

Capture Page Screenshotfilename=None

Takes a screenshot of the current page and embeds it into the log.

filename argument specifies the name of the file to write the screenshot into. If nofilename is given, the screenshot is saved into file appium-screenshot-<counter>.png under the directory where the Robot Framework log file is written into. Thefilename is also considered relative to the same directory, if it is not given in absolute format.

css can be used to modify how the screenshot is taken. By default the bakground color is changed to avoid possible problems with background leaking when the page layout is somehow broken.

Clear Textlocator

Clears the text field identified by locator.

See introduction for details about locating elements.

Click A Pointx=0, y=0

Click on a point

Click Buttonindex_or_name

Click button

Click Elementlocator

Click element identified by locator.

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

Close All Applications 

Closes all open applications.

This keyword is meant to be used in test or suite teardown to make sure all the applications are closed before the test execution finishes.

After this keyword, the application indices returned by Open Application are reset and start from 1.

Close Application 

Closes the current application.

Element Attribute Should Matchlocator, attr_name, match_pattern, regexp=False

Verify that an attribute of an element matches the expected criteria.

The element is identified by locator. See introduction for details about locating elements. If more than one element matches, the first element is selected.

The attr_name is the name of the attribute within the selected element.

The match_pattern is used for the matching, if the match_pattern is

  • boolean or 'True'/'true'/'False'/'false' String then a boolean match is applied
  • any other string is cause a string match

The regexp defines whether the string match is done using regular expressions (i.e. BuiltIn Library'sShould Match Regexp or string pattern match (i.e. BuiltIn Library's Should Match)

Examples:

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 theAndroidElement 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 Should Be Disabledlocator, loglevel=INFO

Verifies that element identified with locator is disabled.

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

Element Should Be Enabledlocator, loglevel=INFO

Verifies that element identified with locator is enabled.

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

Element Value Should Belocator, expected 
Get Appium Timeout 

Gets the timeout in seconds that is used by various keywords.

See Set Appium Timeout for an explanation.

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

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

Get Elementslocator, first_element_only=False, fail_on_error=True

Return elements that match the search criteria

The element is identified by locator. See introduction for details about locating elements.

If the first_element is set to 'True' then only the first matching element is returned.

If the fail_on_error is set to 'True' this keyword fails if the search return nothing.

Returns a list of WebElement Objects.

Get Network Connection Status 

Returns an integer bitmask specifying the network connection type.

Android only.

See set network connection status for more details.

Get Source 

Returns the entire source of the current page.

Go Back 

Goes one step backward in the browser history.

Go To Urlurl

Opens URL in default web browser.

Example:

Open Applicationhttp://localhost:4755/wd/hubplatformName=iOSplatformVersion=7.0deviceName='iPhone Simulator'browserName=Safari
Go To URLhttp://m.webapp.com    
Hide Keyboardkey_name=None

Hides the software keyboard on the device. (optional) In iOS, use key_name to press a particular key, ex. Done. In Android, no parameters are used.

Input Passwordlocator, text

Types the given password into text field identified by locator.

Difference between this keyword and Input Text is that this keyword does not log the given password. See introduction for details about locating elements.

Input Textlocator, text

Types the given text into text field identified by locator.

See introduction for details about locating elements.

Input Valuelocator, text

Sets the given value into text field identified by locator. This is an IOS only keyword, input value makes use of set_value

See introduction for details about locating elements.

Landscape 

Set the device orientation to LANDSCAPE

Lock 

Lock the device

Log Sourceloglevel=INFO

Logs and returns the entire html source of the current page or frame.

The loglevel argument defines the used log level. Valid log levels areWARN, INFO (default), DEBUG, TRACE and NONE (no logging).

Long Presslocator

Long press the element

Long Press Keycodekeycode, metastate=None

Sends a long press of keycode to the device.

Android only.

See press keycode for more details.

Open Applicationremote_url, alias=None, **kwargs

Opens a new application to given Appium server. Capabilities of appium server, Android and iOS, Please checkhttp://appium.io/slate/en/master/?python#appium-server-capabilities

OptionMan.Description
remote_urlYesAppium server url
aliasnoalias

Examples:

Open Applicationhttp://localhost:4723/wd/hubalias=Myapp1platformName=iOSplatformVersion=7.0deviceName='iPhone Simulator'app=your.app 
Open Applicationhttp://localhost:4723/wd/hubplatformName=AndroidplatformVersion=4.2.2deviceName=192.168.56.101:5555app=${CURDIR}/demoapp/OrangeDemoApp.apkappPackage=com.netease.qa.orangedemoappActivity=MainActivity
Page Should Contain Elementlocator, loglevel=INFO

Verifies that current page contains locator element.

If this keyword fails, it automatically logs the page source using the log level specified with the optionalloglevel argument. Givin

Page Should Contain Texttext, loglevel=INFO

Verifies that current page contains text.

If this keyword fails, it automatically logs the page source using the log level specified with the optionalloglevel argument. Giving NONE as level disables logging.

Page Should Not Contain Elementlocator, loglevel=INFO

Verifies that current page not contains locator element.

If this keyword fails, it automatically logs the page source using the log level specified with the optionalloglevel argument. Givin

Page Should Not Contain Texttext, loglevel=INFO

Verifies that current page not contains text.

If this keyword fails, it automatically logs the page source using the log level specified with the optionalloglevel argument. Giving NONE as level disables logging.

Pinchlocator, percent=200%, steps=1

Pinch in on an element a certain amount.

Portrait 

Set the device orientation to PORTRAIT

Press Keycodekeycode, metastate=None

Sends a press of keycode to the device.

Android only.

Possible keycodes & meta states can be found in http://developer.android.com/reference/android/view/KeyEvent.html

Meta state describe the pressed state of key modifiers such as Shift, Ctrl & Alt keys. The Meta State is an integer in which each bit set to 1 represents a pressed meta key.

For example

  • META_SHIFT_ON = 1
  • META_ALT_ON = 2
metastate=1 --> Shift is pressed
metastate=2 --> Alt is pressed
metastate=3 --> Shift+Alt is pressed
  • _keycode- - the keycode to be sent to the device
  • _metastate- - status of the meta keys
Pull Filepath, decode=False

Retrieves the file at path and return it's content.

Android only.

  • path - the path to the file on the device
  • decode - True/False decode the data (base64) before returning it (default=False)
Pull Folderpath, decode=False

Retrieves a folder at path. Returns the folder's contents zipped.

Android only.

  • path - the path to the folder on the device
  • decode - True/False decode the data (base64) before returning it (default=False)
Push Filepath, data, encode=False

Puts the data in the file specified as path.

Android only.

  • path - the path on the device
  • data - data to be written to the file
  • encode - True/False encode the data as base64 before writing it to the file (default=False)
Register Keyword To Run On Failurekeyword

Sets the keyword to execute when a AppiumLibrary keyword fails.

keyword_name is the name of a keyword (from any available libraries) that will be executed if a AppiumLibrary keyword fails. It is not possible to use a keyword that requires arguments. Using the value "Nothing" will disable this feature altogether.

The initial keyword to use is set in importing, and the keyword that is used by default is Capture Page Screenshot. Taking a screenshot when something failed is a very useful feature, but notice that it can slow down the execution.

This keyword returns the name of the previously registered failure keyword. It can be used to restore the original value later.

Example:

Register Keyword To Run On FailureLog Source# Run Log Source on failure. 
${previous kw}=Register Keyword To Run On FailureNothing# Disables run-on-failure functionality and stores the previous kw name in a variable.
Register Keyword To Run On Failure${previous kw}# Restore to the previous keyword. 

This run-on-failure functionality only works when running tests on Python/Jython 2.4 or newer and it does not work on IronPython at all.

Remove Applicationapplication_id

Removes the application that is identified with an application id

Example:

Remove Applicationcom.netease.qa.orangedemo
Reset Application 

Reset application

Scrollstart_locator, end_locator

Scrolls from one element to another Key attributes for arbitrary elements are id and name. See introduction for details about locating elements.

Scroll Downlocator

Scrolls down to element

Scroll Uplocator

Scrolls up to element

Set Appium Timeoutseconds

Sets the timeout in seconds used by various keywords.

There are several Wait ... keywords that take timeout as an argument. All of these timeout arguments are optional. The timeout used by all of them can be set globally using this keyword.

The previous timeout value is returned by this keyword and can be used to set the old value back later. The default timeout is 5 seconds, but it can be altered inimporting.

Example:

${orig timeout} =Set Appium Timeout15 seconds
Open page that loads slowly  
Set Appium Timeout${orig timeout} 
Set Network Connection StatusconnectionStatus

Sets the network connection Status.

Android only.

Possible values:

ValueAliasDataWifiAirplane Mode
0(None)000
1(Airplane Mode)001
2(Wifi only)010
4(Data only)100
6(All network on)110
Shake 

Shake the device

Swipestart_x, start_y, end_x, end_y, duration=1000

Swipe from one point to another point, for an optional duration.

Switch Applicationindex_or_alias

Switches the active application by index or alias.

index_or_alias is either application index (an integer) or alias (a string). Index is got as the return value ofOpen Application.

This keyword returns the index of the previous active application, which can be used to switch back to that application later.

Example:

${appium1}=Open Applicationhttp://localhost:4723/wd/hubalias=MyApp1platformName=iOSplatformVersion=7.0deviceName='iPhone Simulator'app=your.app
${appium2}=Open Applicationhttp://localhost:4755/wd/hubalias=MyApp2platformName=iOSplatformVersion=7.0deviceName='iPhone Simulator'app=your.app
Click ElementsendHello# Executed on appium running at localhost:4755     
Switch Application${appium1}# Switch using index     
Click ElementackHello# Executed on appium running at localhost:4723     
Switch ApplicationMyApp2# Switch using alias     
Page Should Contain TextackHello Received# Executed on appium running at localhost:4755     
Switch To Contextcontext_name

Switch to a new context

Taplocator

Tap on element

Wait Until Page Containstext, timeout=None, error=None

Waits until text appears on current page.

Fails if timeout expires before the text appears. Seeintroduction for more information about timeout and its default value.

error can be used to override the default error message.

See also Wait Until Page Does Not Contain, Wait Until Page Contains Element, Wait Until Page Does Not Contain Element and BuiltIn keyword Wait Until Keyword Succeeds.

Wait Until Page Contains Elementlocator, timeout=None, error=None

Waits until element specified with locator appears on current page.

Fails if timeout expires before the element appears. Seeintroduction for more information about timeout and its default value.

error can be used to override the default error message.

See also Wait Until Page Contains, Wait Until Page Does Not Contain Wait Until Page Does Not Contain Element and BuiltIn keyword Wait Until Keyword Succeeds.

Wait Until Page Does Not Containtext, timeout=None, error=None

Waits until text disappears from current page.

Fails if timeout expires before the text disappears. See introduction for more information about timeout and its default value.

error can be used to override the default error message.

See also Wait Until Page Contains, Wait Until Page Contains Element, Wait Until Page Does Not Contain Element and BuiltIn keyword Wait Until Keyword Succeeds.

Wait Until Page Does Not Contain Elementlocator, timeout=None, error=None

Waits until element specified with locator disappears from current page.

Fails if timeout expires before the element disappears. Seeintroduction for more information about timeout and its default value.

error can be used to override the default error message.

See also Wait Until Page Contains, Wait Until Page Does Not Contain, Wait Until Page Contains Element and BuiltIn keyword Wait Until Keyword Succeeds.

Zoomlocator, percent=200%, steps=1

Zooms in on an element a certain amount.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值