1. Test object
Appium is an open source tool for automating native, mobile web and hybrid applications on iOS, Android devices and Windows desktop platforms.
"Native applications" refer to those applications written with iOS, Android or Windows SDK.
"Mobile web application" is an application accessed with a mobile browser (Appium supports Safari, Chrome on iOS and the built-in browser on Android).
"Hybrid Apps" come with a wrapper around a "webview" - a native control used to interact with web content.
Important: Appium is cross-platform: it allows you to write tests for multiple platforms using the same API, reusing code between iOS, Android and Windows test suites.
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. Adopting the C/S design mode, as long as the client can send http requests to the server
3. Working principle
APPIUM IOS working principle
Let’s go through a The picture shows the working principle of the whole process of IOS APPIUM:
APPIUM The working principle of Android side
Let’s take a look at the android APPIUM through a picture. Working principle of the whole process:
Explanation:
The entire arrow points to a completed instruction loop
webdriver script requires automated testers themselves Write the corresponding test script
It is recommended that you learn about JSON wire protocol, instruments, UiAutomator
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
5, environment setup
( 1) Install Android SDK
1. Android SDK (Software Development Kit) provides Android API libraries and development tools to build, test and debug applications. It can be regarded as used to develop and run Android An application software
2. Provide small tools, such as adb, aapt, uiautomatorview
3. Use the Android emulator to test the device. This step must not be skipped
( 2) Install appium Server
1. Appium official website: https://pium.app/downloads/
2. Download the appium installation package (AppiumForWindows.zip, appium.dmg)
3. Install and configure appium environment variables
(3) Install python-client
1. First install a programming language, such as python language
2. Install Appium-Client, if you use python, you can use pip to install it: pip install Appium-Python-Client
6. Application and operation
①Calling the appium process
1. Configure the mobile device Parameters, tell the server which mobile device I want to call up
2. Grab the controls applied on the phone and specify the corresponding controls to operate
3. Grab the Operate the controls you get, such as clicking, filling in parameters, etc.
The first step is to configure the mobile phone device parameters
The basic configuration of Appium’s Desired Capabilities is as follows:
#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)
Common parameter explanation:
● 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 for native apps, add a "."
● appPackage: the package of the app to be tested. Name (package) information
The second step is to capture the controls of the mobile application
Use the Android SDK built-in tool uiautomatorviewer.bat to view the control parameters of the mobile application (the tool is located in /tools/ bin/ directory)
1. ID positioning
Usage method:
driver.find_element_by_id('com.android.contacts: id/three')
2. Name positioning
Usage method:
el = self.driver.find_element_by_name('missed call') el = self.driver.find_elements_by_name('missed call')
3. class name positioning
Usage:
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 positioning
Usage method:
el = self.driver.find_element_by_accessibility_id('三') el = self.driver .find_elements_by_accessibility_id('三')
5. android uiautomator positioning
##Usage method: el=self.driver.find_element_by_android_uiautomator( 'new UiSelector().description(star symbol ")')els=self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(false)')Step 3 , Operation control1.scrollscroll(self, origin_el, destination_el):Scroll from element origin_el to element destination_elExample: driver. scroll(el1, el2)Usage: driver.scroll(el1,el2)2.taptap(self, positions, duration=None):Simulate finger click (up to five fingers), you can set the holding time (milliseconds) Example: driver.tap([(100, 20), (100, 60), (100 , 100)], 500)Usage: driver.tap([(x,y),(x1,y1)],500)3. swipe swipe(self, start_x, start_y, end_x, end_y, duration=None):Swipe from point A to point B, the sliding time is millisecondsExample: driver.swipe(100, 100 , 100, 400)Usage: driver.swipe(x1,y1,x2,y2,500)4. keyeventkeyevent(self, keycode, metastate= None):Send key code (Android only), the key code can be found on the URLUsage: driver.keyevent('4')5. press_keycode press_keycode(self, keycode, metastate=None):Send the keycode (Android only), the keycode can be found in the URLUsage: driver.press_ keycode('4')6.texttext(self):Returns the text value of the elementUsage:element.text7.clickclick(self):Click on the elementUsage:element.click()8.get_attributeget_attribute(self, name):Get the related value of an elementUsage: element.get_attribute("name")9.sizesize(self):Get the size of the element (height and width)Usage driver.element.size10. page_sourcepage_source(self):Get the source of the current pageUsage: driver.page_source11.quitquit(self):Exit the script and close each related window connectionExample: driver.quit()Execution result judgmentAfter the use case is executed, judgment needs to be made When passing or not, you need to compare it with your expected result. Generally, you can choose to assert to find whether a certain flag appears, or whether the text value of a certain element is equal to the expected value. You can also take a screenshot and compare it with a reference picture, etc.The above is the detailed content of What are the knowledge points of Appium framework?. For more information, please follow other related articles on the PHP Chinese website!