Chapter III Appium API Introduction

Source: Internet
Author: User
Tags appium

Before learning to apply a framework, you should understand the framework of the overall structure or the corresponding API functions, search on the internet, and did not find the corresponding documents, I usually write test cases when the side of the writing while looking at the corresponding API function. This article is also good: http://www.51testing.com/html/15/n-1408815.html, copy over, expand, hope to everyone's learning to help.

3.1 Common API Functions 3.1.1Get information class API

(1) Gets the data in the Strings.xml file corresponding to the default system language.

Get_app_string ()

(2) Find a locale corresponding to the string file Strings.xml within the data.

Get_app_string (String language)

(3) Get the current activity, e.g. (. Apidemos)

Current_activity ()

3.1.2 App install and uninstall Class API

(1) According to Bundleid to determine whether the application has been installed

Is_app_installed (String Bundleid)

(2) Install App,apppath as the application's local path

Install_app (String AppPath)

(3) Uninstalling App.bundleid on Android represents the package name, and there is a dedicated Bundleid number in iOS.

Remove_app (String Bundleid)

(4) Close the application, in fact, just press the home button to put the app in the background

Close_app ()

(5) Start the application

Launch_app ()

(6) Closeapp first and then in Launchapp

Reset_app ()

3.1.3file Operations Class API

(1) writes a character array to a file in a remote directory in 64-bit format. It can also be understood to push local files to the device.

Push_file (String RemotePath, byte[] base64data)

(2) Pull the files on the device to the local hard drive

Pull_file (String RemotePath)

(3) Pull the folder on the device to the local hard drive, the remote file is the file under/data/local/tmp.

Pull_folder (String RemotePath)

3.1.4setting the related class API

(1) Set the phone 's network connection status, you can switch Bluetooth, WiFi, data traffic. The status of each network connection is set through the properties in networkconnectionsetting.

Set_network_connect (networkconnectionsetting connection)

(2) Get the status of the current network

Get_network_connection ()

3.1.5user Action Class API

(1) iOS hidden keyboard

Hide_keyboard ()

(2) Hide keyboard, can only be used on iOS.

Hide_keyboard (String strategy, String keyName)

(3) Press a key, which key is determined by the key value, the key value is defined in the Androidkeycode class

send_key_event (int key)

(4) Perform a touch action, which is encapsulated by the touchaction.

Perform_touchaction (touchaction touchaction)

(5) Click the center point of the element control, duration*5 seconds after the release, so repeat fingers times.

Tap (int fingers, webelement element, int duration)

(6) Click (x, y) Tap, duration*5 milliseconds after release, so repeat fingers times.

Tap (int fingers, int x, int y, int duration)

(7) slide from (Startx,starty) to (Endx,endy), duration step slip, each step is 5 milliseconds.

Swipe (int startx, int starty, int endx, int endy, int duration)

(8) 2 finger-operated controls, sliding from the diagonal to the center point.

Pinch (webelement el)

(9) with (x, y) as the benchmark, calculated (x,y-100), (x,y+100) two points, and then 2 fingers hold the two points while sliding to (x, y)

pinch (int x, int y)

(10) The exact opposite of the pinch (EL) action. Two fingers the center point of the control slowly slides to the right bottom after the left vertex of the control.

Zoom (Webelement el)

(11) The opposite of pinch (x, y). Two fingers slide from (x, Y) point to (x,y-100) and (x,y+100).

Zoom (int x, int y)

(12) Lock screen after how many seconds to unlock

Lock_screen (int seconds)

(13) Simulate shaking the phone

Shake ()

(14) Scroll to a text property for the specified string of controls

Scroll_to (String text)

(15) Scroll to a Text property containing the passed-in string control

Scroll_to_exact (String text)

(16) Setting the context

Context (String name)

(17) Available contexts

Get_context_handles ()

(18) Current context

Get_context ()

(19) Set screen horizontal screen or vertical screen

Rotate (screenorientation orientation)

(20) Get the current screen orientation

Get_orientation ()

3.1.6get control class API

(1) Use the properties in UIAutomation in iOS to get controls

Find_element_by_ios_uiautomation (String using)

(2) Same as above, but get multiple controls

Find_elements_by_ios_uiautomation (String using)

(3) Use the properties in Android's Uiautoamtor to get a single control.

Find_element_by_android_uiautomator (String using)

(4) Same as above, but the method gets multiple controls

Find_elements_by_android_uiautomator (String using)

(5) using the accessibility ID to get a single control

Find_element_by_accessibilityid (String using)

(6) Use Accessibility ID to get multiple controls

Find_elements_by_accessibilityid (String using)

Auxiliary class of 3.1.7 Appiumdriver

Mainly for gesture manipulation, such as sliding, long-press, drag and so on. The principle of touchaction is to put a series of actions in a chain, and then pass the chain to the server. After the server accepts the chain, it parses each action and executes it one by one.

Touchaction ()

(1) performing a press operation on the control

Press (Webelement el)

(2) Press operation at a point at coordinates (x, y)

Press (int x, int y)

(3) A press operation is performed on the x-coordinate offset X-units of the upper-left corner of the control El, and y offset Y-units on the left.

Press (webelement el, int x, int y)

(4) Release action, which represents an end sign of the series action.

Release ()

(5) Target El, move from another point to the target

Move_to (Webelement el)

(6) Target at (x, y) point, move from another point to the target

Move_to (webelement el, int x, int y)

(7) tap on the center point of the control

Tap (Webelement el)

(8) Tap at (x, y)

Tap (int x, int y)

(9) with the upper-left corner of the control El as the Datum, the x-axis moves to the right x units, and the y-axis moves down the Y-units. Tap on this point.

Tap (webelement el, int x, int y)

(10) Represents an empty operation, waiting for a period of time

Wait_action ()

(11) Wait ms seconds

wait_action (int ms)

(12) Control long Press

Long_press (Webelement el)

(13) Tap long Press

long_press (int x, int y)

(14) Offset Point Long press

Long_press (webelement el, int x, int y)

(15) Cancel execution of the action

Cancel ()

3.2Some notes about the API

Appium is a huge testing framework, of course, its corresponding API is also a lot of, I did not find the detailed introduction of the document. From the Internet to find a document, the common API has been mentioned, but it is not possible to cover all, when we write automated test cases, we have to think about there is no solution to your problem of the function? You can then go to Appium to find out, in order to better solve the problems you encounter.

For example, when we test a function, we first need to operate it, this time we have to take into account the corresponding click function, input operation function where are there? When we verify the results, do we want to check that the results are not consistent with what we expected? Then it's about to consider the corresponding assert function. The spirit of divergent thinking cannot be confined to the program itself.

3.3Summary of this chapter

in this chapter, we introduce some of the appium commonly used in the API functions, although not exhaustive, we may not be able to see a bit, but also to have an impression. When you are in the process of writing test cases, if you encounter the relevant actions, you can have an impression, and then use the editor's Lenovo function to find the corresponding API functions. In a later tutorial, we'll start with a succession of applications that allow you to start writing the corresponding automated test cases for any app.

Chapter III Appium API Introduction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.