I'm trying to find out if it is possible to simplify my framework a little bit more. The current solution works, but it does cause some code duplication for me and some other issues that might come down the road.
public class Browsers {
private String Browser;
private String Windows;
private String Ver;
protected WebDriver driver;
@BeforeTest
public void BeforeMethod() {
DriverFactory driverfactory = new DriverFactory();
driver = driverfactory.createdriver(Browser);
}
@AfterTest
public void AfterMethod() {}
public Browsers(String Browser, String Windows, String Ver) {
this.Browser = Browser;
this.Windows = Windows;
this.Ver = Ver;
}
@DataProvider
public static Object[][] dataProviderMethod() {
return new Object[][] {{"FF", "WIndows", "10"}, {"Chrome", "Windows", "10"}};
}
}
public class DriverFactory {
private WebDriver driver;
public WebDriver createdriver(String Browser) {
if (Browser.contains("FF")) {
driver = new FirefoxDriver();
}
else {
driver = new ChromeDriver();
}
return driver;
}
}
public class LoginTests extends Browsers {
@Factory(dataProvider = "dataProviderMethod")
public LoginTests(String Browser, String Windows, String Ver) {
super(Browser, Windows, Ver);
}
@Test
public void LoginValid() {
}
@Test
public void LoginInvalid() {
}
}
Problem
Currently, I'm able to run tests when I create a factory on each of the test classes.
I have to write a constructor to all the test classes that I create. Which causes me some code duplication. When I have 100 tests then it will be quite a lot. Is it possible to avoid it.