Appium's Past Life

Source: Internet
Author: User
Tags sessions install node appium selenium grid

Appium's past life one, what is Appium

Appium is an open-source, cross-platform testing framework that can be used to test native and hybrid mobile applications. Appium supports iOS, Android, and Firefoxos platforms. Appium uses Webdriver's JSON wire protocol to drive the UIAutomation Library of the Apple system and the Uiautomator framework of the Android system. Appium support for iOS systems thanks to Dan Cuellar's research on iOS automation. Appium also integrates the selendroid to support the old Android version.

Appium supports all languages supported by selenium Webdriver, such as Java, Object-c, JavaScript, PHP, Python, Ruby, C #, Clojure, or the Perl language, and can be used selenium The Webdriver API. Appium supports any kind of test framework. If you only use Apple's uiautomation, we can only use JavaScript to write test cases, and only use instruction to run test cases. Similarly, if you only use Google's uiautomation, we can only write test cases in Java. Appium enables True cross-platform automation testing.

Appium selected the design mode of Client-server. As long as the client is able to send HTTP requests to the server, then it is possible for the client to implement in any language, which is how appium and webdriver support multiple languages;

The following is an introduction from Appium's official website.

Appium is a open-source tool you can use the automate mobile native, mobile web, and mobile hybrid applications on IOS and Android platforms. "Mobile native apps" is those written using the IOS or Android SDKs. "Mobile Web Apps" are Web apps accessed using a Mobi Le browser (Appium supports Safari on IOS and Chrome on Android). "Mobile hybrid apps" has a native wrapper around a "WebView" –a native control that enables interaction with Web content . Projects like Phonegap, for example, make it easy-to-build apps using web technologies that is then bundled into a native Wrapper–these is hybrid apps. Importantly, Appium is ' cross-platform ': It allows you to write tests against multiple platforms (IOS, Android), using the Same API. This enables a large or total amount of code reuse between IOS and Android testsuites.

Second, the working principle of appium and its related basic concepts 2.1 working principle

2.1.1 Android

On the Android side, Appium is based on the Webdriver protocol, using Bootstrap.jar, and finally using uiautomator commands to automate the app's testing.

The Uiautomator test framework is an app UI Automation test Java library that comes with the Android SDK.

In addition, thanks to Uiautomator's limited support for H5, Appium introduced Chromedriver and safaridriver to implement H5-based automation.

Appium on Android side workflow
    1. The client side, which is our test script, is our webdriver.

    2. In the middle is the Appium service, Appium a server (4723 port) on the service side, similar to the Selenium webdriver test framework, Appium the standard webdriver jsonwireprotocol. Provided here it provides a set of rest interfaces, Appium server receives the Web driver client standard rest request, parses the request content, and responds to the action with the corresponding framework.

    3. Appium server forwards the request to the middleware Bootstrap.jar, which is written in Java and installed on the phone. Bootstrap listens to port 4724 and receives Appium commands, which are finally implemented with Uiautomator commands.

    4. Finally, Bootstrap returns the results of the execution to Appium server.

    5. Appium server then returns the result to the Appium client.

2.1.2 iOS

On the iOS side, Appium also makes? Webdriver a set of protocols.

Unlike the Android-side test framework, Appium iOS encapsulates Apple's instruments framework, primarily with UI Automation in instrument (Apple's Automated test framework) and then on the device. Into the bootstrap.js to monitor the line.

Appium Workflow on iOS side
    1. The client side is still test script, which is our webdriver testing scripts.

    2. In the middle is the Appium service, Appium a server (4723 port) on the service side, similar to the Selenium webdriver test framework, Appium the standard webdriver jsonwireprotocol. Provided here it provides a set of rest interfaces, Appium server receives the Web driver client standard rest request, parses the request content, and responds to the action with the corresponding framework.

    3. Appium server call Instruments.js start? A socket server, and a sub-process operation? Instruments.app, will Bootstrap.js (a uiautomation script) note? into device? To interact with the outside world

    4. Finally bootstrap.js returns the result of the execution to the Appium server

    5. Appium server then returns the result to the Appium client.

So we can see that the difference between Android and iOS is that Appium forwards the request to Bootstrap.js or Bootstrap.jar. Then by Bootstrap Drive UIAutomation and Uiautomator to the devices to complete the specific action.

2.2 Client/server Architecture

The core of Appium is actually a server that exposes a series of rest APIs.

