Selenium: reuse existing browser session, instead of opening new windows?

  • This has been asked a million times on the web, but there's no clear cut answer. I tried "-browserSessionReuse" today without any luck; my tests keep spawning new browser windows.

    X:\QA\Automation\SELENIUM_SERVER>java -jar selenium-server-standalone-2.8.0.jar -log "log.txt" -browserSessionReuse -forcedBrowserMode "*googlechrome"
    <snip>
    13:42:25.923 INFO - Will recycle browser sessions when possible.
    

    Maybe it's how I'm starting Selenium in my .py files?

    sel = selenium('localhost', 4444, "*chrome", 'http://server/')
    sel.start()
    

    ...perhaps I'm doing too many server starts?

    I don't think that's possible. afaik Selenium always uses new Window

    I've had the same result, and I wanted reuse at one point to check cookie values in a site test.

    you can check QMetry Automation Framework which allows you to reuse session at maximum extent. you never need to create or quite driver it is managed by the framework depends on your run configuration.

  • Sam Woods

    Sam Woods Correct answer

    9 years ago

    This is possible with Selenium 2 and WebDriver. I'm not sure if it is with different versions. In Selenium 2 with WebDriver you can call webDriver = new FirefoxDriver() which spawns a browser, and that browser will stay open for the duration of your testing, or you can choose to close it with webDriver.Quit().
    I like to close my browser window between tests so that I know my tests aren't "dirty" with stored session data that could affect how the tests run, but I can see value in some targeted tests, where I want to try a couple different scenarios while keeping the same session going.

    Funny, I was just reading about this this morning, and I think it will solve my browser windows problem. Thank you.

    What if a page (eg google) is already open in the (chrome) browser and I want to click a button with my selenium script ? This is so easy in (the old) UFT/QTP.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM