Appium Past and Present

 

First, what is Appium

Appium is an open source, cross-platform test frame, the mobile terminal can be used to test the native application and mixing. Appium support IOS, Android and FirefoxOS platform. Appium WebDriver use of json wire protocol, driven Apple UIAutomator framework of UIAutomation library system, Android system. Dan Cuellar's research for IOS automated Appium thanks to support IOS system. Appium also integrated Selendroid, to support older android version.

Appium support Selenium WebDriver all supported languages ​​such as java, Object-C, JavaScript, Php, Python, Ruby, C #, Clojure, or Perl language, but you can use Selenium WebDriver of Api. Appium support any testing framework. If only Apple's UIAutomation, we can only use javascript to write test cases, and only with the Instruction to run test cases. Similarly, if only Google's UIAutomation, we can only use java to write test cases. Appium to achieve a true cross-platform automated testing.

appium select the client-server design pattern. As long as the client can send http request to the server, so if client to achieve what language are possible, and this is appium webdriver how to do multi-language support;

The following passage from the introduction to appium's official website.

Appium is an open-source tool you can use to automate mobile native, mobile web, and mobile hybrid applications on iOS and Android platforms. “Mobile native apps” are those written using the iOS or Android SDKs. “Mobile web apps” are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome on Android). “Mobile hybrid apps” have 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 are then bundled into a native wrapper – these are 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 principle and basic concepts Appium

Works 2.1

 

2.1.1 Android

In Android end, appium WebDriver based protocol, using bootstrap.jar, by adjusting the final command Use with UiAutomator achieve automated testing App.

UiAutomator testing framework that comes with the Android SDK App UI test automation Java libraries.

In addition, as UiAutomator support for H5 limited, appium introduced chromedriver and safaridriver such as to achieve the H5-based automation.

appium android end working stream

  1. client end is what we test script is our webdriver test scripts.

  2. Since the middle of Appium service, Appium in the service reach for a Server (4723 port), with selenium Webdriver testing framework similar, Appium ⽀ support standard WebDriver JSONWireProtocol. Provided herein that provides a REST interface, Appium Server receives the rest standard web driver client request, parses the request content, the response tune Use manipulation corresponding frame.

  3. appium server will forward the request to the middleware Bootstrap.jar, it is written in java, install .Bootstrap listening 4724 port on your phone and receive appium command, and ultimately to achieve with UiAutomator command by adjusting Use.

  4. Last Bootstrap will perform returned to appium server.

  5. appium server then returns the results to appium client.

2.1.2 ios

In IOS end, appium WebDriver Using the same set of protocols.

And Android end frame difference is tested, appium ios apple frame encapsulates Instruments, mainly used in the Instrument UI Automation (Apple's automated testing framework automatically), then the START bootstrap.js feed injection line ⾏ listening device.

appium ios end working stream

  1. client-side test script is still our webdriver test scripts.

  2. Since the middle of Appium service, Appium in the service reach for a Server (4723 port), with selenium Webdriver testing framework similar, Appium ⽀ support standard WebDriver JSONWireProtocol. Provided herein that provides a REST interface, Appium Server receives the rest standard web driver client request, parses the request content, the response tune Use manipulation corresponding frame.

  3. appium server calls instruments.js start ⼀ a socket server, while the separation of a child process submenus when running a instruments.app, will bootstrap.js (a UIAutomation script) injection into the device Use to START and interact with the outside world

  4. Last Bootstrap.js will perform returned to appium server

  5. appium server then returns the results to appium client.

So we can see the difference android ios that forwards the request to bootstrap.js appium or bootstrap.jar. UIAutomation and then driven by the bootstrap UiAutomator to perform specific actions on devices.

2.2 Client/Server Architecture

Appium core is actually a series of REST API exposes the server.

The server functionality is simple: listening on a port, and then receives the command sent by the client to come. These translation command, the command converted into the form of a mobile device may be transmitted to the mobile device appreciated, the mobile device then executes the command after the completion of the execution result back to the appium server, appium server then returns an execution result to the client.

Here client is actually initiated command devices, in general, is the machine we code execution, execution machine appium test code. Appreciated narrow point, the client may be understood as code that can be java / ruby ​​/ python / js, as long as it implements the standard protocols can webdriver.

This design brings several benefits:

  1. It can bring multi-language support;

  2. The server can be placed on any machine, even if it is a cloud server can be; (yes, appium and webdriver a natural fit for cloud testing)

2.3 Session

session is a session in webdriver / appium, all your work is always in session start before you can perform. In general, the POST / session this URL, then pass Desired Capabilities can open a session.

After opening session, it will return a globally unique session id, after almost all requests must bring this session id, because this seesion id represents the simulator you open the browser or mobile device.

Consider further, because the session id is globally unique, then start more than one session on the same machine becomes possible, which is selenium gird depend on the specific theoretical basis.

2.4 Desired Capabilities

Desired Capabilities carries some configuration information. Essentially, this stuff is the key-value in the form of objects. You can be understood as java in the map, python in the dictionary, ruby ​​inside the hash and js in the json object. In fact Desired Capabilities in the transmission is json object.

Desired Capabilities most important role is to tell the server context of this test. This is to be a browser or a mobile terminal test test? If the mobile terminal test, then test android or ios, android test, then if we want to test which app? These questions Desired Capabilities server must give answers, otherwise the server does not buy it, naturally, can not complete the startup mobile app or browser.

Specific examples are as follows:

For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android one. Or we might set the safariAllowPopupscapability to true in order to ensure that, during a Safari automation session, we’re allowed to use JavaScript to open up new windows. See the capabilities doc for the complete list of capabilities available for Appium

2.5 epochs server

That's every time we use the command line to open things appium command.

Appium server Node.js is written. We can use the source code to compile or install directly from the NPM.

2.6 Appium server

Appium server There are many language library Java, Ruby, Python, PHP, JavaScript and C #, these libraries have achieved Appium WebDriver extension of the agreement. When using Appium, you only need to use these libraries instead of the conventional WebDriver library on it. You can see a list of all the libraries here.

2.7 epochs Customers

Since native webdriver api web side is designed, so the mobile terminal together with a bit nondescript. appium official provides a appium client, covering multiple languages ​​ruby ​​/ java / python, ruby ​​client in my opinion is to achieve the best. During the test, generally use these client libraries to replace the native webdriver library. This is not actually replaced, it is regarded as a native client for mobile end webdriver made some extensions, added some convenient method, such as swipe and the like, appium client so that we can more easily write more readable test cases.

2.8  Appium.appAppium.exe

The official provided Appium server GUI package download, which encapsulates all depend Appium server, the user need not worry about how to install Node.js. Appium GUI package also includes an Inspector tool that can help users check the application program level, although the official Android SDK and the Android Device Monitor UI Automator Viewer can also be achieved, but compared to the Inspector still inadequate.

Three, Appium concurrent

 

About appium concurrency, I divided it into two types, the first class single concurrency. The second category based on selenium grid concurrent multi-node test, also known as the cloud measured.

3.1 appium single concurrent

Android concurrent test

Providing a plurality Android Appium start a session on a device program.

appium -p 4492 -bp 2251 -U 32456

Android launch multiple sessions of important instructions include:

instruction Features
-p Appium main port
-U Device id
-bp Appium bootstrap port
–chromedriver-port chromedriver port (when used webviews or chrome)
–selendroid-port selendroid port (when using a selendroid)

iOS concurrent test

Unfortunately, IOS concurrent test can not be performed locally. Not the same as Android, IOS can be only one version of the emulator to run multiple tests at the same time.

Summary: single concurrent currently only realized in android and must start the n appium server correspond to different devices, there may be a real machine devices or simulators. But we must ensure that there is no port after repeated use. The next job is to use testing framework (testng, jasmine, rspec, cucumber, etc.) will be distributed to the different test appium server.

Code Example: GitHub

Code analysis:

  1. First, let us look at the code AppiumParallelTest this class, they first determine the operating system, and get connected devices on the operating system. And using AndroidDeviceConfiguration.java IOSDeviceConfiguration.java in getIOSUDID, getDevices Methods obtain id and the real machine simulator.

  2. The method is then started using startAppiumServer 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://<host_name_appium_server_or_ip-address_appium_server>:<appium_port>/wd/hub",
    "host": <host_name_appium_server_or_ip-address_appium_server>,
    "port": <appium_port>,
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": <grid_port>,
    "hubHost": "<Grid_host_name_or_grid_ip-address>"
  }
}

Fourth, the supported platforms and their needs

Supported Platforms

  • iOS

  • Android

  • FirefoxOS

rely

To run the test, for different mobile platforms, you need to configure the environment, following is a list of requirements related to platform-dependent.

If you want to run through appium npm install installation Appium or research Appium or contribute to Appium. You need [node.js and npm] (https://nodejs.org/en/) to install version 0.10 or higher (using  n  or brew install node to install Nodejs, ensure the installation process, you do not have any use sudo, otherwise you will encounter many problems). We recommend the latest stable version.

You can use appium-doctor to verify that all the dependent Appium. Run appium-doctor, and then provide --ios --android parameters or verification of the dependence of the two platforms is configured correctly. If the run from the source code, you can use the bin / appium-doctor.js or node bin / appium-doctor.js

iOS demand

Android needs

  • The SDK android  the API> =. 17 (additional features need to 18/19)
  • Appium support OS X, Linux, Android on Windows, make sure you follow the instructions below document is to configure different test environments.

FirefoxOS demand

limit

If you install appium on the windows, you can not use precompiled dedicated to the OS X .app file, you can not test IOS apps, because appium dependent on OS X-specific library to support IOS test. This means that you can only test the mac app run up to the IOS. This restriction big.


Finally, attach quite good appiumde learning:

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

Appium官网: 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/

Appium use: 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 to build in the MAC: http://www.15yan.com/story/4GbuTwXQKDU/

appium Concise Guide (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 concurrent test: http://qaseven.github.io/2016/05/05/appium/

Mac Appium Python environment to build: http://www.aichengxu.com/view/55814

Released seven original articles · won praise 6 · views 639

Guess you like

Origin blog.csdn.net/weixin_36273267/article/details/103844874