+ All Categories
Home > Documents > Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs ›...

Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs ›...

Date post: 07-Jun-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
12
Mobile Testing Enterprise Selendroid Integration Release 7.1
Transcript
Page 1: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

 

 

 

Mobile Testing Enterprise

Selendroid Integration Release 7.1  

 

Page 2: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

ii  Keynote Confidential 

Mobile Testing Enterprise 7.1 

June 2015 

Copyright Notice

Copyright © 1995‐2015 Keynote LLC. All rights reserved.     

THE INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED “AS IS” WITHOUT ANY 

EXPRESS REPRESENTATIONS OF WARRANTIES. IN ADDITION, KEYNOTE DISCLAIMS ALL 

IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY WARRANTY OF 

MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON‐INFRINGEMENT OF 

THIRD PARTY INTELLECTURAL PROPERTY RIGHTS. 

All text and figures included in this publication are the exclusive property of Keynote and may not be 

copied, reproduced, or used in any way without the express permission in writing of Keynote. 

Information in this document is subject to change without notice and does not represent a commitment 

on the part of Keynote. Keynote may have patents or pending patent applications covering subject matter 

in this document. The furnishing of this document does not give you any license to these patents except 

as expressly provided in any written license agreement from Keynote.   

The trademarks or registered trademarks of Keynote LLC in the United States and other countries include 

Keynote®, DataPulse®, CustomerScope®, Keynote Customer Experience Rankings®, Perspective®, Keynote 

Red Alert®, Keynote WebEffective®, The Internet Performance Authority®, MyKeynote®, SIGOS®, SITE®, 

keynote® The Mobile & Internet Performance Authority™,  Keynote FlexUse®, Keynote DeviceAnywhere®, 

DeviceAnywhere®, Keynote DemoAnywhere®, Keynote MonitorAnywhere®. All related trademarks, 

trade names, logos, characters, design and trade dress are trademarks or registered trademarks of 

Keynote LLC in the United States and other countries and may not be used without written 

permission.  All other trademarks are the property of their respective owners.  

Please forward any comments or suggestions regarding this document to Keynote Support. 

Keynote LLC  

777 Mariners Island Blvd.  

San Mateo, CA 94404 

 

Page 3: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Selendroid Integration    Mobile Testing Enterprise 

  Keynote Confidential  iii 

Contents

1  Overview ............................................................................................................................4 

2  Requirements .....................................................................................................................4 

3  Selendroid Integration Using Studio .............................................................................5 

4  Running Selendroid Integration from Outside Studio ................................................6 

5  Sample Code ......................................................................................................................8 

5.1  Setting Up an ADB Tunnel ........................................................................................................... 8 

5.2  Native Application ......................................................................................................................... 8 

5.3  Web Application .......................................................................................................................... 10 

5.4  Hybrid Application ...................................................................................................................... 11 

 

 

 

 

Page 4: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

4  Keynote Confidential 

1 Overview

Users of Mobile Testing Enterprise can avail of Java API functions for integration with Selendroid for 

mobile application testing on Android devices. Integration is run in one of two ways: using Keynote’s 

Studio client or using an IDE directly outside of Studio. The requirements and high‐level process for each 

of these methods are outlined below. 

Mobile Testing Enterprise API functions device.connectAdbTunnel(), device.disconnectAdbTunnel(), and device.forwardAdb() API functions should be used for opening and closing an ADB tunnel to the device and for port forwarding.  

device.connectAdbTunnel()—Creates a tunnel session between remote server (where the 

device is connected) and the local server (client machine) 

device.terminateAdbTunnel()—Closes the tunnel session. 

device.forwardAdb()—Forwards the traffic from client machine to the remote machine where 

device is connected. Traffic is forwarded from port 8081 on the local machine to port 8080 on the 

remote machine—these ports cannot be changed. Ensure that 8081 on the client machine is enabled 

(not being used by any other process). 

NOTE When running Selendroid integration directly from an IDE of your choice, these API functions are 

replaced by the Keynote wrapper JAR. 

2 Requirements

Requirements/supported integration components: 

Selendroid 0.15.0 

Android devices—Android target API versions 10 to 19 are supported. Refer to www.selendroid.io 

for latest supported versions. 

IMPORTANT This integration is meant for test execution only on private devices, either in an 

enterprise environment or in the Mobile Testing Enterprise cloud environment.  

