Appium Automation Test (ii)

Source: Internet
Author: User
Tags xpath appium

I. Get the app package name and portal Activity

Get the app package name and Portal Activity:aapt command

AAPT directory:

Android SDK Build-tools directory (if you want to run in cmd, configure environment variables, otherwise you need to open cmd in the directory where AAPT is located)

Example:

adt-bundle-windows-x86_64-20140702\sdk\build-tools\android-4.4w

Command syntax:

AAPT dump badging apk Install package name

Example:

AAPT dump badging D:\Python full stack automation \python_ tool \appium+ Simulator \future-release-2018.apk

Search for launchable-activity, get activity on start Page

Part of the Code

# Start Page Two ways desired_caps["appactivity"". Activity.addition.WelcomeActivity"desired_caps["appactivity"  "com.xxzb.fenwoo.activity.addition.WelcomeActivity"

Actual effect

two. Hybird & Webview

Hybird Hybrid Application, embedding WebView in applications, accessing Web pages via WebView

WebView is a control that presents Web pages based on the WebKit engine.

Role:

    • Display and render the Web interface

    • Use HTML files directly (Web or APK resource Pack assets) for layout

    • Can be called interactively with JavaScript

three. Native APP

Traditional native app development model, Android based Java language, the underlying call Google provides api,ios based on objective C or swift, the underlying call Apple's official API

Tips

1. In the phone/simulator click about version number 5 in the phone, out developer options

2. Tick show layout boundaries in developer options

3. If the interface is HTML, the interface will not have layout boundary display, if there is a native interface

four. Android Layout type

Five. Common Controls
    • TextView

    text controls, displaying text/text

    • EditText

    Editable input box for receiving user-entered data

    • Button  

    button, the user triggers a series of events by clicking the button

    • CheckBox

    Check/multi-select button

    • ImageView

picture controls, for displaying pictures

    • ProgressBar

Load a progress bar indicating that some data is being loaded

six. Control Properties
    • Index

Index

    • Text

text Description, the new version needs to be used: Findelementbyandroiduiautomator ("New Uiselector ()." Text (\ "teacher team \") ")

    • Resource-id

control/Layout bounds

[480 1179] Description of the control/layout starting coordinates: X, Y axis

[720 1280] Description of control/layout termination coordinates: X, Y axis

Appendix:

seven. Appium-app page element Positioning

1. Locating elements by ID: Resource-id

2. Position via text (discarded)

3. Positioning by classname: ClassName

4. Positioning by Accessibilityid: Content-desc

5. Positioning via Androiduiautomator

6. Positioning by XPath

#Resource-id PositioningDRIVER.FIND_ELEMENT_BY_ID ("Com.xxzb.fenwoo:id/layout_borrow_money")#classname PositioningDriver.find_element_by_class_name ("Android.widget.RelativeLayout")#Content-desc PositioningDRIVER.FIND_ELEMENT_BY_ACCESSIBILITY_ID ("")#uiautomator (all attributes supported) positioningDriver.find_element_by_android_uiautomator ('new Uiselector (). ResourceId ("Com.xxzb.fenwoo:id/layout_item3")')#XPath positioningDriver.find_element_by_xpath ('//android.widget.textview[@text =\ "borrowing term \"]')

XPath, ID, class, accessibility ID,-android uiautomator

eight. UI Automator

UI Automation test framework, Android mobile app

requirements: Android 4.3 or above

    • Provides a series of APIs: Perform UI tests on a system or third-party app

    • Allows operation on the device under test, such as opening the System settings menu

    • Suitable for writing black box automation tests

The main features of the UI Automator Framework are:

1. Element positioning: The UI Automator Viewer scans and analyzes the image tools for the UI components of the application under test

2. Element manipulation: Accessing device state for various operations on target devices and apps

3. Element recognition: UI Automator APIs capture and manipulate UI components in multiple applications

Nine. UI Automator Viewer

Element recognition Tool: UI Automator Viewer

In the tools directory under the Android SDK

10. UI automators APIs

UIObject class: Android Component Object

The object has many methods and properties that simulate the actual operation of the phone, such as: text editing, gesture manipulation, etc.

Like in Web Automation, Element objects (webelement), with clicks, input operations, etc.

Uiselector class:

locating components through various properties of components and node relationships

Calling method: New Uiselector (). ResourceId ("")

New Uiselector (). ClassName (\ "android.widget.linearlayout\"). ResourceId (\ "com.xxzb.fenwoo:id/layout_item3\")

Because the return value of a function is the instantiation of the object itself, it can constantly call many methods

Uidevice class: Provides a series of methods and properties to simulate the actual operation on the phone (higher level, similar to document or window)

Get device Information: screen resolution, optional status, light off screen ...

Operation: Key, coordinate operation, slide, drag 、......

11. Androiduiautomator positioning (double quotes in Java represent strings, so positional expressions must be double quotes)

Using the Uiselector class in Uiautomator to handle element positioning

In the Python client appium library, the uiautomator to get the element is: Driver.find_element_by_android_uiautomator ()

The method's argument is an expression of the Uiselector class locating the element: New Uiselector (). Function name ("Positional expression")

New Uiselector (). Function name ("Positional expression")

Instantiates an Uiselector object and then invokes the interface through an instance

Example:

Driver.find_element_by_android_uiautomator (' new Uiselector (). ResourceId ("Com.xxzb.fenwoo:id/btn_login") ' )

12. Example
 fromAppiumImportWebdriver fromSelenium.webdriver.support.waitImportwebdriverwait fromSelenium.webdriver.supportImportExpected_conditions as EC fromAppium.webdriver.common.mobilebyImportMobileby#It's up to you to tell Appium server which app on which device I'm working on#desired capabilities--key value name. The key names are already defined.#information preparation for manipulating objectsDesired_caps = {}#operating system--target machinedesired_caps["PlatformName"] ="Android"#System Versiondesired_caps["platformversion"] ="5.1.1"#Device Namedesired_caps["devicename"] ="Android Emulator"#App Info#Package Namedesired_caps["Apppackage"] ="Com.xxzb.fenwoo"#Home Pagedesired_caps["appactivity"] =". Activity. Mainactivity"#Connect to Appium server and tell it to manipulate the objectDriver = Webdriver. Remote ('Http://127.0.0.1:4723/wd/hub', Desired_caps)#waitWebdriverwait (Driver, 1). Until (Ec.visibility_of_element_located (mobileby.id,"Com.xxzb.fenwoo:id/btn_login")))#Click the Sign in registration buttonDRIVER.FIND_ELEMENT_BY_ID ("Com.xxzb.fenwoo:id/btn_login"). Click ()#waitWebdriverwait (Driver, 1). Until (Ec.visibility_of_element_located (mobileby.id,"Com.xxzb.fenwoo:id/et_phone")))#Enter user nameDRIVER.FIND_ELEMENT_BY_ID ("Com.xxzb.fenwoo:id/et_phone"). Send_keys ("18684720553")#Next StepDRIVER.FIND_ELEMENT_BY_ID ("Com.xxzb.fenwoo:id/btn_next_step"). Click ()
13. Appium Function Introduction

Appium Automation Test (ii)

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.