I am already logged in to my googlemail account in Firefox browser with profile named: test_profile.
Using Selenium, I launch Firefox browser with profile test_profile, but I am seeing login page. Meaning, the session/cookies are not being used.
What am I doing wrong? Or what can be done so I can use my session.
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("test_profile");
WebDriver driver = new FirefoxDriver(profile);
driver.get("https://www.googlemail.com");
Thanks.
Related
I have following scenario to automate :
User Logs in to a website. Navigates to a certain page on website
Save the url for that page.
Close browser
Open the browser again and navigate to the saved url.
User should be able to see the page without logging in.
I can automate first 3 steps. But when I open browser again in step 4, a new session is started and my user sees log in page.
I believe the web driver browser is in incognito mode. So session cookie is not stored.
Is there any way to automate this scenario using selenium web driver?
It's because every time when you invoke browser, selenium opens a new browser profile..so your cookies will be lost..
You can inject cookies for the second time..
Cookie ck = new Cookie("name", "value");
driver.manage().addCookie(ck);
Or you can use same browser profile for driver..
FirefoxBinary binary = new FirefoxBinary();
File firefoxProfileFolder = new File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
webDriver driver= new FirefoxDriver(binary, profile);
You have to quit the webdriver before launching the saved url.
At 3rd step write driver.quit(); and at 4th step write:
driver.get("<saved_url>");
I ran my test in BrowserStack and here is an example outcome
How can I turn off this behaviour of Firefox in a selenium test via DesiredCapabilities?
I want to be able to drive this behaviour with settings instead of adding code for a specific browser.
This prompt is related to firefox health report, you can disable it in as: (in java)
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("datareporting.healthreport.uploadEnabled", false);
profile.setPreference("datareporting.healthreport.service.enabled",
false);
profile.setPreference("datareporting.healthreport.service.firstRun",
false);
WebDriver driver = new FirefoxDriver(profile);
I have Jenkins running headless on a remote machine(centOS). I am trying to run some automated login tests using Selenium Grid (with both hub and a node on same centOS machine) on a development environment whose security certificate is self signed. So, on the home page, when the login link is clicked, it lands up at https error page, while selenium webdriver expects the login page. So all tests are getting failed. I tried to create firefox profile:
nodeUrl = "http://localhost:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
capability.setCapability(FirefoxDriver.PROFILE, profile);
capability.setBrowserName("firefox");
capability.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL(nodeUrl), capability);
But this does not work out. How can i make sure that when the node invokes firefox, it accept that untrusted certificate?
There is a bug in my app wherein Logout doesn't work. I need to workaround this issue in my automation that is in Java using WebDriver. The workaround is to close the browser and reopen it and open the Login page.
To automate this workaround, here is what I have tried:
browserDriver.quit();
browserDriver = new FirefoxDriver(capabilities);
browserDriver.get(loginPageURL);
This returns a new session id. Is there a way to retain the previous session id and set it back. I can get the previous session id using
((RemoteWebDriver)browserDriver).getSessionId();
I also tried deleting all the cookies for the current domain using the following code, but the user was still logged in.
browserDriver.manage().deleteAllCookies();
browserDriver.navigate().refresh();
browserDriver.get(loginPageURL);
Appreciate any help on this.
Up to my knowledge after calling the quit() method on driver it will not retain the previous session id.
Anyway try to launch the browser using specific firefox profile by disabling cache in that.
FirefoxProfile profile = new ProfilesIni().getProfile(profilePath);
profile.setPreference("browser.cache.disk.enable", false);
profile.setPreference("browser.cache.memory.enable", false);
profile.setPreference("browser.cache.offline.enable", false);
profile.setPreference("network.http.use-cache", false);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(dc);
driver.get(url);
Firefox Profile creation ==>
https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
Edit-I
Change below setting in that profile
In "about:config" you can set "Browser.sessionstore.enabled" to false, in which case firefox will not restore your browsing session after it closed.
When you either use
driver.quit();
or
driver.close();
Selenium always starts a new session. This means it's always directs you to the 'Login' page.
Just use below piece of code, no need to set capabilities.
browserDriver.quit();
browserDriver.get(loginPageURL);
You will see the Login page.
I have problems with the firefox driver when I set the proxy settings. The settings is properly settled, but is working to slow and the firefox driver can't continue the program. My purpose is to open google then type some search criteria, to submit this criteria and to open one of the result pages that is show. Everything is good when I don't use the proxy. Here is my code for proxy:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http","some Proxy");
profile.setPreference("network.proxy.http_port", port);
driver = new FirefoxDriver(profile);
Please try with below one:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
WebDriver driver = new FirefoxDriver(profile);