What profile does Selenium WebDriver use by default? - firefox

Where does Selenium WebDriver (a.k.a Selenium 2) get the anonymous profile that it uses when it opens FirefoxDriver? If it used the default for Firefox, %appdata%/roaming/mozilla/firefox/profiles, then if I were to disable a firefox plugin, it should be disabled for Selenium WebDriver also, so why isn't it?

I will answer it, supporting comment from #twall: When starting firefox in Selenium 2 WebDriver, it starts new, anonymous profile.
However, if you want to change it, you can create new Firefox profile and name it somehow, you know what it is - e.g. SELENIUM
Then in your code do this:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
That way, Firefox will always start that profile. In the profile you do all the settings you need

You can assign to each Selenium grid 2 node a specific firefox profile:
java -jar selenium-server-standalone-2.37.0.jar
-Dwebdriver.firefox.profile=my-profile -role node -hub http://example-server.org:4444/grid/register
Notice that the value of the webdriver.firefox.profile has to be the firefox profile name, not the location or the folder name

When running webdriver on a test server with no options to create profiles on the machine you can create your profile programmatically:
private FirefoxProfile GetFirefoxProfile()
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
return firefoxProfile;
}

Fetching a profile is not useful as it is internally creating another copy of the fetched named profile. Accessing the original profile is required if
for eg: test coverage data should be written to a data store across multiple invocations.
Here is a possible solution by Overriding the ProfilesIni class of Selenium
Start by creating a Custom profile using firefox -p, say "CustomSeleniumProfile"
ProfilesIni profileini = new ProfilesIni() {
#Override
public FirefoxProfile getProfile(String profileName) {
File appData = locateAppDataDirectory(Platform.getCurrent());
Map<String, File> profiles = readProfiles(appData);
File profileDir = profiles.get(profileName);
if (profileDir == null)
return null;
return new FirefoxProfile(profileDir);
}
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);
driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");

Related

Firefox pop up obscures the screen paritally in selenium test

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);

selenium firefox webdriver - accessing session

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.

Get Firefox Profile Name at Runtime and Set preferrence

I have a scenario to handle where I am opening Firefox browser using Selenium Webdriver and each time it opens up a new profile. Code is written below:
WebDriver driver = new FirefoxDriver();
Each time it opens up a new profile which is something like : anonymous8958670169066009851webdriver-profile and profile name changes every time WebDriver opens up a Firefox browser. My intention is to get the profile name at runtime and set some preferences on it like handling unresponsive JS alert etc. Basically flow will look like something below:
WebDriver driver = new FirefoxDriver();
<Write some code here to get Firefox profile name>
<Set profile settings like **profile.setPreference("extensions.firebug.currentVersion", "1.8.1");>
Please help me in the second step i.e. Write some code here to get Firefox profile name if anyone already achieved something similar before.
You're approaching the problem backward. The correct thing to do is to create the FirefoxProfile object yourself, and using it in the constructor to the FirefoxDriver. The code would look something like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver driver = new FirefoxDriver(profile);

How to start selenium with firefox driver

I try to follow this link: http://www.seleniumhq.org/docs/03_webdriver.jsp
In SetUpTest:
protected IWebDriver driver;
protected ISelenium selenium;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
selenium = new DefaultSelenium(
"localhost",
4444,
"*chrome",
"http://localhost");
selenium.Start();
verificationErrors = new StringBuilder();
}
When this line driver = new FirefoxDriver(); execute, I have this error:
Additional information: Cannot find a file named '***[Link to my project]\webdriver.xpi' or an embedded resource with the id 'WebDriver.FirefoxExt.zip'.
When I change it to driver = new ChromeDriver();, it opens firefox, but it cannot find element although element already render.
How to make selenium works with firefox?
If you was using C#, this appears that you have added Nuget packages of both Selenium .NET binding and Firefox Driver
I was following this tutorial https://learn.microsoft.com/en-us/vsts/build-release/test/continuous-test-selenium#create-the-test-project. It asks to add all these packages
After the project is created, you must add the Selenium and browser driver references used by the browser to execute the tests. Open the shortcut menu for the Unit Test project and choose Manage NuGet Packages. Add the following packages to your project:
Selenium.WebDriver
Selenium.WebDriver.ChromeDriver
Selenium.WebDriver.IEDriver
Selenium.Firefox.WebDriver
Selenium.WebDriver.PhantomJS.Xplatform
This is wrong. If you are using Firefox driver, you only need Selenium.WebDriver (maybe Selenium.Support as well) and Selenium.Firefox.WebDriver. You don't need Selenium.WebDriver.PhantomJS.Xplatform which will add the wrong WebDriver.dll into your project and the test run will complain about missing .json and .xpi file.

Firefox Driver in Selenium 2 work too slow when is set the proxy settings

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);

Resources