Can we continue with the same webdriver after a test execution has abruptly stopped.
I am currently using a webdriver reference in all test cases but need to reuse the same driver object afer i restart a test suite again.
After searching i got that we can get the driver's session id
Can we use the session id to reinitialize the driver
Also searched that it can be done with remote webdriver. But dont know How exactly it will work.
Please help.
you can certainly use the session id of the webdriver but for this you have to store the session id at the time of initializing in order to use it later.
for details see this blog post
For chrome browser
http://binaryclips.com/2015/08/25/selenium-webdriver-in-c-how-to-use-the-existing-window-of-chrome-browser/
For firefox browser
http://binaryclips.com/2014/09/16/selenium-web-driver-in-c-how-to-continue-script-on-the-already-opened-browser-instance/
Related
I'm using Selenium Web Driver API with Java. Whenever I run Web Driver, it automatically creates a tmp Firefox Profile and executes all driver related code relative to the tmp profile.
My issue is not with the extra space this creates as asked in this question: How to stop Selenium from creating temporary Firefox Profiles using Web Driver? and I know I could call driver.quit to clear the resources used by the tmp profile.
Rather, my issue is I want to use the permanent Firefox Profile so that the next time I launch this FF profile I inherit all the cookies and cache of the previous profile. I know I can manually save and add cookies each time but this is tedious.
So, is there any way to force Firefox not to create a tmp profile and launch Firefox as if I was browsing normally using the permanent profile? I just want it to launch as if I was browsing like a normal user.
Thanks
Generally Selenium do not support cross-session cookies.
Most easy way is to use Serialization.
You need to create wrapper class around selenium's cookie and make it serializable. And create class CookiesManager where will be 2 methods: SaveSession() -- to save and RestoreSession() - to restore from serialized file.
Another way is to save some cookies information into some temp cookies file. Like.... Csv or XML.
Sample of this way you can see here: Keep user logged in - save cookies using web driver
but only for c#.
Using specific profile:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("profileToolsQA");
WebDriver driver = new FirefoxDriver(myprofile);
to create some additional profile for firefox you need to run firefox profile manager by the following way: firefox.exe -p
I have search throughout the internet but none of the answers I found have a clear solution.
I am using selenium webdriver with Java.
My test needs to verify when you save your login information and close the browser and reopen it then those credentials remain and are saved on a new session. So I want to close the current session and reopen it in order to verify if a cookie persists on the page however Selenium deletes all stored session data so the test case will always fail. Is there any way to prevent Selenium from deleting the stored session data after closing the browser for the specific test case?
When I do run it I get a no such session error.
This solution works for chrome .
When you launch chrome (I think same applies for other browsers ) selenium creates a temporary profile and when you close it it deletes it. So when you relaunch the browser the new profile will not have the session information. What you can do is use profiles.
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:\\Users\\"+System.getenv("USERNAME")+"\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(desiredCapabilities);
This way if you create your driver, every time chrome will be launched with the same profile and if you dont do
driver.manage().deleteAllCookies();
Your session information will persist in the new session of chrome driver. If you dont want it to persist you can clean the cookies using the above command or just simple log out. This should solve your problem. Similar things should also be possible in other browsers.
To know which profile is currently used type chrome://version/ in your address bar it has the information of the current profile being usesd. To know more about see this
I am running parallel automated tests against a Selenium Grid.
Sometimes, a test with fail with;
Session [c1d99cc1-c689-4053-b68d-51c3682c13c4] was terminated due to CLIENT_STOPPED_SESSION (org.openqa.grid.common.exception.GridException)
[remote server] org.openqa.grid.internal.ActiveTestSessions(ActiveTestSessions.java):105:in `getExistingSession'
The Selenium documentation says;
CLIENT_STOPPED_SESSION The session was stopped using an ordinary call to stop/quit on the client. Why are you using it again??
However, I know that the client has not attempted to stop/quit. I am using parallel rspec so each thread is actually it's own Ruby instance, so there is no issue test side.
Also, if I directly query the Node using http://{node_ip}:5556/wd/hub/static/resource/hub.html, I can see the session is still open. If quit/stop had been issued then, this session would have been deleted.
It would appear that it is only the Session Registry in the Selenium Grid Hub that thinks this session has been stopped. There is no evidence of the session being stopped anywhere else.
Is there a known issue with Grid where the incorrect session has been marked as stopped?
Please follow the blog and try the step, and let us know if that link doesn't help
https://seleniummonk.blogspot.in/p/selenium-grid.html
Currently I have the following issue:
my code is
WebDriver driver = new ChromeDriver();
driver.close();
But thoissometimes ens in an error.
Try using driver.quit(); Do not use close();
Actually, this is problem, especially if you are using Chrome. Try also sing Firefox.
Add driver.quit() to an #AfterClass method
Close will shut the current active window and if it is the last window will then perform a quit(), it does however need to have a valid active session to be able to do this.
If your test has failed that session is probably dead, so when you call a close it doesn't know where to send the command and doesn't do anything.
Quit will shut down all clients if there are no active sessions so if you send a quit and have no active sessions it will just clean up
I am trying to use Selenium 2.0 (Webdriver) to implement a series of tests. Before these tests can run, I have to login into the application. Since the application is not my 'own' (testing api-built functionality), each test should not be logging into my application to run.
I would prefer to do the following:
Connect my webdriver tests to my open Firefox browser (already loggedin)
Run my webdriver projects with the same browser.
I understand that Selenium usually assigns a session id to its browsers. However, the current Java implementation of Selenium 2.0 driver does not make use of session id (maybe it does but I don't know where to find it. )
Can someone provide some direction on how to resolve my issue (existing browser and run multiple tests with Selenium 2.0 (java))? Any code provided would also be helpful. Thanks!
Here is what I have learnt:
Selenium 1: As Ioan suggested earlier, use "-firefoxProfileTemplate" when starting up the Selenium RC server and point to the location of your Firefox profile.
Selenium 2: I suppose you can use the Selenium 1 RC server, however, since Selenium 2 uses WebDriver, you can point to the profile information within your code.
File profileDir = new File("/Users/_____/selenium/FFprofile");
FirefoxProfile profile =
new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(
profile);
Notes:
Make sure you run "firefox -profilemanager" to create your initial profile and save your login information.
Allow the browser/website to always store your authentication credentials avoiding "popup"/"login" wwindows, etcs.
Hope this helps somebody who may run into a similar issue: Using the same browser profile in Selenium, etc.