Appium Automation Testing (3)--appium framework and process Introduction

Source: Internet
Author: User
<span id="Label3"></p>Appium Introduction<p><p>Appium is a mobile-based automation framework that can be used to test native applications, mobile Web applications and hybrid applications, and is cross-platform. Available for iOS and Android as well as for Firefox operating Systems. Native apps are apps written using an Android or iOS sdk, which is a web app that resembles a safari app or Chrome app or class browser app in Ios. Hybrid application refers to the application of webview, which is applied to Web content Interactivity.<br>What's important is that Appium is cross-platform and cross-platform, meaning that you can use a set of APIs for different platforms to write test Cases.</p></p><p><p></p></p><p><p>, Appium is divided into three main points: client side, server side, and test mobile device<br>Client side: test scripts written in various languages<br>Server Side: We install the part of the Appium tool, dedicated to listening and receiving requests from the client side, forwarding requests and controlling the mobile device to perform the test, by default turn on and listen to the 4723 interface<br>Mobile Devices: support for three types of devices, our ultimate goal: automatic execution of specified actions on the device<br>The whole process:<br>first, Install the Appium tool on a server (server side), open the process (the default 4723 interface) to listen;<br>second, write the test script, put it on the server, execute the test script (equivalent to send a command to the server Side)<br>third, The mobile device receives a command sent from the server side, performing the specified action</p></p>Appium Application and operation<p><p><strong>(i) Call the Appium process</strong><br>1, Configure the phone device parameters, tell the server side I want to set up which phone device<br>2, grab the controls applied on the phone, specify the corresponding controls to operate<br>3, the control to crawl to operate, such as click, fill in parameters, etc.<br><strong>(ii) the first step, the configuration of mobile device parameters</strong><br>Appium's desired Capabilities Basic configuration is as Follows:</p></p><pre><span style="color: #0000ff"><span style="color: #0000ff"></span> from</span>Appium<span style="color: #0000ff"><span style="color: #0000ff">Import</span></span><span style="color: #000000"><span style="color: #000000">Webdriverdesired_caps</span></span>=<span style="color: #000000"><span style="color: #000000"> { </span></span><span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">PlatformName</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>:<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">Android</span></span><span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #000000"><span style="color: #000000">, </span></span><span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">devicename</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>:<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">611AKBPP22HR5</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>,<span style="color: #008000"><span style="color: #008000">#</span></span><span style="color: #008000"><span style="color: #008000">device name found by ADB devices</span></span> <span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">platformversion</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>:<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">4.4.2</span></span><span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #000000"><span style="color: #000000">, </span></span><span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">Apppackage</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>:<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">Com.duowan.mobile</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>,<span style="color: #008000"><span style="color: #008000">#</span></span><span style="color: #008000"><span style="color: #008000">package name of the app under test</span></span> <span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">appactivity</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>:<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">com.yy.mobile.ui.splash.SplashActivity</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>,<span style="color: #008000"><span style="color: #008000">#</span></span><span style="color: #008000"><span style="color: #008000">Activity at startup</span></span><span style="color: #000000"><span style="color: #000000">}driver</span></span>= Webdriver. Remote (<span style="color: #800000"><span style="color: #800000">'</span></span><span style="color: #800000"><span style="color: #800000">Http://localhost:4723/wd/hub</span></span><span style="color: #800000"><span style="color: #800000">'</span></span>, Desired_caps)</pre><p><p>Common parameter Explanation:<br>Devicename: Specify the boot device, such as Android Emulator, IPhone simulator, etc.<br>Automationname: Specify the automation engine, default Appium<br>Platformname: Specify mobile platform, Android or iOS<br>platformversion: Specifies the system version of the PLATFORM. For example, specify Android system version 4.2<br>Appactivity: the activity of the app to be tested, note that the native app should add a "." before the Activity.<br>Apppackage: Package name information for the app to be tested<br><strong>(iii) second step, grab the controls applied on the phone</strong><br>Use the Android SDK built-in tool Uiautomatorviewer.bat to view the control parameters for your phone app (located in The/tools/bin/directory)<br>1. ID Location</p></p><p><p></p></p><p><p>How to Use:<br>driver.find_element_by_id (' Com.android.contacts:id/three ')</p></p><p><p>2. Name positioning</p></p><p><p></p></p><p><p>How to Use:<br>El = Self.driver.find_element_by_name (' missed call ')<br>El = Self.driver.find_elements_by_name (' missed call ')</p></p><p><p>3. Class name positioning</p></p><p><p></p></p><p><p>How to Use:<br>Els = self.driver.find_element_by_class_name (' Android.widget.ImageButton ')<br>Els = self.driver.find_elements_by_class_name (' Android.widget.ImageButton ')</p></p><p><p>4, Accessibility ID Location</p></p><p><p></p></p><p><p>How to Use:<br>El = self.driver.find_element_by_accessibility_id (' three ')<br>El = self.driver.find_elements_by_accessibility_id (' three ')</p></p><p><p>5, Android Uiautomator Positioning</p></p><p><p></p></p><p><p>How to Use:<br>el = self.driver.find_element_by_android_uiautomator (' new uiselector (). description (star symbol ") ')<br>Els = self.driver.find_elements_by_android_uiautomator (' new uiselector (). clickable (false) ')</p></p><p><p><strong>(iv) Step three, manipulating controls</strong></p></p><p><p>1.scroll<br>Scroll (self, origin_el, destination_el):<br>Scrolls from element Origin_el to element Destination_el<br>Example: Driver.scroll (el1, El2)<br>Usage: Driver.scroll (el1,el2)</p></p><p><p>2.tap<br>Tap (self, positions, duration=none):<br>Analog finger tap (up to five fingers), can be set to hold the length of time (ms)<br>Example: driver.tap ([(100, 20), (100, 60), (100, 100)], 500)<br>Usage: Driver.tap ([(x, y), (x1,y1)],500)</p></p><p><p>3. Swipe<br>Swipe (self, start_x, start_y, end_x, end_y, duration=none):<br>Swipe from point A to point B and slide time to milliseconds<br>Example: driver.swipe (100, 100, 100, 400)<br>Usage: Driver.swipe (x1,y1,x2,y2,500)</p></p><p><p>4. KeyEvent<br>KeyEvent (self, keycode, metastate=none):<br>Send key code (android only), key code can be found on the URL<br>Usage: driver.keyevent (' 4 ')</p></p><p><p>5. Press_keycode<br>Press_keycode (self, keycode, metastate=none):<br>Send key code (android only), key code can be found on the URL<br>Usage: driver.press_ keycode (' 4 ')</p></p><p><p>6.text<br>Text (self):<br>Returns the text value of an element<br>Usage: Element.text</p></p><p><p>7.click<br>Click (self):<br>Click on the element<br>Usage: Element.click ()</p></p><p><p>8.get_attribute<br>Get_attribute (self, name):<br>Gets the related value of an element<br>Usage: Element.get_attribute ("name")</p></p><p><p>9.size<br>Size (self):<br>Gets the size (height and Width) of the element<br>Usage Driver.element.size</p></p><p><p>Ten. Page_source<br>Page_source (self):<br>Gets the source of the current page<br>Usage: Driver.page_source</p></p><p><p>11.quit<br>Quit (self):<br>Exit the script to run and close each associated window connection<br>Example: Driver.quit ()</p></p><p><p></p></p><p><p>Appium Automation Testing (3)--appium framework and process Introduction</p></p></span>

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.