Talking about the automated testing tool Appium

Table of contents

Foreword:

1. Brief introduction

(1) Test object

(2) Supported platforms and languages

(3) Working principle

(4) Installation tools

2. Environment construction

(1) Install the Android SDK

(2) Install Appium Server

(3) Install python-client

3. Application and operation

(1) Call the appium process

(2) The first step is to configure the parameters of the mobile phone device

(3) The second step is to capture the controls applied on the mobile phone

(4) The third step is to operate the controls

Four. Summary


Foreword:

One of the main features of Appium is that it is a cross-platform tool that can run on different operating systems. This means you can use the same set of test scripts to run tests on different mobile platforms, saving time and resources.

1. Brief introduction

(1) Test object

appium is an open source tool for automated testing that supports native applications, web applications and hybrid applications on iOS and Android platforms.
● Mobile native application: an application written purely in ios or android development language, aimed at a certain type of mobile device, and can be directly installed in the device. Generally, it can be obtained through an application store, such as a game app; ● Mobile web application
: Applications accessed using mobile browsers (appium supports Safari on iOS and Chrome on Android), do not need to be downloaded to the device, but directly accessed through the browser, such as the H5 Jiuqu Fengshen game; ● Mixed applications: use
both Web page language and program language development, differentiate mobile operating system distribution through the application store, users need to install and use mobile applications, such as Taobao client on mobile phones

(2) Supported platforms and languages

● appium is cross-platform and supports OSX, Windows and Linux systems. It allows testers to use the same set of APIs to write automated test scripts on different platforms (iOS, Android), which greatly increases the reusability of code between iOS and Android test suites Appium supports multiple languages ​​and adopts C/S design
mode , as long as the client can send http requests to the server

(3) Working principle

The following image reference URL: http://www.testclass.net/appium/appium-base-summary/

As shown in the figure, appium is mainly divided into three points: client end, server end, and testing mobile devices
client end: test scripts written in various languages
​​server end: the part where we install appium tools, which is specially used for Listen to and receive requests from the client, forward requests and control mobile devices to perform tests, and enable and monitor interface 4723 by default
● Mobile devices: support three types of devices, our ultimate goal: to automatically perform specified operations on the device
The whole process:
first , install the appium tool ( server side) on a server, start the process (default 4723 interface) to monitor; second
, write a test script, place it on the server, and execute the test script (equivalent to sending commands to the server side)
3. The mobile device receives the command sent by the server and executes the specified operation

(4) Installation tools

● Test language, such as python
● appium client
● appium server
● mobile device, if you use a virtual machine, you need to install it

2. Environment construction

(1) Install the Android SDK

1. Android SDK (Software Development Kit, software development kit) provides Android API library and development tools to build, test and debug applications, which can be regarded as a software for developing and running Android applications. 2. Provide small tools, such
as adb, aapt, uiautomatorview
3. The test device uses an Android emulator, this step must not be skipped

(2) Install Appium Server

1. Download the appium installation package
2. Install and configure appium environment variables

(3) Install python-client

1. Install the programming language first, such as python language
2. Install Appium-Client, python can be installed with pip: pip install Appium-Python-Client

3. Application and operation

(1) Call the appium process

1. Configure the mobile device parameters and tell the server which mobile device I want to call.
2. Grab the controls applied on the mobile phone, and specify the corresponding controls to operate.
3. Operate the captured controls, such as Click, fill in parameters, etc.

(2) The first step is to configure the parameters of the mobile phone device

Appium 的 Desired Capabilities 基本配置如下:
#Android environment
import unittest
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
desired_caps['appPackage'] = package
desired_caps['appActivity'] = activity

self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

Explanation of common parameters:

● deviceName: Specify the startup device, such as Android Emulator, iPhone Simulator, etc.
● automationName: Specify the automation engine, the default is appium
● platformName: Specify the mobile platform, Android or iOS
● platformVersion: Specify the system version of the platform. For example, specify the Android system version as 4.2.
● appActivity: the Activity of the app to be tested. Note that a "." must be added before the activity for a native app.
● appPackage: the package name (package) information of the app to be tested

(3) The second step is to capture the controls applied on the mobile phone

Use the Android SDK built-in tool uiautomatorviewer.bat to view the control parameters of the mobile application (the tool is located in the /tools/bin/ directory)
1. ID positioning

Usage:
driver.find_element_by_id('com.android.contacts:id/three')

2. Name positioning

How to use:
el = self.driver.find_element_by_name('missed call')
el = self.driver.find_elements_by_name('missed call')

3. Class name positioning

使用方法:
els = self.driver.find_element_by_class_name('android.widget.ImageButton')
els = self.driver.find_elements_by_class_name('android.widget.ImageButton')

4, Accessibility ID localization

使用方法:
el = self.driver.find_element_by_accessibility_id('三')
el = self.driver.find_elements_by_accessibility_id('三')

5. Android uiautomator positioning

Usage:
el = self.driver.find_element_by_android_uiautomator('new UiSelector().description(star sign")')
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(false)')

(4) The third step is to operate the controls

1.scroll  
scroll(self, origin_el, destination_el):  
从元素origin_el滚动至元素destination_el  
举例:driver.scroll(el1, el2)  
用法:driver.scroll(el1,el2)

2.tap  
tap(self, positions, duration=None):  
模拟手指点击(最多五个手指),可设置按住时间长度(毫秒)  
举例:driver.tap([(100, 20), (100, 60), (100, 100)], 500)  
用法:driver.tap([(x,y),(x1,y1)],500)

3. swipe
swipe(self, start_x, start_y, end_x, end_y, duration=None):  
从A点滑动至B点,滑动时间为毫秒  
举例:driver.swipe(100, 100, 100, 400)  
用法:driver.swipe(x1,y1,x2,y2,500)

4. keyevent
keyevent(self, keycode, metastate=None):  
发送按键码(安卓仅有),按键码可以上网址中找到  
用法:driver.keyevent(‘4’)

5. press_keycode
press_keycode(self, keycode, metastate=None):  
发送按键码(安卓仅有),按键码可以上网址中找到  
用法:driver.press_ keycode(‘4’)

6.text
text(self):  
返回元素的文本值  
用法:element.text

7.click
click(self):  
点击元素  
用法:element.click()

8.get_attribute
get_attribute(self, name):   
获取某元素的相关值  
用法:element.get_attribute(“name”)

9.size
size(self):  
获取元素的大小(高和宽)  
用法 driver.element.size

10. page_source
page_source(self):    
获取当前页面的源  
用法:driver.page_source

11.quit
quit(self):   
退出脚本运行并关闭每个相关的窗口连接   
举例:driver.quit()

Four. Summary

1. Appium is cross-platform and supports Android and IOS automated testing.
2. Appium supports multiple languages, such as java, Object-C, JavaScript, Php, Python, Ruby, C#, Clojure, etc.
3. Supports native applications, web applications and hybrid applications
4. Only supports UI testing

  As someone who has been here, I also hope that everyone will avoid some detours

Here I will share with you some necessities of the way forward in automated testing, hoping to help you.

(software testing related materials, automated testing related materials, technical questions and answers, etc.)

I believe it can make you better progress!

Click on the small card below

Guess you like

Origin blog.csdn.net/Free355/article/details/131764410