This declaration
WebDriver driver = new FirefoxDriver();
always opens a new instance window of Firefox. It doesn't use the already opened firefox.
Can anyone let me know how to use a already opened firefox for testing instead of opening a new one?
Be careful with that, because in case the driver crashes once, then all the test cases that have to be executed after that will be affected because they are using the same driver, also you will be sharing cookies, and perhaps sessions already opened previously, etc.
The more robust solution is to create a new WebDriver for each test cases because doing that you are making all your tests cases less dependent on the others.
If the reason that is motivating you is the time each WebDriver takes to be created, perhaps you could start thinking on run test cases in parallel for example with TestNG.
Thanks
Best way to do that is, extend RemoteWebDriver and override startSession method-:
Steps:
Start selenium server using command- java -jar selenium-server-standalone-3.x.x.jar. By default your session start on port 4444.
open url http://localhost:4444/wd/hub/static/resource/hub.html
start new firefox session clicking on create session button and select firefox browser.
Once the session start, copy the session id and paste it in property file or xml file where you want.
read session id form the file where you saved in following method
@Override
protected void startSession(Capabilities desiredCapabilities) {
String sid = getSessionIDFromPropertyFile();
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With