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
Related
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
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/
I am trying to implement some Selenium 2 Webdriver tests with JUnit. The documentation on SeleniumHQ.org and the web is confusing to me because it seems to jump back and forth between Selenium RC and Webdriver. Plus, my Java is not very strong. I've took a few courses years ago, but haven't used it much. I want to have JUnit tests run from a headless CI server, and have Firefox run on a remote client system by using Webdriver.
From what I've gathered, I can use the following code to open a Webdriver-controlled instance of Firefox on my local system. The web site I'm testing has an untrusted SSL/TLS certificate, so I need to tell the Firefox driver to accept untrusted certificates. This works great locally:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true); // NOTE: this is the default behavior
RemoteWebDriver driver = new FirefoxDriver(profile);
Selenium selenium = new WebDriverBackedSelenium(driver, baseurl);
But I can't figure out how to do this on the remote system using Webdriver. The two approaches seem totally incompatible. The code above does not fit in any way into the following code that I have been using for using Webdriver remotely:
Selenium selenium = new DefaultSelenium(host, port, browser, baseurl);
selenium.start();
Now, I have spent many hours working with custom Firefox profiles on the remote test system. It worked in the summer of 2012, but after recent OS and browser updates, it stopped working. It seems much better to create the Firefox driver profile and call setAcceptUntrustedCertificates(true). Is it possible to use Webdriver to run tests in a browser on a remote system and also have the browser ignore untrusted SSL/TLS certificates?
As mentioned in your question, you don't need to set any property for accepting untrusted certificates explicitly. By default webdriver accepts untrusted certificates. Rather than using a webdriverbacked selenium, you should use the remotewebdriver directly like:
Webdriver wd = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
Here http://localhost:4444/wd/hub is the URL of the Hub to which tests should be send for execution. When you start the tests, hub will look for remote nodes that have registered with firefox capability.
Personally I would suggest to read documentation at http://code.google.com/p/selenium/wiki/Grid2 rather than seleniumhq.org. As far as I know, selenium team is trying to get the seleniumhq documentation updated. You can also contribute to it :)
First of all i will recommend sticking to webdriver if you are using webdriver backed selenium just for profile. You can define profile to be used on your local machine as
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver driver = new FirefoxDriver(firefoxProfile);
To Answer Your Question: I will quote Simon Stewart's solution from here:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(FirefoxDriver.PROFILE, profile);
Use this profile to create the remote driver.
Now if this doesn't work than may be we can write-up a bug (or at least a feature request).
post edit: I can not really test this solution as I dont have a cert issue site readily available. So in a way I would be looking towards you feedback to get the real picture... :)
When I asked this question, I didn't understand the distinction between Selenium objects and WebDriver objects. Even though I was specifically trying to learn about Selenium 2's "WebDriver" feature, I foolishly thought that I could write a "Selenium 2 Webdriver" project with Selenium 2 objects. That may sound obvious to someone who has experience with these tools, but that distinction was still not clear in my mind after reading "Selenium 2" books and project documentation.
As I result, I was writing Java code to instantiate a Selenium object to examine a web page, and trying to pass the Selenium object a WebDriver object, in the hope that the test would run on a remote server.
Now it seems clearer: The Selenium and WebDriver projects merged into a new umbrella project named (confusingly) Selenium 2.0, but they are distinct and separate tools within Selenium 2. If I want to use the WebDriver API, it seems that I must convert any existing Selenium objects to WebDriver objects. There appears to be no useful interaction between the two tools.
For example, in my project I had the following code. It ran great on my local desktop system's web browser:
Selenium selenium = new DefaultSelenium(host, port, browser, baseurl);
selenium.get(urlPath);
selenium.type(username_field, username);
selenium.type(password_field, password);
selenium.click(login_button);
But I want to be able to run that test on a headless continuous integration server, not my desktop system. I have converted the code to use a WebDriver object instead of a Selenium object. Now it runs on a remote system connected to a Selenium Grid 2 server:
WebDriver driver = new RemoteWebDriver(new URL("http://10.0.0.29:4444/wd/hub"), capability);
driver.get(urlPath);
driver.findElement(By.name(username_field)).sendKeys(username);
driver.findElement(By.name(password_field)).sendKeys(password);
driver.findElement(By.className(login_button)).submit();
I hope other people wanting to learn how to use WebDriver in Selenium 2 will not waste as much time as I did reading about Selenium objects, thinking that the Selenium object is part of WebDriver. My current [n00b] advice is to ignore anything that mentions Selenium objects, and focus purely on finding out as much as you can about WebDriver objects. A good place to start is the WebDriver documentation at SeleniumHQ.org:
http://seleniumhq.org/docs/03_webdriver.jsp#webdriver-and-the-selenium-server
As A.J. suggested in his answer, also take a look at the Selenium Grid documentation:
http://code.google.com/p/selenium/wiki/Grid2
And PS: a remote Selenium 2 Webdriver instance accepts untrusted SSL/TLS certificates automatically, by default. No code required.
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.
I'm getting the following error when starting up Selenium on XP
java.lang.RuntimeException:
Could not start Selenium session: Failed to start new browser session:
java.lang.RuntimeException: java.io.FileNotFoundException:
C:\Program Files\Mozilla Firefox (Access is denied)
Any thoughts?
Kind of stating the obvious, but it looks like Selenium is trying to read/write a Firefox profile but the system is blocking it. This could be because the Selenium user doesn't have appropriate security permissions, or possibly something else is locking access to a profile file.
You could try running the Sysinternals Process Explorer tools to identify what is getting in the way.
Firefox can block access to profiles to Selenium during the copy process, as is mentioned in this related answer.
You may also want to refer to the Selenium documentation in regards to profile handling:
Firefox will not run two instances
simultaneously unless you specify a
separate profile for each instance.
Selenium-RC 1.0 and later runs in a
separate profile automatically, so if
you are using Selenium 1.0, you can
probably skip this section. However,
if you’re using an older version of
Selenium or if you need to use a
specific profile for your tests (such
as adding an https certificate or
having some addons installed), you
will need to explicitly specify the
profile.
Are you starting Firefox with the actual path to the Firefox browser? If you set Chrome as the target browser you should be able to avoid this.