Reuse current browser session

1,240 views
Skip to first unread message

Dhiraj W.

unread,
Jan 9, 2016, 2:44:25 AM1/9/16
to Selenium Users
How to reuse current browser session in selenium webdriver??

Details: If test script has been failed because of some property change in screen control and user wants to continue the script from that point only then how this can be achieved using webdriver

Krishnan Mahadevan

unread,
Jan 9, 2016, 2:48:06 AM1/9/16
to Selenium Users
I don't think this can be achieved using webdriver.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Jan 8, 2016 at 3:52 PM, Dhiraj W. <wdh...@gmail.com> wrote:
How to reuse current browser session in selenium webdriver??

Details: If test script has been failed because of some property change in screen control and user wants to continue the script from that point only then how this can be achieved using webdriver

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f3ee2d58-c72a-42b5-9931-20f529585bb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carl Nagle

unread,
Jan 9, 2016, 5:49:20 PM1/9/16
to seleniu...@googlegroups.com
This can be done, but there are some things that have to be taken care of.

First, you have to use a Selenium Server. It can be local or remote.

Second you have to either cache session info and use this to reconnect to existing sessions, and/or ping and get information from the selenium server to connect and reuse existing sessions.

Third, your tests or framework code must not tell the session to close or exit on completion until that is truly the intent.

This is one of the things the custom RemoteDriver in SeleniumPlus handles automatically for testers. For example, automation may launch a session and get the app to a point and then other tools can use Selenium or browser development tools to interrogate the app alongside human interaction.

Or it can be the other way. Special tools like ProcessContainr provided with SeleniumPlus might launch a selenium session for human interaction, navigation, or exploration, and iterative automation development and debugging of tests can occur with the same session.

http://safsdev.sourceforge.net/doc/org/safs/selenium/webdriver/lib/RemoteDriver.html

https://github.com/SAFSDEV/Core/blob/master/src/org/safs/selenium/webdriver/lib/RemoteDriver.java

Carl Nagle

Krishnan Mahadevan

unread,
Jan 9, 2016, 9:29:52 PM1/9/16
to seleniu...@googlegroups.com
Carl,

When you say Selenium server, am guessing you are talking about a Grid environment.
But how is this going to be useful when the user does this in a Grid environment that runs in a remote infrastructure.

The notion of SessionId [ session Id is merely a way that the Grid setup uses wherein it maps a specific browser instance to a particular UI test ] is applicable only for Grid/Hub. So lets say you have extracted out the SessionId from the driver object, how do you expect a user to use it against a browser that’s running in a remote machine ? [ Are you specifying that a user log into that machine and then work with that browser ? ]


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Carl Nagle

unread,
Jan 9, 2016, 11:45:54 PM1/9/16
to seleniu...@googlegroups.com
No. A Selenium Server does not have to be in a grid environment. You can run a server on your local machine. You can run it on a remote machine that is not part of any grid.

By default SeleniumPlus will use and even launch a Selenium Server on the local machine. It can be configured to connect to and even launch a Selenium Server on a remote machine.

Selenium running with a remote driver thru a selenium server behaves the same whether it is on the local machine, or a remote one. And yes, you can reconnect and reuse existing browser sessions on remote machines. But true, you might not interactively play with a remote browser session, unless you were doing remote desktop or vnc to that machine. For example, playing with safari on a mac from a windows machine--such as might be the case during test development.

I would not suggest that a session id assumes a relationship between any specific UI test and a browser instance. In reality, the selenium session marked by an id is only that--an identification to a particular browser instance. The Remote driver that instantiated it can come and go and that entire process can die. A new remote driver can be configured to find it and reconnect to that session.

Carl Nagle

Krishnan Mahadevan

unread,
Jan 10, 2016, 12:01:46 AM1/10/16
to Selenium Users
Carl,

I dont quite see the point of one wanting to connect to a remote Selenium Server. When would one want to do that ?
If its within the realms of the Grid environment I can still understand that because the Hub basically adds the below value additions :

* Figure out if a Selenium server is up or not
* Figure out if a selenium server that is hooked up to it, has the "desired capabilities" as well.
* Route the UI test to the appropriate selenium server, based on what is hooked on to it as various different nodes.

But if one is going to be connecting directly to a remote selenium server, then one is basically getting themselves deprived of all these benefits.


For local executions IMO, starting a selenium server and then connecting to it via the WebDriver infrastructure seems a bit too much of work especially because all the concrete WebDriver implementations have the inbuilt knowledge of firing up their own server and then running tests against it.

But yes, I agree with your more crisp explanation of what a session Id really is. Thanks for calling that in a perfect manner !


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

carl....@sas.com

unread,
Jan 11, 2016, 2:04:41 PM1/11/16
to Selenium Users
The reason we have chosen to ALWAYS use a Selenium Server--whether local or remote--is to resolve the very issues asked of the original poster.  First and foremost, to be able to keep sessions open and alive and be able to connect to them from different Selenium test and debugging processes.  At times, particular during test development and debugging, we can have 2 different processes open and talking to the the Selenium Server sessions at the same time (not literally, but logically).

In most cases, our testers don't want to use the production Grid environment for test development and debugging.  They use their own private "pool" of real and virtual machines that they control (and limit) access to for web and/or mobile testing.

In addition, our test framework adds significant features for automated testing that go beyond what Selenium provides alone.  A single test scenario may require use of Selenium, SeBuilder/Interpreter Scripts, Java AWT Robot, AutoIt, Image-Based Testing (IBT), and other automation tools due to the complex or hybrid nature of some of the applications being tested.  These are expected to work whether testing local, or remote.  And much of this is handled behind-the-scenes in a manner the tester does not have to know about or write code for.

So, for this type of general-purpose full-featured solution to automated testing, the Selenium portion of the solution dictates we use a Selenium Server--whether it be local or remote--with our own custom RemoteDriver to provide the full featureset requested of our users and their automated testing requirements.

The original poster's question is exactly the type of scenario we needed to achieve for our users.  Allow some code to drive the app to some state.  Exit the code but DO NOT end the browser session.  Manipulate, investigate, and analyze the still running browser session.  Write some new test code or snippets and try it out on that still running browser session.  Try some more.  Try some Java AWT Robot, IBT or AutoIt, or TestComplete if that is necessary.  Try some more.  All in the same test and development debugging session until something can be made to work robustly.

Sure, there will be simpler and more straight-forward ways to use Selenium in a Selenium-only solution for "simple" web applications.  But I think we can see by the various types of posts across the web that there are a great many "web applications" that are not simple, and cannot use a Selenium-only solution.  This is the type of framework our SAFSDEV developers have been providing our testers for almost 2 decades.  And using a Selenium Server in this way seems to be the best way to allow our users to take advantage of Selenium WebDriver capabilities without giving up access to all the other tools they have needed over the years and still use alongside Selenium.

Carl Nagle
Reply all
Reply to author
Forward
0 new messages