Open new browser session/window/tab

971 views
Skip to first unread message

Vin

unread,
Sep 20, 2016, 3:37:29 PM9/20/16
to selenide
Hi,
How can we go about in a situation where once a browser session is opened, we have a step to open another browser window/tab to do some work there & close it, then come back to the 1st window.
-Vin

Andrei Solntsev

unread,
Sep 20, 2016, 5:22:10 PM9/20/16
to Vin, selenide
Generally I think it's a bad idea.
You should use only one browser during test. If you need to emulate another user's action, do it "technically", not via UI. Say, update data in database or call some API methods.

If you still want to do it via UI (which is bad idea because UI is slow and unstable), you can create new webdrivers manually and set them via method WebDriverRunner.setWebDriver(); Something like this:

WebDriver wd1 = new XXDriver();
WebDriverRunner.setWebDriver(wd1);
/// actions 1

WebDriver wd2 = new XXDriver();
WebDriverRunner.setWebDriver(wd2);
/// actions 2
wd2.close();

WebDriverRunner.setWebDriver(wd1);
/// actions 3

wd1.close();

Andrei Solntsev

--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vin

unread,
Sep 21, 2016, 5:20:20 PM9/21/16
to selenide, pvi...@gmail.com
Thx Andrei.
We are in a situation to use 2 browser sessions....like do a setup in 1 window & then open 2nd to validate the change in another dependent app.
After posting, did figure out the setting of the browser2, only that did not know that the wd1 needs to be reset.
That is what was throwing me off. Why does closing of wd2 affect wd1?
-Vin


Andrei Solntsev

unread,
Sep 21, 2016, 5:40:45 PM9/21/16
to Vin, selenide
I still repeat the same: it's a bad idea.
What you really should do is:
1. Create test for "setup". Verify that "setup" modifies correctly data in database.
2. Create test for "another dependent app". Verify that the app behaves correctly if data is changed in database.

Tests should be independent!

P.S. closing wd2 should not affect wd1. 

Andrei Solntsev

Vin

unread,
Oct 3, 2016, 1:47:16 PM10/3/16
to selenide, pvi...@gmail.com
Not exactly related to this, but close enough...
Is there any way to close window/browser without driver.close();
Trying to run a test for 3 iterations & after the end of each one, need to close the browser, but not the driver.


Andrei Solntsev

unread,
Oct 3, 2016, 5:27:47 PM10/3/16
to Vin, selenide
Hi Vin!
What exactly you are trying to achive? Why you want to close browser, but not webdriver? What's the difference for you?

I think that there is no difference. When the last window of browser is closed, the browser gets closed, and the webdriver gets closed too. 

Andrei Solntsev

Reply all
Reply to author
Forward
0 new messages