I am trying to run same test case on multiple emulators. I am passing two ports and UDID to create sessions for each devices.Also creating two threads for each device.
Here is my code :
public class StartingSteps implements Runnable{
private AppiumDriverLocalService appiumService;
int port;
String udid;
public StartingSteps(int portNumber, String udid) {
this.port = portNumber;
this.udid = udid;
}
Runnable r1 = new StartingSteps(4700,“udid_of_firstdevice”); //device id of first mobile device
Runnable r2 = new StartingSteps(5000,“udid_of_seconddevice”); //device id of second mobile device
new Thread(r1).start();
new Thread(r2).start();
@Override
public void run() {
}
public void initialize(String udid)
{
String osName = System.getProperty("os.name");
System.out.println("started");
if (osName.contains("Mac")) {
appiumService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File(“node_path”))
// .withAppiumJS(new File(“appium_path”))
.withIPAddress("127.0.0.1")
.usingPort(port)
.withArgument(GeneralServerFlag.ROBOT_ADDRESS,udid)
.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER, String.valueOf(port+2))
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withLogFile(new File("target/{"+udid+"}.log")));
}
appiumService.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
cap.setCapability("app", “app_path/Goibibo.apk");
cap.setCapability("appPackage", “package_name”);
cap.setCapability("appActivity", “activity_name”);
cap.setCapability("autoAcceptAlerts", true);
cap.setCapability("newCommandTimeout", 30);
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"), cap);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
} @After
public void tearDown(Scenario scenario) {
driver.quit();
appiumService.stop();
}
}
But code is not getting compiled.It is giving exception
cucumber.runtime.CucumberException: class steps.StartingSteps doesn’t have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath
at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:45)
at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:224)
at cucumber.runtime.Runtime.runHooks(Runtime.java:212)
at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:202)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40)
at cucumber.runtime.model.CucumberScenarioOutline.run(CucumberScenarioOutline.java:46)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.runtime.Runtime.run(Runtime.java:122)
at cucumber.api.cli.Main.run(Main.java:36)
at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.NoSuchMethodException: steps.StartingSteps.()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getConstructor(Class.java:1825)
at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:40)
… 11 more
Please let me know what can be done