Mobile Automation Testing--Appium's desired capabilities and positioning controls

Source: Internet
Author: User

First, desired capabilities

Desired capabilities must be provided at the start of the session.

Desired capabilities is essentially stored in the form of the key value dictionary, which the client sends to the server and tells the server how we want to test it. It tells Appium server something like:

    • This test starts the browser or starts the mobile device.

    • Whether to start Andorid or start iOS.

    • What is the app's package when you start Android?

    • What is the activity of the app when you start Android?

    • ...

The fixed wording is as follows:

desired_caps = {}
desired_caps[' platformname ' = ' Android '
desired_caps[' platformversion '] = ' 4.4.2 '
desired_caps[' devicename '] = ' 127.0.0.1:62001 '
desired_caps[' apppackage '] = ' com.tencent.mobileqq '
desired_caps[' appactivity ' = ' com.tencent.mobileqq.activity.SplashActivity ' # Android exclusive
desired_caps["Unicodekeyboard"] = "True"
desired_caps["Resetkeyboard"] = "True"
desired_caps["NoReset"] = "True"
Driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps)

  • DeviceName: Which device is started, is it a real machine or an emulator? IPhone simulator,ipad simulator,iphone Retina 4-inch,android emulator,galaxy S4 ...

  • Automationname: What kind of automation engine is used. Appium (default) or Selendroid.

  • PlatformName: which mobile platform to use. IOS, Android, Orfirefoxos.

  • Platformversion: Specifies the system version of the platform. For example, the Android platform, version 5.1.

  • Appactivity: The activity name of the app to be tested. such as Mainactivity,. Settings. Note that the native app should add a "." Before the activity.

  • Apppackage: The Java package for the app to be tested. Like Com.example.android.myApp, Com.android.settings.

  • Noreset:don ' t reset app state before this session
  • Resetkeyboard:reset keyboard to their original state, after running Unicode tests with unicodeKeyboard capability. ignored if used alone. Defaultfalse
  • Unicodekeyboard:enable Unicode Input, defaultfalse
  • /127.0.0.1:4723:appium-server Address

More parameter configuration: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

Knowledge Development: Positioning Apppackage and appactivity method

Download the latest build-tools in the SDK and check apppackage and appactivity with AAPT dump badging xxx.apk command .

cmd input adb logcat | findstr/i Start, force stop the software being tested, open again, observe logcat. (Manually open the apppackage that need to be operated, starting from the bottom of Logcat)

Second, positioning control

Appium to view the properties of a control by using the Uiautomatorviewer.bat tool. The tool is located in the/tools/bin/directory of the Android SDK.

1. ID Location

Driver. find_element_by_id(' Resource-id ')

# ID is different from selenium, there may be a duplicate problem.

# appium-desktop If an ID is present when fetching an element, it can be used directly.

# Resource-id may appear repetitive, need to see how many of them. 2. Class name positioningdriver. Find_element_by_class_name(' class ') # corresponding to the class field, there may be more than one class. # Multiple identical classes, each fetch takes only the first encountered element. 3. XPath positioningdriver. Find_element_by_xpath('//android.widget.edittext[@text = ' phone number '] ') # XPath path locator, with Web XPath positioned in a little bit different# Native App's positioning is based on class, mainly used in parameters such as text, Resource-id, index 4,accessibility ID Location-This method belongs to the Appium extension of the location methoddriver. find_element_by_accessibility_id(' Content-desc ') # Android corresponds to CONTENT-DESC ios corresponding accessibility identifier# Content-desc is a special field defined for people with disabilities 5,android Uiautomator positioning-this method belongs to Appium extension localization methodAndroid's source test framework for positioning, fast positioning speeddriver. Find_element_by_android_uiautomator(' new Uiselector (). Text ("Phone number") ') # Match all text textdriver. Find_elements_by_android_uiautomator(' new Uiselector (). ClassName ("Android.widget.TextView") # ClassName6, Iospredicatestringsupport for more than iOS10, can be multiple properties simultaneously location, recommended. (Alternative XPath)driver. Find_elements_by_ios_predicate("label = = ' Login ')

Mobile Automation Testing--Appium's desired capabilities and positioning controls

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.