Setup Selenium GRID to Execute Appium Script on IOS Simulator or Device from Remote Machine

Lets take an example of 2 machines mentioned below :

Machine 1 : Windows OS (will be acting as a HUB)

Machine 2 : MAC OS (Will be acting as a node)

Follow steps mentioned below :

Machine 1 Setup (IP Address : 10.10.0.46) (WIndows OS)

1. Download Selenium Standalone server and save it in a folder

Grid

2. Open command prompt, navigate to the location where selenium JAR is saved and start Hub using following command

cd gridsetup

java -jar selenium-server-standalone-3.4.0.jar -role hub

NOTE : As HUB port is not mentioned in above command, so it will be started on 4444 by default

Grid

After executing above command, invoke following URL to check Hub is started or not

http://HUB_IP_Address:hub_port/grid/console

Eg : http://10.10.0.46:4444/grid/console

Grid

Machine 2 Setup (IP Address : 10.10.1.40) (MAC OS)

1. Download Selenium Standalone server and save it in a folder.

2. Install Appium and start the server by using below command.
NOTE : Refer this doc to Install Appium via Terminal
Here, we are using Appium version 1.6.4


appium --port 4723 --address 10.10.1.40

After executing above command, Appium server will get started on port 4723

Grid

3. Now is the time to Register a node. Before registering a node to a HUB, first you have to create JSON file and save it in a folder where selenium stand alone jar is saved.

Grid

Sample JSON code

{
    "capabilities": [
        {
            "browserName": "iPhone-Simulator",
            "version": "10.3",
            "maxInstances": 1,
            "platform":"MAC",
            "seleniumProtocol": "WebDriver"
        }
    ],
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "url": "http://10.10.1.40:4723/wd/hub",
        "host": "10.10.1.40",
        "port": 4723,
        "maxSession": 5,
        "register": true,
        "registerCycle": 5000,
        "role": "node",
        "hub": "http://10.10.0.46:4444",
        "hubPort": 4444,
        "hubHost": "10.10.0.46",
        "debug": false,
        "servlets" : [],
        "withoutServlets": [],
        "custom": {}
    
}

You have to update the above JSON code accordingly. Just Refer below details while updating JSON:

"browserName": "<e.g._iPhone5_or_iPad4>",
"version":"<version_of_iOS_e.g._7.1>",
"platform":"<platform_e.g._MAC_or_ANDROID>"

"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>,
"hubPort": <grid_port>,
"hubHost": "<Grid_host_name_or_grid_ip-address>"

4. Open Terminal in MAC OS, navigate to the folder where selenium selenium JAR and JSON file is saved and execute following command to register node with Hub Machine

cd lib

java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://10.10.0.46:4444/grid/register -nodeConfig config-iphone.json

You have to update the above command accordingly. Just refer below details while updating above command :


-nodeConfig <filename>
-hub <Hub Machine IP Address>

Grid

5. After executing above command, node will get registered to HUB. Just check it by invoking following URL : http://10.10.0.46:4444/grid/console

Grid

Grid set up is done. Next step is to execute Appium script on IOS simulator or device from Remote Machine

Below sample code will be executed on IOS Simulator in Machine 2 (MAC OS)

6. Now, execute below code from Machine 1( Windows OS) and it will executed on IOS simulator in Machine 2 (MAC OS)

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Tests {

	static RemoteWebDriver driver;
	DesiredCapabilities capabilities;

	@Before
	public void setUp() throws Exception {
		capabilities = DesiredCapabilities.safari();
		capabilities.setCapability("automationName", "XCUITest");
		capabilities.setCapability("platformName", "iOS");
		capabilities.setCapability("platformVersion", "10.3");
		capabilities.setCapability("deviceName", "iPhone 6s");
		capabilities.setCapability("browserName", "Safari");
		capabilities.setCapability("launchTimeout", 120000);

		URL url = new URL("http://10.10.1.40:4723/wd/hub"); //IP Address of Appium Server
		driver = new RemoteWebDriver(url, capabilities);
		driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);

	}

	@Test
	public void webTest1() {
		String email = "adkajdaks@sa.com";
		driver.get("http://www.ebay.in");
		driver.findElement(By.xpath("//*[@class='mhf-links']/a[2]")).click();
		getElement(By.xpath("//*[text()='Register']")).click();
		getElement(By.id("firstname")).sendKeys("abcd");
		getElement(By.id("lastname")).sendKeys("adftyh");
		getElement(By.xpath("//input[@id='email']")).sendKeys(email);
		getElement(By.xpath("//input[@id='remail']")).sendKeys(email);
		getElement(By.id("PASSWORD")).sendKeys("pass@1234");
		System.out.println("passed");
	}

	WebElement getElement(By locator) {
		WebDriverWait wait = new WebDriverWait(driver, 20);
		WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
		return element;

	}

	@After
	public void tearDown() {
		driver.quit();
	}
}

If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *