Need help on Creating Android/iOS drivers based on XML OS type tags

#1

I am unable to write one test case that works for both Android and iOS.

I have got code from seetest appium studio with 2 Java Classes - AndroidDriver, iOSDriver seprately.
But i wanted to initiate drivers with only one Java class refernece.

I am trying to handle code as per below in base test case. But not sure how to get XML values to in to OS value

	String os="";
	if(os=="android") {
		dc.setCapability("testName", "AndroidDemoTest");
		driver = new AndroidDriver<>(new URL(getProperty("url",cloudProperties) + "/wd/hub"), dc);
		
	}else {
		dc.setCapability("testName", "IOSDemoTest");
		driver = new IOSDriver<>(new URL(getProperty("url",cloudProperties) + "/wd/hub"), dc);
	}
0 Likes

#2

One example that uses XML file with TestNG is:

@BeforeMethod
@Parameters({"OS"})
public void setUp(String OS) {
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability("accessKey", accessKey);

    if (OS.equalsIgnoreCase("Android")) {
        // Capabilities you want
        driver = new AndroidDriver<>(new URL(getProperty("url", cloudProperties) + "/wd/hub"), dc);
    } else if (OS.equalsIgnoreCase("IOS")) {
        // Capabilities you want
        driver = new IOSDriver<>(new URL(getProperty("url", cloudProperties) + "/wd/hub"), dc);
    }
}

Then what I will do is to have a testng.xml file in the project:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Automation" parallel="tests">

    <test name="Test Run">
        <parameter name="OS" value="Android" />
            <classes>
                <class name="test.MyTestClass" />
            </classes>
    </test>
</suite>

As we can see, in the Parameter in our XML file, we can simply switch between Android or IOS, hope this helps.

0 Likes