Monday, January 30, 2023

Portability testing a web application UI with Selenium

Portability testing of web application UI can easily be handled with Selenium. To handle cross browser testing you can implement a driver instantiation pattern like the one shown below,


public class TestBase {
protected static WebDriver driver;
public static void instantiateDriver() {
if (BROWSER.equals("chrome")) {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);
} else if (BROWSER.equals("edge")) {
WebDriverManager.edgedriver().setup();
EdgeOptions options = new EdgeOptions();
options.addArguments("start-maximized");
driver = new EdgeDriver(options);
} else{
Logger.getAnonymousLogger().log(Level.INFO,"An unsupported browser argument was provided at run-time.");
}
}
}
view raw TestBase.java hosted with ❤ by GitHub


For cross mobile agent testing, you can use a TestNG data provider to pass in the device types into your test method and repeat the test for as many emulated devices as you would like.

Find the complete project here, https://github.com/handakumbura/SeleniumAutomationEmployerProfile/tree/feature/cross_browser_cross_agent


public class CrossMobileAgentTest extends TestBase {
@AfterMethod
public static void cleanUp() {
driver.quit();
}
@Test(dataProvider = "userAgentsData")
public static void testDataProvider(String s) {
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", Map.of("deviceName", s));
driver = new ChromeDriver(options);
driver.get(Constants.DROPDOWN_PAGE_URL);
DropDownPageFunctions dropDownPageFunctions = new DropDownPageFunctions(driver);
TestData testData = JSONUtil.readTestData("002");
dropDownPageFunctions.selectValueFromDropDown(testData.getStringValue());
//Asserts to see if the dropdown selection has been set.
Assert.assertTrue(dropDownPageFunctions.isTheGivenValueSelected(testData.getStringValue()), "The given value was not set as the dropdown selection.");
}
@DataProvider(name = "userAgentsData")
public static Object[][] generateData() {
return new String[][]{{"iPhone 5"}, {"iPhone 6"}, {"Nexus 6"}};
}
}








No comments:

Post a Comment

What's in my Bag? EDC of a Tester