Skip to main content

How can you save resources when instantiaing driver?

I asked on my previous post about what was wrong in instantiating driver on set up method?

And here is the solution video on my YouTube channel (After 5 years of gap I finally added new video tutorial :))

The solution described on video tutorial uses following set up -

public class BaseClassOnDemandDriverSetup {

private WebDriver driver;

@BeforeMethod
public void setupTest() {
// Any other set up goes here
}

@AfterMethod
public void teardown() {
if (driver != null) {
driver.quit();
}
}

public WebDriver getDriver() {
if(driver == null) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
return driver;
}
}


Comments

Post a Comment

No spam only genuine comments :)