selenium webdriver - Browser opens many times while Geb testing -
i wrote following test simple spring boot web application:
@springapplicationconfiguration(classes=[pdk]) @webintegrationtest @dirtiescontext class gebmainpagespec extends gebspec { @autowired webapplicationcontext context; def setup() { system.setproperty("webdriver.chrome.driver", "chromedriver/win32/chromedriver.exe"); browser.driver = new chromedriver(); browser.baseurl = "http://localhost:8080/"; } def 'static page present , works, check without pages'() { when: go "" then: assert title == "myapp" } def 'static page present , works, check pages'() { when: mainpage then: loginwithformusername.value() == "root" } }
these tests apparently work, i.e. pass or fail depending on page data.
the problem opens 2 instances of chrome browser operate (by number of tests).
how prevent that? may reuse browser? or may close after each test?
update
if add below
def cleanupspec() { browser.driver.quit() }
then tests startin run twice, moreover, each second run try htmlunit
(i.e. "in memory" web browser, not chrome).
you shouldn't instantiate driver when using gebspec
because handles lifecycle of driver instance through browser instance lazy initializes in it's getbrowser()
method.
see sections of book of geb how geb interacts webdriver
instances , configuring driver used via the config script learn more.
Comments
Post a Comment