The functionality of this server is very simple: listen to a port and then receive a command sent by the client. Translate these command, turn these command into a mobile device understandable form sent to the mobile device, and then the mobile device executes these command after the execution results are returned to the Appium Server,appium server and then return the execution results to the client.

In this case, the client is actually the device that initiates the command, which is generally the machine that our code executes, the machine that executes the Appium test code. In a narrow sense, the client can be understood as a code, and the code can be java/ruby/python/js, as long as it implements the Webdriver standard protocol.

This design idea brings some benefits:

    1. Can bring multi-lingual support;

    2. Server can be placed on any machine, even if the cloud server can be; (yes, appium and Webdriver are natural for cloud testing)

2.3 Session

Session is a conversation, in Webdriver/appium, all your work is always after the session start can be done. In general, by post/session this URL, and then passed in desired capabilities can open the session.

When the session is opened, a globally unique session ID is returned, and almost all requests must be brought with the session ID, since the seesion ID represents the browser you opened or the emulator for the mobile device.

Think further, since session ID is globally unique, it becomes possible to start multiple sessions on the same machine, which is the specific theoretical basis that selenium gird relies on.

2.4 Desired capabilities

Desired capabilities carries some configuration information. In essence, this is an object in the form of Key-value. You can think of it as a dictionary in Map,python in Java, a hash in Ruby, and a JSON object in JS. In fact desired capabilities is a JSON object when it is transmitted.

The most important role of desired capabilities is to tell the server the context of this test. Do you want to do a browser test or a mobile test this time? If it's a mobile test, Android or iOS, what app do we test if we test Android? Server of these questions desired capabilities must answer, otherwise the server does not buy, nature will not be able to complete the mobile app or browser launch.

Specific examples are as follows:

For example, we might set the "PlatformName capability to iOS to tell" Appium that we want a iOS session, rather than an an Droid One. Or we might set the safariallowpopupscapability to true on order to ensure that, during a Safari automation session, we ' re Allowed to the use of JavaScript to open up new windows. See the capabilities doc for the complete list of capabilities available for Appium

2.5 Appium Server

This is what we open with the Appium command at the command line every time.

Appium server is written in node. js. We can compile with the source code or install it directly from NPM.

2.6 Appium Service Side

The Appium server has many language libraries, such as Java, Ruby, Python, PHP, JavaScript, and C #, all of which implement Appium extensions to the Webdriver protocol. When using Appium, you can simply use these libraries instead of the regular Webdriver library. You can see a list of all the libraries from here.

2.7 Appium Clients

Because the native Webdriver API is designed for the web, it is a bit nondescript to use on the mobile side. Appium official provides a set of Appium client, covering a variety of language ruby/java/python, in my opinion, Ruby client is to achieve the best. In testing, it is common to use these client libraries to replace the native Webdriver library. This is not actually a replacement, as the client has some mobile extensions to the native Webdriver, including some handy methods, such as swipe, Appium client makes it easier to write better-readable test cases.

2.8 Appium.app, Appium.exe

The official Appium server-side download of the GUI package encapsulates all dependencies on the Appium server, and users don't have to worry about installing node. js. The GUI-encapsulated Appium also includes a inspector tool that can help users check the program hierarchy of the app, although Android Device Monitor and UI Automator viewer in the SDK are also implemented, However, compared with the inspector still have shortcomings.

Third, appium concurrency

About Appium concurrency, I divide it into 2 categories, the first type of single-machine concurrency. The second type is based on the selenium grid multi-node concurrency test, also known as cloud measurement.

3.1 Appium single-machine concurrent Android concurrency test

Appium provides a scenario for launching multiple Android sessions on a single device.

Appium-p 4492-BP 2251-u 32456

Important instructions for starting multiple Android sessions include:

instruction function
-P Main port of Appium
-U Device ID
-bp Appium Bootstrap Port
–chromedriver-port Chromedriver Port (when using webviews or chrome)
–selendroid-port Selendroid Port (when selendroid is used)
iOS concurrency Test

Unfortunately, iOS cannot perform local concurrency tests. Unlike Android, iOS can only launch one version of the emulator at a time to run multiple tests.

Summary: Stand-alone concurrency is currently only available on Android, and you must start N appium server for different devices, where devices can be either a real machine or an emulator. However, you must ensure that the port is not reused. The next step is to use the test framework (Testng,jasmine,rspec,cucumber, etc.) to distribute the tests to different Appium servers.

