First, appium working principle
The basic workflow is as follows:
- Appium provides a set of Web services that appium a server (4723 port) for communicating with the script client.
- The server receives the Web driver (i.e. Appium client) standard request, parses the request content, and invokes the corresponding framework response operation.
- Appium server forwards the request to the Bootstrap.jar,bootstrap on the device in Android to receive the Appium command (Port 4724), and the underlying operation is performed by invoking the Uiautomator command.
- The execution results are also returned to Appium server by bootstrap.
Schematic diagram:
Two ports:
- 4723:appium server communication with the Automation script client
- 4724:appium server communication to mobile devices
Second, Appium advantages
- Box platform
- Cross-application
- Cross-Architecture: supports native and WebView two architectures
- Cross-language: Do not restrict scripting languages
- Other: Do not rely on source code, do not need to re-sign, unrestricted testing framework and platform (Eg:testng,jtest)
Third, use case writing process
1, start Appium server;
2, init driver;
Desiredcapabilities settings: app, device, PlatformName, devicename, Udid, timeout, etc.
3, use case execution: Simulate the user to do UI operation;
4. Test Complete:
1. 卸载app:removeapp 2. driver退出:driver.quit()
Four, the common API element positioning
The Appium element positioning method relies on selenium, so selenium positioning, appium support, and Android and iOS native positioning methods are supported.
Element Positioning method:
Method |
meaning |
Findelementbyid |
The id attribute of the element |
Findelementsbyname |
The Name property of the element |
Findelementbytagname |
The label name of the element |
Findelementsbyclassname |
The class property of the element |
Findelementbycssselector |
Selenium's most powerful positioning method, faster than XPath, but harder than XPath |
Findelementbyxpath |
What is XPath |
Findelementbycssselector |
Selenium's most powerful positioning method, faster than XPath, but harder than XPath |
Findelementsbylinktext |
All display text for linked elements |
Findelementbypartiallinktext |
Part of a linked element displays text |
Accessibilityid |
Appium is used to override the name positioning method, android-mainly uses the element's CONTENT-DESC attribute; ios-uses the element's label or name |
Findelementbyandroiduiautomator (New Uiselector (). Text (text)) |
Find by text |
Android Common methods: ID, ClassName, XPath, Androiduiautomator, Accessibilityid.
(i) Element positioning attributes supported by Androiduiautomator
index(int index)text(String text)resourceId(String id)className(String className)packageName(String packageName)description(String desc)checked(boolean val)clickable(boolean val)enabled(boolean val)longClickable(boolean val)password(boolean val)selected(boolean val)instance(int val)
Feature: All attributes of an element can be used for positioning, very powerful and fast.
(ii) XPath element positioning
1. Use absolute path
driver.findElementByXPath("className/className/className/className");
2. Using relative paths
driver.findElementByXPath("//className");
3. Using the index of an element
driver.findElementByXPath("//className[index]");
4. Positioning by attributes of elements
driver.findElementByXPath("//className[@label='XXX'][@isVisible='1']");
V. Driver support operation of common API
//元素操作 webElement.click(); webElement.sendkeys(); //文件传输 driver.pushFile(remotePath, file); driver.pullFile(remotePath); //启动activity driver.startActivity(activity); //APP操作 driver.installApp(appPath); driver.resetApp(); driver.launchApp(); driver.closeApp(); driver.removeApp(bundleId);
Vi. assertions of common APIs
Assert.assertTrue(boolean);Assert.assertFalse(boolean);Assert.assertSame(expected, actual);Assert.assertEquals(expected, actual);
Androiddriverwait: Wait for the xxx element to appear
Principle Reference: 69220719
Appium First Knowledge