将我的驱动程序实例列为静态的最佳做法,特别是对于双重测试执行?
驱动程序工厂(用于设置驱动程序实例):
public class DriverFactory {
public static WebDriver driver;
protected BasePage basePage;
protected LoginPage loginPage;
public WebDriver getDriver() throws Exception {
try {
ReadConfigFile file = new ReadConfigFile();
String browserName = file.getBrowser();
switch (browserName) {
//firefox setup
case "firefox":
if (null == driver) {
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver();
}
break;
}
}
}
}
步骤类:(黄瓜步骤类):
public class LoginSteps extends DriverFactory {
@Given("^User navigates to the \"([^\"]*)\" website$")
public void user_navigates_to_the_website(String url) throws Throwable {
BasePage basePage = new BasePage();
basePage.loadUrl(url);
}
}
基页(页面对象的基页):
public class BasePage extends DriverFactory {
protected WebDriverWait wait;
protected JavascriptExecutor jsExecutor;
public BasePage() throws IOException {
this.wait = new WebDriverWait(driver, 15);
jsExecutor = ((JavascriptExecutor) driver);
}
}