Help Guide for pCloudy-java-Connector for Appium

pCloudy Appium integration

 

1. pCloudy-java-Connector for Appium

 

1.1 Overview

Appium is an open source test automation framework which is used with wide range of mobile apps that supports only android/ios or both. pCloudy is a popular mobile testing platform integrated with Appium script which enables you to automate test of mobile apps as well. If you have your Appium Scripts (or you plan to build them) in Java then you can use the pCloudy-java-connector.jar to integrate with the pCloudy platform. In case, you don’t have your Appium script then, you will need to use the rest web services APIs which are given in the end of this document.

 

1.2 Objective of this document

This user help guide has been developed for pCloudy end users. This help guide will help you to understand the APIs that pCloudy platform provides to integrate your existing Appium Scripts with pCloudy. After the integration, you will be able to execute your Appium scripts from your PC directly to the pCloudy real device cloud.

 

1.3 System Requirements

  • Java based Appium Script
  • Eclipse or Netbeans
  • >APK or IPA file
  • pCloudy Account
  • pCloudy-java-connector jar

NoteThe APIs are evolving and we will come back with a better set of APIs & the jar soon. You might need a little tweaking in the code.

 

1.4 Stepwise Workflow of the APIs for getting an Appium Driver

 

The basic steps to get APIs for Appium Driver are given below:

appium testing

 

1.5 How to get my API Key for using the services

If you are a registered user then you just need to follow few simple steps to get API key for using our services.

Login to pcloudy.com –

 

Appium

 

After successful login, Instant Access page opens. Now, you finds different devices which can be filtered from the above given dropdown list of devices. From this page, you can book your device by clicking on Book your Device link. Furthermore, you can connect with any given device to perform mobile testing but you will be given 10 minutes only. While performing testing operation on selected device, you cannot perform testing on other device simultaneously.  For this, you need to release previously connected device.

When you click on settings option, support page opens by default which helps you to drop support ticket. It also includes various options like support, History, Test Runs, UDID, Profile, Credits, Unsubscribe, and API.

 

1.6 How to integrate my existing Appium Scripts on Java with pCloudy

You need pCloudy java connector jar file and corresponding APIs for Appium based mobile testing platform, pCloudy. You should add the pCloudy-java-connector.jar in its build path as a reference within the your java project containing appium scripts. See this link to learn how to add reference in eclipse.You can download pCloudy-java-connector.jar from this link –

http://support.pcloudy.com/solution/articles/9000062255-adding-reference-to-jars-in-eclipse

While downloading such file, you may come across message as given below which alerts you regarding safety of your computer.

 

pCloudy java connector jar file

 

Now, you can reference the JAR file in Eclipse or Android studio. Please refer the link.

The pCloudy-java-connector.jar comprises the following methods which gives you a wrapper code over the web services. Furthermore, you will not need to call the Rest APIs if you are working on JAVA:

 

Appium Automation Testing

 

1.7 Useful Codes to get Web-Driver Object

 

A. Run on Android Native

 

public void runExecutionOnPCloudy() {
Connector pCloudyCONNECTOR = new Connector();

// User Authentication over pCloudy
String authToken = pCloudyCONNECTOR.authenticateUser(“abc@gmail.com”, “asd53sd3fa4asd5fsasda”);
ArrayList selectedDevices = new ArrayList<>();

// Populate the selected Devices here
selectedDevices.add(MobileDevice.getNew(“Gionee_Ctrl-V6L_Android_4.4.2”, 73, “Ctrl-V6L”, “Ctrl V6L”, “android”, “4.4.2”, “Gionee”));

// Book the selected devices in pCloudy

BookingDtoDevice[] bookedDevicesIDs = pCloudyCONNECTOR.bookDevicesForAppium(authToken, selectedDevices, 5, “friendlySessionName”);
System.out.println(“Devices booked successfully”);

// Upload apk in pCloudy
PDriveFileDTO pDriveFile = pCloudyCONNECTOR.uploadApp(authToken, new File(appPath));
System.out.println(“ipa file uploaded successfully”);
pCloudyCONNECTOR.initAppiumHubForApp(authToken, pDriveFile);

// Get the endpoint from pCloudy
URL endpoint = pCloudyCONNECTOR.getAppiumEndpoint(authToken);
System.out.println(“Appium Endpoint:” + endpoint);

// Create multiple driver objects in multiple threads
for (int i = 0; i < bookedDevicesIDs.length; i++) {
Thread.sleep(5000);
new Thread(getTestCaseClass(endpoint, bookedDevicesIDs[i])).start();
}
}

private Runnable getTestCaseClass(final URL endpoint, final BookingDtoDevice dto) {

// this will give a Thread Safe TestScript class.

// You may also like to have this as a named class in a separate file

return new Runnable() {
@Override

public void run() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“newCommandTimeout”, 600);
capabilities.setCapability(“launchTimeout”, 90000);
capabilities.setCapability(“deviceName”, dto.capabilities.deviceName);
capabilities.setCapability(“browserName”, dto.capabilities.deviceName);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, appPackage);
capabilities.setCapability(“appActivity”, appActivity);
capabilities.setCapability(“rotatable”, true);
AppiumDriver driver = new AndroidDriver(endpoint, capabilities);

