Appium Introductory Knowledge

Source: Internet
Author: User

UI Automation related Tools

1. Appium Platform

2, Apple's uiautomation

3, Google's uiautomation

A brief introduction to these tools:

1, Appium Introduction

Appium uses Webdriver's JSON wire protocol to drive the UIAutomation Library of the Apple system and the Uiautomator framework of the Android system.

Appium uses standard automation APIs on different platforms, so there is no need to recompile or modify your application when cross-platform.

Appium supports more languages, such as Java, Object-c, JavaScript, PHP, Python, Ruby, C #, Clojure, or Perl languages.

2, Apple's uiautomation

The Apple home uiautomation is a test framework that comes with Xcode, which can be run in instruments and can be directly recorded and run directly.

Using only Apple's uiautomation, we can only use JavaScript to write test cases, and we can only run test cases with instruction.

3, Google's uiautomation

Google's uiautomation is Google's own UI Automation testing tool.

Using only Google's uiautomation, we can only write test cases in Java.

Appium Introduction

The core of Appium is a Web server that provides a set of REST interfaces. It receives the client's connection, hears the command, executes the commands on the mobile device, and returns the execution results to the client in the HTTP response.

Environment construction

I used a relatively simple script python to complete the Appium script, the following is the completion of the UI Automation with Python, the environment is set up as follows:

1, installation Appium

2. Install Appium python Client

Other environmental requirements

1. IOS

Mac OS X 10.7 or higher, recommended 10.9.2

XCode >= 4.6.3, recommended 5.1.1

Apple Developer Tools

2. Android

Android SDK API >= 17 (recommendation 18/19)

How to invoke Python code

1. Open Appium

Open the Appium corresponding installation path, for example: C:\Program Files (x86) \appium\node_modules\.bin

Under this path, run: Appium to start, appium default is to automatically install APK

If you need not install, add a parameter, start the command as follows: Appium--no-reset

2. Calling the Python script

Navigate to the path of the written Python script main.py first

Then run the command:

Python-m UnitTest Main

Introduction to Python Scripting

Desired capabilities

Desired capabilities is a collection of key-value pairs (for example, a map or hash), the client sends these key-value pairs to the server and tells the server how we want to test them. For example, we can set the PlatformName capability to iOS and tell the Appium server that we want an iOS session instead of an Android.

desired_capabilities.py

When writing a Python script, you need to create 2 files: desired_capabilities.py and main.py

Desired_capabilities.py is mainly established get_desired_capabilities ()

First, Get_desired_capabilities ()

Gets the arguments for this session. There are 8 main parameters set here. Users can adjust according to their own needs.

1. PlatformName, we test the target machine.

2. Platformversion, test the system version of the target device.

3. DeviceName, the name of the test machine (the name of the device).

4. Apppackage, the package name of the application being tested (only for Android testing).

5. Appwaitpackage, the test will wait (only for Android test).

6. App, where the application files are being tested

7. Newcommandtimeout, the maximum time interval for two instructions. If this interval is exceeded, Appium server will terminate this session.

8. Automationname, the automation engine used for this session. Android 4.2 below system please use Selendroid;ios, Android 4.2 or more (included) please use Appium.

Second, main.py

Is the functionality of the UI script.

Common methods to organize

1. Find Control methods

1) ID: Search by Resource-id. Note that when testing Android apps, the Appium engine and the Selendroid engine have different IDs, appium similar to this: Com.alibaba.mts.mtsdemoapp:id/login_login_button While the Selendroid ID is: Login_login_button. Therefore, if you want to write a generic script, we recommend that you use a different lookup method.

2) XPath: Search by XPath. For example, find a TextView control that contains the "add Note" string: Driver.findelement (By.xpath, "//android.widget.textview[contains (@text, ' Add note ‘)]")。

3) Link_text: (Does not support Android 4.2.1 or less) search through the text text of the control, such as: Driver.findelement (by.link_text, "login"), find the control text is "login" control. Note that it does not match the words "Login Bar", "Fast login" and so on. It is recommended to use the following "Partial_link_text".

4) Partial_link_text: (Does not support Android 4.2.1 below) similar to Link_text, but can match "login Bar", "Fast login" and other text control. Just include "Sign in".

5) Tag_name: Search by control class name, such as EditText, button, etc.

6) Class_name: Search by the full class name of the control, such as Android.widget.EditText, Android.widget.Button, etc.

The properties of these controls can be viewed with the Uiautomatorviewer tool, as shown in:

2. Common operation

1) Slide the screen, such as the slide of the guide page

Driver . Swipe (startx, starty,endx,endy,duration)

Start and end coordinates, duration indicates the sliding time, the longer the slide the more slowly left and right, the y-coordinate is unchanged

2) Click the button

Driver.click ()

3) Wait

Time.sleep (N)

N is the time to wait, in seconds

4) lock screen

Driver . Lock (5)

5) put the app in the background

Driver . Background_app (5)

6) Close up the keyboard

Driver . Hide_keyboard ()

7) Open the notification bar

Driver . open_notifications ()

8) Check if installed

Driver . is_app_installed (' Com.example.android.apis ')

9) Install the application to the device

Driver . Install_app (' path/to/my.apk ')

Remove the app from your device

Driver . Remove_app (' Com.example.android.apis ')

One) simulate equipment shaking

Driver . Shake ()

Close the app

Driver . Close_app ()

(key event)

Send a key event to the device

Driver . keyevent (176)

- ) through MQC inspection

You can enter MQC's own inspection instructions directly in your code.

Self.driver.shell ("Log-p i-t Mqc-log-master screenshot")

Appium Introductory Knowledge

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.