code example: GitHub

Code parsing:

    1. First, let's look at the Appiumparalleltest class in the code, they first judge the operating system, and get the devices connected to the operating system. The ID of the real machine and the simulator is obtained by using the Getiosudid,getdevices method in Androiddeviceconfiguration.java and Iosdeviceconfiguration.java respectively.

    2. Then use the Startappiumserver method to start Appium server, using Appiumserverforandroid () or Appiumserverforios ().

3.2 appium Grid distributed concurrency

1. Start Selenium grid Sever

java -jar selenium-server-standalone-2.47.1.jar -port 4444 -role hub   -hub http://192.168.199.140:4444/grid/registe

2. Registered Appium server as the grid node

appium --nodeconfig appium_node_S3.json  -p 4823  -bp 3356 -U "192.168.99.104:5555" --chromedriver-port 4738

3. Configure the test Script,run the tests

@BeforeTest@Parameters({"deviceName"})public void setUp(String deviceName) throws Exception {    capabilities.setCapability("deviceName",deviceName);    capabilities.setCapability("platformVersion", "5.0");    capabilities.setCapability("app", getApp("ContactManager.apk"));    setUpAndroidDriver();}

GRID NODE CONFIGURATION EXAMPLE JSON FILE

{  "capabilities":      [        { "deviceName": "192.168.56.101:5555",          "browserName": "<e.g._iPhone5_or_iPad4>",          "version":"<version_of_iOS_e.g._7.1>",          "maxInstances": 1,          "platform":"<platform_e.g._MAC_or_ANDROID>"        }      ],  "configuration":  {    "cleanUpCycle":2000,    "timeout":30000,    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",    "url":"http://
Iv. support platform and its needs support platform
    • Ios

    • Android

    • Firefoxos

Depend on

In order to run the tests, for different mobile platforms, you need to configure the next environment, which lists the related dependent platform requirements.

If you want to run Appium or research appium or contribute to appium with NPM install Appium. You need to install [node. js and NPM] (https://nodejs.org/en/) 0.10 or later (install NODEJS using N or Brew install node to ensure that you do not use any sudo during installation, otherwise you will Encounter many problems). We recommend the latest stable version.

You can use Appium-doctor to verify all dependencies of Appium. Run Appium-doctor, and then provide the--ios or--android parameters to verify that the dependencies on the two platforms are configured correctly. If you are running from source code, you can use Bin/appium-doctor.js or node bin/appium-doctor.js

IOS Requirements
    • Mac OS X 10.7 or higher, recommended 10.9.2
    • XCode >= 4.6.3, recommended 5.1.1
    • Apple Developer Tools (iPhone simulator SDK, command line Tools)
    • Make sure you've read the documentation we wrote about how to configure the IOS test environment
Android Requirements
    • Android SDK API >= 17 (Additional features required 18/19)
    • Appium supports Android on OS x,linux,windows, ensuring that you configure different test environments as instructed by the following documentation.

      • Linux
      • Os x
      • Windows
Firefoxos demand
    • Firefox OS Simulator
Limit

If you install Appium on Windows, you won't be able to use pre-compiled. app files dedicated to OS X, and you will also be unable to test iOS apps because Appium relies on OS X-specific libraries to support iOS testing. This means that you can only run iOS app tests on your Mac. This is a pretty big limit.

At last, I attach a good appiumde study:

Https://anikikun.gitbooks.io/appium-girls-tutorial/content/start_appium_server.html

Appium Official website: http://appium.io/

Appium Girls Study Guide: https://www.gitbook.com/star/book/anikikun/appium-girls-tutorial

Appium Girls Study Manual: https://anikikun.gitbooks.io/appium-girls-tutorial/content/

Use of Appium: http://icocoa.tk/appiumde-shi-yong.html

Github:https://github.com/appium/appium/blob/master/docs/cn/appium-setup/running-on-windows.cn.md

Github:https://github.com/appium/appium/tree/master/docs/cn

Appium Environment construction under Mac: http://www.15yan.com/story/4GbuTwXQKDU/

Appium Concise Tutorial (1-11): http://www.easonhan.info/

Appium from source.cn:http://appium.readthedocs.io/en/stable/cn/contributing-to-appium/appium-from-source.cn/

Appium Concurrency test: http://qaseven.github.io/2016/05/05/appium/

MAC Appium Python Environment Build: http://www.aichengxu.com/view/55814

Appium's Past Life

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.