// Your Test Script Goes Here…

}
};
}

 

B. Run on Android Web

 

public void runExecutionOnPCloudy() {
Connector pCloudyCONNECTOR = new Connector();

// User Authentication over pCloudy

String authToken = pCloudyCONNECTOR.authenticateUser(“uttam.kumar@sstsinc.com”, “sadf54sad65fds6sdsdsw”);
ArrayList selectedDevices = new ArrayList<>();

// Populate the selected Devices here
selectedDevices.add(MobileDevice.getNew(“Gionee_Ctrl-V6L_Android_4.4.2”, 73, “Ctrl-V6L”, “Ctrl V6L”, “android”, “4.4.2”, “Gionee”));

// Book the selected devices in pCloudy

BookingDtoDevice[] bookedDevicesIDs = pCloudyCONNECTOR.bookDevicesForAppium(authToken, selectedDevices, 5, “friendlySessionName”);
System.out.println(“Devices booked successfully”);
pCloudyCONNECTOR.initAppiumHubForBrower(authToken, “Chrome”);

// Get the endpoint from pCloudy
URL endpoint = pCloudyCONNECTOR.getAppiumEndpoint(authToken);
System.out.println(“Appium Endpoint:” + endpoint);

// Create multiple driver objects in multiple threads
for (int i = 0; i < bookedDevicesIDs.length; i++) {
Thread.sleep(5000);
new Thread(getTestCaseClass(endpoint, bookedDevicesIDs[i])).start();
}
}

private Runnable getTestCaseClass(final URL endpoint, final BookingDtoDevice dto) {

// this will give a Thread Safe TestScript class.

// You may also like to have this as a named class in a separate file
return new Runnable() {
@Override

public void run() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(“chrome”);
capabilities.setCapability(“newCommandTimeout”, 600);
capabilities.setCapability(“deviceName”, dto.capabilities.deviceName);
capabilities.setCapability(“platformName”, dto.capabilities.platformName);
AppiumDriver driver = new AndroidDriver(endpoint, capabilities);
// Your Test Script Goes Here…
}
};
}

 

C. Run on IOS

public void runExecutionOnPCloudy() {
Connector pCloudyCONNECTOR = new Connector();

// User Authentication over pCloudy
String authToken = pCloudyCONNECTOR.authenticateUser(“uttam.kumar@sstsinc.com”, “sadf5sd5fds5sfd5a5fdas1”);
ArrayList selectedDevices = new ArrayList<>();

// Populate the selected Devices here
selectedDevices.add(MobileDevice.getNew(“Apple_iPad2_Ios_7.1.2”, 70, “iPad2”, “iPad 2”, “ios”, “7.1.2”, “Apple”));

// Book the selected devices in pCloudy
        BookingDtoDevice[] bookedDevicesIDs = pCloudyCONNECTOR.bookDevicesForAppium(authToken, selectedDevices, 5, “friendlySessionName”);
System.out.println(“Devices booked successfully”);

// Upload apk in pCloudy
PDriveFileDTO pDriveFile = pCloudyCONNECTOR.uploadApp(authToken, new File(appPath));
System.out.println(“ipa file uploaded successfully”);
pCloudyCONNECTOR.initAppiumHubForApp(authToken, pDriveFile);

// Get the endpoint from pCloudy

URL endpoint = pCloudyCONNECTOR.getAppiumEndpoint(authToken);
System.out.println(“Appium Endpoint:” + endpoint);

// Create multiple driver objects in multiple threads
for (int i = 0; i < bookedDevicesIDs.length; i++) {
Thread.sleep(5000);
new Thread(getTestCaseClass(endpoint, bookedDevicesIDs[i])).start();
}
}

private Runnable getTestCaseClass(final URL endpoint, final BookingDtoDevice dto) {
// this will give a Thread Safe TestScript class.
// You may also like to have this as a named class in a separate file

return new Runnable() {
@Override
public void run() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“newCommandTimeout”, 600);
capabilities.setCapability(“launchTimeout”, 90000);
capabilities.setCapability(“deviceName”, dto.capabilities.deviceName);
capabilities.setCapability(“browserName”, dto.capabilities.deviceName);
capabilities.setCapability(“platformName”, “ios”);
capabilities.setCapability(“bundleId”, bundleId);
IOSDriver driver = new IOSDriver(endpoint, capabilities);
// Your Test Script Goes Here…
}
};
}

 

2. Rest APIs if needed to be used in platforms other than Java

 

https://s3.amazonaws.com/pcloudy-content-distribution/v2/API_USAGE_V2.pdf

Avinash Tiwari

Avinash Tiwari is a thought leader, a recognized keynote speaker, and the co-founder of pCloudy.com. He has 15+ experience in Product development and Testing. He brings with him a passion for emerging technology and quick adoption, both of which have solidified his reputation as a leader in the mobile app testing field.