Executing Appium Code from Windows Machine to Remote iOS Device

You are here:
< All Topics

Overview

Appium is most prevalently used for testing mobile apps. In order to get quicker and more precise results, it aids in running automated testing of native and hybrid applications for Android and iOS devices.

Appium is a framework for automating the testing of apps that run on operating systems like iOS, macOS, Android, and Windows. Similar to Selenium, it gives the tester the ability to create test scripts in a variety of programming languages, including Java, Ruby, Python, PHP, and C#, which can be used on both Android and iOS platforms.

Prerequisites

  • Download the latest Appium client.
  • TestGrid account

How to Execute Local Appium Code from Windows Machine to Remote iOS Device?

Here is the Appium code for your reference:

package test;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;

public class MobileDemo{

    //Obtain Run URL from Link Provided for Organization
    static String TG_DEVICE_URL="https://demo.testgrid.devicecloud/wd/hub";
    
    //Obtain Capabilities from Link Provided for Organization
    static String TG_DEVICE_NAME="Pixel 3";
    static String TG_DEVICE_UDID="TGDC0001";
    static String TG_DEVICE_PLATFORMNAME="Android";
    static String TG_DEVICE_PLATFORMVERSION="10";
    
    //Set Package Name & Activity - For App You want to automate
    static String APP_PACKAGE="com.android.calculator2";
    static String APP_ACTIVITY="com.android.calculator2.Calculator";

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("deviceName",TG_DEVICE_NAME );
        cap.setCapability("udid", TG_DEVICE_UDID);
        cap.setCapability("platformName", TG_DEVICE_PLATFORMNAME);
        cap.setCapability("platformVersion",TG_DEVICE_PLATFORMVERSION);
        cap.setCapability("appPackage",APP_PACKAGE);
        cap.setCapability("appActivity", APP_ACTIVITY);
        URL url = new URL(TG_DEVICE_URL);
        AppiumDriver<MobileElement> driver = new AppiumDriver<MobileElement>(url,cap);
        
        //Write Automation Steps
        MobileElement no7 = driver.findElement(By.id("com.android.calculator2:id/digit_7"));
        MobileElement no3 = driver.findElement(By.id("com.android.calculator2:id/digit_3"));
        MobileElement plusop = driver.findElement(By.id("com.android.calculator2:id/op_add"));
        MobileElement eqop = driver.findElement(By.id("com.android.calculator2:id/eq"));
        no7.click();
        plusop.click();
        no3.click();
        eqop.click();
        driver.quit(); 
        
    }
}
  • Get Run URL and device compatibility from TestGrid’s device cloud.
  • Add the obtained URL to the java code.
public class MobileDemo{
  //Obtain Run URL from Link Provided for Organization
   static String TG_DEVICE_URL="https://demo.testgrid.devicecloud/wd/hub";

 

  • Add the obtained device capabilities to the code
  • The following variables need to be changed as provided for organization & as per devices:

                              TG_DEVICE_URL

                              TG_DEVICE_NAME

                              TG_DEVICE_UDID

                              TG_DEVICE_PLATFORMNAME

                              TG_DEVICE_PLATFORMVERSION

//Obtain Capabilities from Link Provided for Organization 
static String TG_DEVICE_NAME="Pixel 3"; 
static String TG_DEVICE_UDID="TGDC0001"; 
static String TG_DEVICE_PLATFORMNAME="Android"; 
static String TG_DEVICE_PLATFORMVERSION="10";
  • Now, set the package name and activity for the application that you want to automate.
//Set Package Name & Activity - For App You want to automate
  static String APP_PACKAGE="com.android.calculator2";
  static String APP_ACTIVITY="com.android.calculator2.Calculator";
  public static void main(String[] args) throws MalformedURLException, InterruptedException {
      DesiredCapabilities cap = new DesiredCapabilities();
      cap.setCapability("deviceName",TG_DEVICE_NAME );
      cap.setCapability("udid", TG_DEVICE_UDID);
      cap.setCapability("platformName", TG_DEVICE_PLATFORMNAME);
      cap.setCapability("platformVersion",TG_DEVICE_PLATFORMVERSION);
      cap.setCapability("appPackage",APP_PACKAGE);
      cap.setCapability("appActivity", APP_ACTIVITY);
      URL url = new URL(TG_DEVICE_URL);
      AppiumDriver<MobileElement> driver = new AppiumDriver<MobileElement>(url,cap);
  • Add automation steps as required.
  • Execute the program.You can view the live execution results on the cloud portal of TestGrid.

You can view the live execution results on the cloud portal of TestGrid.

Additional Links

You can also do these with the TestGrid Platform:

Table of Contents