Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97790

How does the Singleton class control when driver.quit() and driver.close() are called?

$
0
0

If I comment out the driver.quit() and driver.close() lines, the calling test classes use the same driver and browser session, but obviously do not kill the driver and browser on completion of all test classes!

If I uncomment those 2 lines, the driver and browser session will be killed between test classes which defeats the purpose of the Singleton class.

Where and how does the Singleton/BaseTest class control when driver.quit() and driver.close() are called?

class Singleton {
    private static Singleton single_instance = null;   

    public static Singleton getInstance() { 
        if (single_instance == null) 
            single_instance = new Singleton();   
        return single_instance; 
    } 
} 
//-------------------------------------------
public abstract class BaseTest {
    protected static WebDriver driver;  
    static Singleton singleton = null;  

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        if(singleton == null) {
            singleton = Singleton.getInstance();        
            System.setProperty("webdriver.chrome.driver", System.getenv("CHROME_DRIVER"));
            driver = new ChromeDriver();
        }
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
        //driver.close();
        //driver.quit();
    }
}

Viewing all articles
Browse latest Browse all 97790

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>