I'm looking for the recommendation of removing (replacing) the hard-coded browser/OS/Version values from @DataProvider public static Object[][] sauceBrowserDataProvider. The code example:
@DataProvider(name = "hardCodedBrowsers", parallel = true)
public static Object[][] sauceBrowserDataProvider(Method testMethod) {
return new Object[][]{
**new Object[]{"firefox", "55.0", "Windows 10"},
new Object[]{"chrome", "65.0", "Windows 10"},**
};}
@Test( dataProvider = "hardCodedBrowsers")
public void createDriver(String browser, String version, String os)
throws Exception {
Class<? extends TestRemote> SLclass = this.getClass();
DesiredCapabilities capabilities = new DesiredCapabilities();
// set desired capabilities to launch appropriate browser on Sauce
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.VERSION, version);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, os);
capabilities.setCapability("seleniumVersion", "3.8.1");
capabilities.setCapability("name", SLclass.getSimpleName());
capabilities.setCapability("screenResolution", "1920x1080");
driver = (new RemoteWebDriver(new URL("http://" + SAUCE_USERNAME + ":" + SAUCE_ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"), capabilities));
configRead = new ConfigFileReader();
propertyRead = new PropertyLoader();
baseUrl = propertyRead.getProperty("site.url");
app = new Application(driver);
getURL();
}
This is a selenium project on Java/ TestNg/ Jenkins/Saucelabs
The easiest way of doing this would be to Move the combinations(browser/OS/Version) to a data source like an excel spreadsheet or a csv or a json/yaml/xml and have your
@DataProvider
read them from there.Update
You can utilize QAF TestNG extension. It providers different inbuilt data-providers to load test data from different data source like xml, json, excel, properties, database. With QAF you can set different data source as below:
Moreover you can switch data-provider without change in code. In addition to that it has lots of features for black box testing of web, mobile (using selenium, appium) and web-services.