Pablo Pablo - 1 year ago 167
Groovy Question

SessionNotFoundException opening a new browser with Selenium + geb

I want to close and start a new browser/window in my test, so I tried:

driver = new ChromeDriver()


org.openqa.selenium.remote.SessionNotFoundException at myTest.groovy:169

Linea 169 is:


Everything I put just after the browser.close() will output the same error.

I've also tried storing cookies and config:
Set allCookies = driver.manage().getCookies();

for(Cookie cookie : allCookies)
browser.driver = browser.config.driver */

My GebConfig.groovy:

driver = {
System.setProperty('', '.\\drivers\\ChromeDriver\\chromedriver.exe')
newDriver = new ChromeDriver()

autoClearCookies = false
return newDriver;


All I need to do is close current window, open a new one and start with another test.

Answer Source

Note that browser.close() calls driver.close() so you are essentially calling driver.close() two times.

What you really need is to clear the driver cache (I'm assuming that you are using the cache as it is the default) by calling CachingDriverFactory.clearCacheAndQuitDriver() and then to create a new instance of Browser using browser = new Browser() which will create a new instance of Driver.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download