Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Selenium webdriver: Reuse existing browser session, instead of opening new windows? #3927

Closed
lukeis opened this issue Mar 3, 2016 · 9 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 3927

What steps will reproduce the problem?

1. Execute test scripts without closing browser
2. identify something that goes wrong in test scripts, do some changes for it. 
3.and try to run it from same browser, which will not be possible. It will open new
browser and execute test scripts.

What is the expected output? What do you see instead?

I want to use my existing browser session. I am executing my test scripts in one browser
suppose IE,mozilla or Chrome any single one and try to execute single method or groups
of method then, selenium webdriver should have functionality to resue opened/ existing
or current browser.

Selenium version:
OS: win XP 
Browser: IE, mozilla firefox, google chrome.
Browser version: IE-8, mozilla firefox-10, google chrome-18


kindly share reply as soon as possible and revert me back on my mail id: newniva@gmail.com

Reported by newniva on 2012-05-18 09:13:46

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Merging to an existing issue.

At the mement, you can extend RemoteWebDriver and override startSession method like
this:

  @Override
  protected void startSession(Capabilities desiredCapabilities) {
    String sid = getPreviousSessionIdFromSomeStorage();
    if (sid != null) {
      setSessionId(sid);
      try {
        getCurrentUrl();
      } catch (WebDriverException e) {
        // session is not valid
        sid = null;
      }
    }
    if (sid == null) {
      super.startSession(desiredCapabilities);
      saveSessionIdToSomeStorage(getSessionId().toString());
    }
  }

Reported by barancev on 2012-05-18 10:57:08

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I was able to do it this way up until around build 2.17 or so.  Now it no longer works,
and I am trying to figure out why.  Here was the code that used to work for me (attached).

Reported by austenjt on 2012-10-04 19:16:45


- _Attachment: [ReusableFirefoxDriver.java](https://storage.googleapis.com/google-code-attachments/selenium/issue-3927/comment-4/ReusableFirefoxDriver.java)_

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For me also ReusableFirefoxDriver.java worked until 2.25 version, where implementation
of ExtensionConnection method (it is overwritten in ReusableFirefoxDriver class)of
FirefoxDriver class is changed.

Did somebody find the solution?

Reported by zzz_ekostyreva@opsource.net on 2012-10-31 10:24:37

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

If you want to use webdriver this way, why you are not saving its value into a static
var or into a single_ton class so that you are not instantiating it multiple times
?

Reported by hakkussg on 2012-11-12 13:26:26

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Hi hakku,
How to save webdriver's value into a static var or single_ton?
May you share your code?

Thanks a million!

Reported by backpacker999 on 2013-02-09 02:27:16

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

this should solve the issue ,how to access the selenium browser session:
WebDriver  driver=new RemoteWebDriver(new URL("http://localhost:7055/hub"), DesiredCapabilities.firefox());
        driver.get("http://www.google.com");

Reported by alterhu2020 on 2014-06-06 10:45:42

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Abovementioned ReusableFirefoxDriver works with latest Selenium (2.42.2). All you need
is to override method
    void startSession(Capabilities, Capabilities) 
as well.

Reported by scf370 on 2014-09-12 13:58:14

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Please Anyone have a working sample for attaching existing browser in Internet explorer

Reported by hkhande on 2014-12-10 11:12:33

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:15:25

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant