How to execute one machine appium script to another machine(Remote machine)?

Is it possible to have Appium running on a remote machine and devices also connected in a same remote machine, and run the test script from the local machine?

Below code was working fine in local machine with local appium server. Please help me any one.bcaz i am new to appium.

package com.appiumproj.test;    
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;

public class Appium {

AppiumDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{

     //Set up desired capabilities and pass the Android app-activity and app-package to Appium

   DesiredCapabilities capabilities = new DesiredCapabilities();
   capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.2");
   capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
   capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"ZX1D62FPVQ");
   capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculatord");
   capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); 
   driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void testCal(){


   WebElement two=driver.findElement(By.name("2"));
    two.click();
    WebElement plus=driver.findElement(By.name("+"));
    plus.click();
    WebElement four=driver.findElement(By.name("4"));
    four.click();
    WebElement equalTo=driver.findElement(By.name("="));
    equalTo.click();

    WebElement results=driver.findElement(By.className("android.widget.EditText"));

    assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";

    System.out.println("Inside Test Function");
terClass
public void teardown(){


    driver.closeApp();
}
}

I want to execute the same script in remote machine.Android device connected in the remote machine and appium also running remote machine.But the script is in Local machine.

So if want to run same script on the different machine you need to give that machine IP Address(in which ur going to run script) in desired capabilities but make sure the .apk file is there in the remote machine also and run the script.Now ur script will run in both the machines

Hi @Demappa,

Thank you for your reply.Can you tell me the procedure or suggest me some link.Bcause i am new to Appium.

@Yosuva

Change this line such that the IP address matches your remote machine’s IP address and port number for appium server.

Hi @aghoward,
Which appium server should be turned on ? My machine appium server or remote machine appium server?

You need to have the appium server running on the machine that the device is connected to.

  1. Connect your device to the machine. You can connect it using USB or WIFI. Refer this link

  2. Make sure you have correct device name and other properties in desired capabilities. If you have only 1 device connected and you want to run your script on that default device then there is no need to specify device name in capabilities.

That’s all!!

Hi @aghoward , @markwongmtw and @Kamal_Girdher
Thank you so much.It is working fine with one android device.But i want to run on multiple devices.

Hi,

I am getting UnreachableBrowserException and ConnectException when I tried to run appium test scripts on remote machine.I have followed the below steps.

Steps:

  1. I have given remote machine IP address in Appium general settings.
  2. Starting Appium server on the remote machine

Please tell me if anything I missed and is there any firewalls blocking test execution.
Please help me any one on the same Thanks in advance.

@Kamal_Girdher Just telnet that remote machine ip with same appium port number.
Example
Telnet 192.168.1.2 4723

4723 is appium server port
If you are able telnet then no issues.please send code which you tried and appium logs.

1 Like

@Yosuva Could you please tell me the steps for running appium test scripts on windows remote machine. It is very useful for me.

Thanks in advance.

Do we need to set the Android Home in the Slave machine?

It is depend on how slave connecting to master machine. In most cases YES. Plus set all PATH also.

Through Jenkins job the slave node is triggered and it is executed there. So one way is to set all installation and set the PATH

Other one is to go with Grid?