Selendroid standalone JARs (with dependencies) imported in your Keynote Studio or Java IDE (e.g., 

Eclipse) project 

Test native or hybrid application APK file copied to the same directory as the Selendroid JARs, which 

is required when starting the Selendroid server—if testing a web application, download the 

Selendroid test APK (selendroid-test-app-0.15.0.apk) from https://github.com/selendroid/selendroid/releases/tag/0.15.0.   

Mobile test scripts written in Java 

If running the integration without using Studio during script creation and execution, you also require the 

following in addition to the requirements listed above—please contact Keynote Support 

(http://support.keynote.com).  

Keynote Studio JARs  

Keynote wrapper JAR KDAwrapper-1.2.4.jar  

Page 5: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Selendroid Integration    Mobile Testing Enterprise 

  Keynote Confidential  5 

On the Mobile Testing Enterprise cloud‐based service, this product can only be used to run tests on 

private devices. 

NOTES Selendroid enables testing of native, hybrid, and web mobile applications, all of which Mobile 

Testing Enterprise supports (see Sample Code below). You can test web applications in both the 

AndroidDriver Webview application and Chrome version 43. 

Mobile Testing Enterprise‐Selendroid test cases cannot be scheduled using Keynote’s LiveTest server or 

scheduling utility. 

3 Selendroid Integration Using Studio

To implement integration with Selendroid using Studio: 

1 Create a Studio project. 

2 Add Selendroid JAR files (available at www.selendroid.io) to the project in Studio: 

a Open project properties (right‐click project name > Properties). 

b Select the Dependencies tab > Add JAR. The files are installed at the following location: 

C:\Users\<Windows_user_name>\AppData\Local\DeviceAnywhere\workspaces.<DAE_environment_name>\<Studio_user_ID>\<project_name>\lib\user

c Save project properties. 

3 Call the project into your Java IDE, e.g., Eclipse.  

4 Open up an ADB tunnel to the device—you need to do this once per session. You can do this in a 

separate Java script (see Setting Up an ADB Tunnel in the Sample Code section) or insert the code to 

open up the tunnel at the top of your application test script. 

Use the device.connectAdbTunnel() and device.forwardAdb() API functions for opening an ADB tunnel to the device and for port forwarding.

device.connectAdbTunnel()—Creates a tunnel session between remote server (where the 

device is connected) and the local server (client machine) 

device.forwardAdb()—Forwards the traffic from client machine to the remote machine 

where device is connected. Traffic is forwarded from port 8081 on the local machine to port 8080 

on the remote machine—these ports cannot be changed. Ensure that 8081 on the client machine is 

enabled (not being used by any other process). 

5 Once the ADB session has been created, start the Selendroid standalone server on your local machine 

to establish communication to the device. 

a Open the command prompt and navigate to folder where you have downloaded the Selendriod 

JAR files (see Requirements). 

b Run the following command to install your test APK or the Selendroid test APK on the device: 

java -jar selendroid-standalone-0.15.0-with-dependencies.jar -app <selendroid-test-app-0.15.0.apk_or_your_own_test_app>

NOTE If you are testing a web application, installing the Selendroid test APK ensures that when 

you run your test case, the AndroidDriver Webview application is also installed. This enables 

Page 6: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

6  Keynote Confidential 

you to view test execution on your own web application within Selendroid’s WebView 

application.   

c Once the command is executed, navigate to http://localhost:4444/wd/hub/status/ in a browser to make sure that the application and the device is recognized by the Selendroid 

standalone server.  For more information, check the Selendroid getting started page at 

http://selendroid.io/setup.html. 

6 Create your Java test case (in Studio or your IDE) for execution via Selendroid.  

7 Use the API call device.terminateAdbTunnel() in your script to close the tunnel session. 

8 Before executing the script, acquire the device in Studio or call the device using the Java API, 

providing the device MCD number in your Java test case.  

4 Running Selendroid Integration from Outside Studio

In order to integrate with Selendroid for mobile testing directly from an IDE of your choice, ensure that 

you have the required Keynote Studio JARs and the Keynote wrapper JAR from Keynote Support.  

Studio must be installed but is not required for script creation and execution. 

JUnit and TestNG frameworks are supported. This section is based on a JUnit test case in Eclipse for 

purposes of illustration.  

When integrating Mobile Testing Enterprise with Selendroid directly from an IDE, each session supports 

connecting to a single mobile device, defined by its MCD number (see step 7 below).  

1 Download and install Studio. Log in at least once.  

2 Create a Java project in Eclipse (File > New > Java Project > Finish).  

3 Add Studio JAR files to the build path—right‐click the project > Build Path > Configure Build Path. 

Jar files are in located in your Studio installation at C:\\Users\ <Windows_username>\AppData\Local\DeviceAnywhere\jars.<jar_version_number>. 

4 Add the Keynote wrapper JAR KDAwrapper-1.2.4.jar to the build path.  

5 Add Selendroid JARs to the build path.  

6 Create a new JUnit test case in the project. 

7 Add the line KDAwrapper.startADBTunnel(8896,true); to the test case where: 

8896 is replaced by the MCD of the device you wish to acquire and test on.  

The second parameter can be false or true.  

true creates the session and waits for you to press x + Enter to close the session. Use this for 

development purposes where the session needs to stay open through multiple iterations of 

test executions. 

false creates the session, executes your test case, and terminates the session at the end of 

test execution. Use this for headless execution.  

NOTE You can check the MCD number of a device in Studio by right‐clicking the device in the 

device list and viewing Device Info. 

Page 7: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Selendroid Integration    Mobile Testing Enterprise 

  Keynote Confidential  7 

Running this line connects to the Mobile Testing Enterprise environment, acquires a license to create 

an API session, acquires a device, and establishes an ADB tunnel, and forwards ADB commands to 

the device.  

You can open one session to a single device at a time. To test on a different device, you must close the 

existing session and open a new session.  

You must have one free Keynote Enterprise license per device to execute this command. 

The session is valid as long as you do not explicitly close it or hit the 30‐minute device inactivity 

timeout.  

8 Point to the Keynote configuration file:  

a Run > Run Configuration > double‐click JUnit in the left tree.  

b Select your test case in the tree. 

c Enter the following line in the Arguments tab: 

-DMC_HOME=C:\Users\<Windows_username>\AppData\Local\DeviceAnywhere

9 Click Apply > Run to run this test case to create a Mobile Testing Enterprise ADB session. 

10 Optionally, if you want to see test case execution on the device, log in to Studio with the same 

credentials used to establish the session and wait for the device (right‐click the device in the device 

list > Wait for Device).  

CAUTION Do not acquire the device before kicking off test case execution or you will not be able to 

open the ADB tunnel. Wait till you see the output Created tunnel from ports local in your IDE to acquire the device in Studio.  

9 When running the Keynote wrapper in development mode (see Step 7 above), once the ADB session 

has been created, start the Selendroid standalone server on your local machine to establish 

communication to the device. 

a Open the command prompt and navigate to folder where you have downloaded the Selendriod 

JAR files (see Requirements). 

b Run the following command to install your test APK or the Selendroid test APK on the device: 

java -jar selendroid-standalone-0.15.0-with-dependencies.jar -app <selendroid-test-app-0.15.0.apk_or_your_own_test_app>

NOTE If you are testing a web application, installing the Selendroid test APK ensures that when 

you run your test case, the AndroidDriver Webview application is also installed. This enables 

you to view test execution on your own web application within Selendroid’s WebView 

application.   

c Once the command is executed, navigate to http://localhost:4444/wd/hub/status/ in a browser to make sure that the application and the device is recognized by the Selendroid 

standalone server.  For more information, check the Selendroid getting started page at 

http://selendroid.io/setup.html. 

If you are running the Keynote wrapper in headless testing mode (see Step 7 above), you must start 

up the Selendroid server programmatically right after invoking the Keynote wrapper JAR (Step 7 

above), and then shut the Selendroid server down at the end of your test case.  

Page 8: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

8  Keynote Confidential 

11 Complete writing your test case.  

12 To close the session, if you have used KDAwrapper.startADBTunnel(8896,true);, you must 

press x + Enter. If you have used KDAwrapper.startADBTunnel(8896,false);, the session is automatically terminated at the end of script execution.  

5 Sample Code

Sample code provided below runs on Selendroid test applications installed on a test device. 

Figure 5‐1 Selendroid Test Applications Installed on Test Device 

 

5.1 Setting Up an ADB Tunnel If integrating with Selendroid using Studio, you must set up an ADB tunnel and port forwarding before 

executing your test script. You can paste this code snippet into a separate script or to the top of the script 

for testing your application. 

device.connectAdbTunnel(); device.forwardAdb(); System.out.println("ADB Tunnel has been created");

To close the tunnel, insert the following line into your script: 

device.terminateAdbTunnel();

NOTE The ADB tunnel is also automatically closed when you release the device. 

5.2 Native Application This code snippet registers a new user in the Selendroid test native application. 

SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.15.0");

Page 9: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Selendroid Integration    Mobile Testing Enterprise 

  Keynote Confidential  9 

WebDriver driver = new SelendroidDriver(capa); driver.findElement(By.id("startUserRegistration")).click(); Thread.sleep(5000); driver.findElement(By.id("inputUsername")).sendKeys("Selendroid"); driver.findElement(By.id("inputEmail")).sendKeys("[email protected]"); driver.findElement(By.id("inputPassword")).sendKeys("12345"); driver.findElement(By.id("inputName")).clear(); driver.findElement(By.id("inputName")).sendKeys("KDA"); driver.findElement(By.id("input_preferedProgrammingLanguage")).click(); Thread.sleep(2000); driver.findElement(By.linkText("Java")).click(); driver.findElement(By.id("btnRegisterUser")).click(); Thread.sleep(2000); Assert.assertEquals(driver.findElement(By.id("label_name_data")).getText(), "KDA"); Assert.assertEquals(driver.findElement(By.id("label_username_data")).getText(), "Selendroid"); Assert.assertEquals(driver.findElement(By.id("label_password_data")).getText(), "12345"); Assert.assertEquals(driver.findElement(By.id("label_email_data")).getText(), "[email protected]"); Assert.assertEquals(driver.findElement(By.id("label_preferedProgrammingLanguage_data")).getText(), "Java"); Assert.assertEquals(driver.findElement(By.id("label_acceptAdds_data")).getText(), "false"); driver.findElement(By.id("buttonRegisterUser")).click(); Thread.sleep(5000); driver.quit();

Page 10: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

10  Keynote Confidential 

Figure 5‐2 Selendroid Native Application Script Execution 

 

5.3 Web Application This code snippet searches for a mobile device on eBay in the Selendroid test web application. 

WebDriver driver = null; DesiredCapabilities caps = SelendroidCapabilities.android(); driver = new SelendroidDriver(caps); driver.get("http://m.ebay.de"); WebElement element = driver.findElement(By.id("kw")); element.sendKeys("Nexus 5"); Thread.sleep(5000); element.submit(); Thread.sleep(5000); driver.quit();

Page 11: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Selendroid Integration    Mobile Testing Enterprise 

  Keynote Confidential  11 

Figure 5‐3 Selendroid Web Application Script Execution 

 

5.4 Hybrid Application This code snippet searches an employee directory for an employee’s direct reports in the Selendroid test 

hybrid application. 

SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.directory:0.0.1"); WebDriver driver = new SelendroidDriver(capa); Thread.sleep(5000); driver.get("and-activity://io.selendroid.directory.EmployeeDirectory"); // Switch to the web view context driver.switchTo().window("WEBVIEW"); String vpOfEngineering = "John Williams"; driver.findElement(By.tagName("input")).sendKeys(vpOfEngineering); driver.findElement(By.partialLinkText(vpOfEngineering)).click(); Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/4"); // Verify Manager String temp1 = new String(driver.findElements(By.tagName("li")).get(0).getText()); Assert.assertTrue(temp1.endsWith("James King")); Thread.sleep(10000); // Verify number of direct reports WebElement directs = driver.findElements(By.tagName("li")).get(1);

Page 12: Mobile Testing Enterprise Selendroid Integration › app › uploads › root › appex-docs › ... · separate Java script (see Setting Up an ADB Tunnel in the Sample Code section)

Mobile Testing Enterprise    Selendroid Integration 

12  Keynote Confidential 

Assert.assertTrue(directs.getText().endsWith("3")); directs.click(); Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/4/reports"); // Verify directs by name Assert.assertTrue(driver.findElements(By.tagName("li")).get(0).getText().startsWith("Paul Jones")); Assert.assertTrue(driver.findElements(By.tagName("li")).get(1).getText().startsWith("Paula Gates")); Assert.assertTrue(driver.findElements(By.tagName("li")).get(2).getText().startsWith("Steven Wells")); Thread.sleep(10000); driver.navigate().back(); Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/4"); driver.quit();

Figure 5‐4 Selendroid Hybrid Application Script Execution 

 

 


Recommended