Useful Codes to get Web-Driver Object

 (A) RUN ON ANDROID NATIVE

public void runExecutionOnPCloudy() throws IOException, ConnectError, InterruptedException {
 Connector con = new Connector("https://device.pcloudy.com/api/");

 // User Authentication over pCloudy
 String authToken = con.authenticateUser(pCloudyUsername, pCloudyApiKey);

 ArrayList < MobileDevice > selectedDevices = new ArrayList < > ();

 // Populate the selected Devices here
 selectedDevices.add(MobileDevice.getNew("Samsung_GalaxyE7_Android_5.1.1", 143, "GalaxyE7", "Galaxy E7", "android", "5.1.1", "Samsung"));

 // To select multiple devices manually, use either of these:
 //selectedDevices.addAll(con.chooseMultipleDevices(authToken, "android"));
 // selectedDevices.addAll(CloudyCONNECTOR.chooseSingleDevice(authToken, "android"));

 String sessionName = selectedDevices.get(0).display_name + " Appium Session";
 // Book the selected devices in pCloudy
 BookingDtoDevice[] bookedDevices = con.AppiumApis().bookDevicesForAppium(authToken, selectedDevices, 10, sessionName);
 System.out.println("Devices booked successfully");

 // Select apk in pCloudy Cloud Drive
 File fileToBeUploaded = new File("./com.ba.mobile.apk");
 PDriveFileDTO alreadyUploadedApp = con.getAvailableAppIfUploaded(authToken, fileToBeUploaded.getName());
 if (alreadyUploadedApp == null) {
  System.out.println("Uploading App: " + fileToBeUploaded.getAbsolutePath());
  PDriveFileDTO uploadedApp = con.uploadApp(authToken, fileToBeUploaded, false);
  System.out.println("App uploaded");
  alreadyUploadedApp = new PDriveFileDTO();
  alreadyUploadedApp.file = uploadedApp.file;
 } else {
  System.out.println(" App already present. Not uploading... ");
 }

 con.AppiumApis().initAppiumHubForApp(authToken, alreadyUploadedApp);

 URL endpoint = con.AppiumApis().getAppiumEndpoint(authToken);
 System.out.println("Appium Endpoint: " + endpoint);

 URL reportFolderOnPCloudy = con.AppiumApis().getAppiumReportFolder(authToken);
 System.out.println("Report Folder: " + reportFolderOnPCloudy);

 List < Thread > allThreads = new ArrayList < Thread > ();
 MultipleRunReport multipleReports = new MultipleRunReport();

 // Create multiple driver objects in multiple threads
 for (int i = 0; i < bookedDevices.length; i++) {
  BookingDtoDevice aDevice = bookedDevices[i];
  PCloudyAppiumSession pCloudySession = new PCloudyAppiumSession(con, authToken, aDevice);
  SingleRunReport report = new SingleRunReport();
  multipleReports.add(report);

  report.Header = aDevice.manufacturer + " " + aDevice.model + " " + aDevice.version;
  report.Enviroment.addDetail("NetworkType", aDevice.networkType);
  report.Enviroment.addDetail("Phone Number", aDevice.phoneNumber);
  report.HyperLinks.addLink("Appium Endpoint", endpoint);
  report.HyperLinks.addLink("pCloudy Result Folder", reportFolderOnPCloudy);

  Runnable testCase = getTestCaseClass(endpoint, aDevice, pCloudySession, report);
  Thread aThread = new Thread(testCase);
  aThread.start();
  allThreads.add(aThread);
 }

 for (Thread aThread: allThreads) {
  aThread.join();
 }

 con.revokeTokenPrivileges(authToken);

 File consolidatedReport = new File(ReportsFolder, "ConsolidatedReports.html");
 HtmlFilePrinter printer = new HtmlFilePrinter(consolidatedReport);
 printer.printConsolidatedSingleRunReport(multipleReports);
 System.out.println("Check the reports at : " + consolidatedReport.getAbsolutePath());

 System.out.println("Execution Completed...");
}

private Runnable getTestCaseClass(final URL endpoint, final BookingDtoDevice aDevice, final PCloudyAppiumSession pCloudySession, final SingleRunReport report) {
 // 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() {
   File deviceFolder = new File(ReportsFolder, aDevice.manufacturer + " " + aDevice.model + " " + aDevice.version);
   File snapshotsFolder = new File(deviceFolder, "Snapshots");
   snapshotsFolder.mkdirs();
   try {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("newCommandTimeout", 600);
    capabilities.setCapability("launchTimeout", 90000);
    capabilities.setCapability("deviceName", aDevice.capabilities.deviceName);
    capabilities.setCapability("browserName", aDevice.capabilities.deviceName);
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("appPackage", "com.ba.mobile");
    capabilities.setCapability("appActivity", "com.ba.mobile.LaunchActivity");
    capabilities.setCapability("rotatable", true);
    AppiumDriver driver = new AndroidDriver(endpoint, capabilities);

    report.beginTestcase("TestCase BA");
    report.addStep("Launch App", capabilities.toString(), endpoint.toString(), ExecutionResult.Pass);

    report.addComment("--- Add your Test Scripts over here ---");

    // ###########################################
    // ###########################################
    // ###########################################
    // ###########################################
    // Your Test Script Goes Here
    // ###########################################
    // ###########################################
    // ###########################################
    // ###########################################
    // ###########################################


    File snapshotTmpFile = pCloudySession.takeScreenshot();
    File snapshotFile = new File(snapshotsFolder, snapshotTmpFile.getName());
    FileUtils.moveFile(snapshotTmpFile, snapshotFile);

    report.addStep("Take Screenshot", null, null, snapshotFile.getAbsolutePath(), ExecutionResult.Pass);


    // release session now
    pCloudySession.releaseSessionNow();

    report.addStep("Release Appium Session", null, null, ExecutionResult.Pass);

   } catch (ConnectError | IOException e) {
    report.addStep("Error Running TestCase", null, e.getMessage(), ExecutionResult.Fail);
    e.printStackTrace();
   } finally {
    HtmlFilePrinter printer = new HtmlFilePrinter(new File(deviceFolder, deviceFolder.getName() + ".html"));
    printer.printSingleRunReport(report);

   }
  }

 };
}


(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…
  }
 };
}


Also download the Sample project from below link -

   
http://pcloudy-content-distribution.s3.amazonaws.com/index.html?prefix=Sample Appium Projects/java/

 (C) RUN ON IOS

To run Appium on iOS(below 9.3) and XCUI(above 9.3), please download the Sample iOS project to run on pCloudy -

   
http://pcloudy-content-distribution.s3.amazonaws.com/index.html?prefix=Sample Appium Projects/java/


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