1.Создайте один класс AbstractHook в пакете TestScript
public class AbstractHook {
protected static WebDriver driver;
protected WebDriver getdriver() {
if (driver == null) {
System.setProperty("webdriver.gecko.driver","geckodriver.exe");
driver = new FirefoxDriver();
} else if (driver == null) {
System.setProperty("webdriver.chrome.driver",
"chromedriver.exe");
driver = new ChromeDriver();
}
return driver;
}
2.Класс класса
public class Hook extends AbstractHook {
AbstractHook df = new AbstractHook();
@Before
public void createdriver() {
df.getdriver();
driver.get("some url");// no need
}
}
3. Код TestScript
public class TestScript01 extends AbstractHook {
WebDriver driver = getdriver();
@Given("^I want to open the gmail url on firefox$")
public void i_want_to_open_the_Gmail_url_on_firefox() throws Throwable {
driver.get("give some url");
}
}
4.Runnerclass
@RunWith(Cucumber.class)
@CucumberOptions(features = "Feature", monochrome = true, glue = { "com.scripts" }, plugin = { "pretty","html:target/cucumber" },
tags = {"@sa,@sanity" },
// dryRun = false)
public class RunnerClass {
}
Попробуйте, таким образом, Драйвер будет инициализирован один раз и использован во всех классах TestScript.