Hey guys,
I need some help as I have been stuck for two days on this.
I’m trying to add some logic which will ideally generate a Driver Factory which can be launched from the TestRunner, depending on what code I have in this class. Basically choose whether to launch iOS or Android from the TestRunner (along with any tags I need to run)
I know I haven’t done this the right way, because even when I try to launch iOS, it still launched Android.
I also still am not able to run all of this from my TestRunner class…
This is what I currently have:
Hooks.java
@Before
public void setUpDriver() throws Exception {
DriverFactory df = new DriverFactory();
df.setUpMobileDriver(iOS);
}
@After
public void teardown(Scenario scenario) {
System.out.println("\n The result of test: " + scenario.getName() + " = " + scenario.getStatus());
driver.quit();
System.out.println("\n Test quit");
}
}
DriverFactory.java
public class DriverFactory {
public static AppiumDriver driver;
DesiredCapabilities caps = new DesiredCapabilities();
String driverUrl = ("http://0.0.0.0:4723/wd/hub");
public AppiumDriver Android;
public AppiumDriver iOS;
public synchronized void setUpMobileDriver(AppiumDriver platform) throws MalformedURLException {
if (platform == Android) {
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.0");
caps.setCapability(AndroidMobileCapabilityType.AVD, "Android9_Nexus");
caps.setCapability("platformName", "Android");
caps.setCapability(MobileCapabilityType.APPLICATION_NAME, "test");
caps.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.14.0");
caps.setCapability("autoAcceptAlerts", true);
caps.setCapability("unicodeKeyboard", true);
caps.setCapability("resetKeyboard", true);
caps.setCapability("noReset", true);
caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.test.test");
caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.test");
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
driver = new AndroidDriver(new URL(driverUrl), caps);
} else if (platform == iOS) {
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.1");
caps.setCapability(MobileCapabilityType.APPLICATION_NAME, "com.test.test");
caps.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.14.0");
caps.setCapability("autoAcceptAlerts", true);
caps.setCapability("unicodeKeyboard", true);
caps.setCapability("resetKeyboard", true);
caps.setCapability(MobileCapabilityType.UDID, "abcdefg12345");
caps.setCapability("bundleId", "abcdefg");
driver = new IOSDriver(new URL(driverUrl), caps);
} else
driver = null;
}
TestRunner.java
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "html:target/cucumber-reports"}
, monochrome = true
, features = "src/test/java/feature"
,tags = "@login"
)
public class TestRunner {
}
Any help is greatly appreciated!!!