Hi rgonalo,
I have been facing some issues in Appium Grid. The hub has connected to the node properly.I have connected two devices for testing.The App has installed both devices and then stopped working.Herewith I have attached the code for reference.Please Specify me where the problem is.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
public class AppiumGrid {
private AndroidDriver driver = null;
public String appionlicatPath = "E:/sample.apk";
public String MobileDevice_1 ="D1";
public String MobileDevice_2 ="D2";
public static DesiredCapabilities capabilities = new DesiredCapabilities();
AppiumDriver d1,d2;
@BeforeTest
@Parameters("Device_ID")
public void startAppium(String DeviceID) throws MalformedURLException, InterruptedException{
if(DeviceID.equalsIgnoreCase("mobile1")){
setcapabilities(appionlicatPath, MobileDevice_1,"Appium");
}
if(DeviceID.equalsIgnoreCase("mobile2")){
setcapabilities(appionlicatPath, MobileDevice_2,"Appium");
}
driver = new AndroidDriver(new URL("http://127.0.0.1:4444/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
@Test()
public void loginTest() throws InterruptedException{
Thread.sleep(1000);
{
System.out.println("Driver"+driver);
String app_package_name = "sample/id";
By userId = By.id(app_package_name + "username");
By password = By.id(app_package_name + "password");
driver.findElement(userId).sendKeys("***********************");
driver.findElement(password).sendKeys("****************);
driver.findElement(login_Button).click();
}
}
public void setcapabilities(String apppath,String device,String automation){
DesiredCapabilities capabilities1= new DesiredCapabilities();
capabilities1.setCapability("deviceName","G000H404540508AB");
capabilities1.setCapability("platformVersion", "5.1.1");
capabilities1.setCapability("udid", "G000H404540508AB");
capabilities1.setCapability("appActivity", "com.entappia.mhhs");
try {
d1 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities1);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Not able to start application");
e.printStackTrace();
}
d1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
DesiredCapabilities capabilities2= new DesiredCapabilities();
//capabilities2.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities2.setCapability("deviceName","G000H4045405088W");
//capabilities2.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities2.setCapability("platformVersion", "5.1");
//capabilities2.setCapability(CapabilityType.PLATFORM, "ANDROID");
capabilities2.setCapability("udid", "G000H4045405088W");
try {
d2= new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities2);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Not able to start application");
e.printStackTrace();
}
d2.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
}
@AfterMethod
@ AfterTest(alwaysRun= true)
public void tearDown(){
driver.quit();
}
}