I'm running the following on Win7 with Java6 and Firefox with webdriver:
WebDriver driver = new FirefoxDriver();
driver.get("http://locahost/");
Instead of opening my local server this opens http://www.localhost.com/ which is a registered domain on the internet.
Why is webdriver doing this?
How can I fix this in a way that doesn't involve changing my hosts file?
There is no server at locahost:80 (because of the typo?). If a host name has been entered into the location bar and doesn't resolve then Firefox will try to "fix it". This behavior is controlled by the preferences browser.fixup.alternate.enabled (by default true), browser.fixup.alternate.prefix (by default www.) and browser.fixup.alternate.suffix (by default .com). Webdriver allows changing Firefox preferences via FirefoxProfile.setPreference() so you can disable this behavior - or simply fix the typo.
Related
Current Problem
I'm running automated selenium scripts every night. I just noticed that Firefox 38 is crashing and nothing is being listed in the firefox logs.
Clicking "Restart" firefox means that the tests run fine.
Is there anyway to debug and find what is going on with firefox crashing?
Firefox error report: https://crash-stats.mozilla.com/report/index/fdba810a-1980-45ea-b64b-0e8c62150604
Current Solution
Since "Restart Firefox" is already selected, using xdotool this button is clicked by sending the enter key. (note: set appropriate display, export DISPLAY=:1). I am executing a bash script from cron that contains the following section of code:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin
export DISPLAY=":99"
java -jar /home/m/selenium-server-standalone-2.45.0.jar -htmlSuite "*firefox" "http://www.google.com" "selenium/2_Suite.html" "test_results/2_results.htm" &
sleep 5
xdotool key KP_Enter
wait
Update
Except for simulating the enter key to restart firefox and run the tests, I'v disabled all future updates on my headless automated testing VM using https://support.mozilla.org/en-US/questions/1003777 .
Selenium works on FireFox version 33.0 or below. Do not update your fire fox, selenium will not work on Firefox 36.0.
I had this issue with the .NET bindings. I never solved it, but I have a workaround.
I found that the issue didn't occur when instantiating the Selenium Firefox driver from an existing profile, so my workaround was to create a blank profile, launch Selenium's Firefox driver using a temporary copy of that profile; then at the conclusion of the test, delete the temporary copy.
In this way, you're still using a reasonably-fresh profile, and importantly the same profile, for every test.
The Selenium documentation has instructions on launching the Firefox driver with an existing profile.
I have set this option in my Firefox for Downloads. But each time I am opening the Firefox using Webdriver it is set to Save files to Downloads. So whenever there is a file which is to be downloaded from Firefox launched by Webdriver, it will save to default location.
What can I do so that it always asks me for Download location when launched using webdriver?
Create a firefox profile like this:
https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
In this profile, set the correct download destination.Now in your code when you create the firefox driver, start it with the newly created profile. This should do the trick.
I was able to achieve this using the following code snippet:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.useDownloadDir", false);
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://www.google.com");
How to prevent firefox showing the safe mode dialog after the crash?
It blocks the automatic selenium tests.
I have no idea how you got this and what your testing flow is. So I can't reproduce and test the solution. But Firefox Safe Mode can be disabled by setting the key toolkit.startup.max_resumed_crashes in about:config to -1.
Here's how to start Firefox with that preference set in C# binding:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("toolkit.startup.max_resumed_crashes", "-1");
IWebDriver driver = new FirefoxDriver(profile);
Since Firefox 23, you can also use the environment variable MOZ_DISABLE_AUTO_SAFE_MODE to disable this dialog and the automatic safe mode.
Did you take a look at the configuration options in about:config, there are options for safebrowsing which might be useful.
The solution by #mmm worked until the recent Tor Browser Bundle (which uses Firefox).
If you need an alternative, you can always delete the line
user_pref("toolkit.startup.recent_crashes", 4);
from prefs.js, for example like
sed -i '/toolkit\.startup\.recent_crashes/d' /path/to/prefs.js
or call this as
os.system("sed -i '/toolkit\.startup\.recent_crashes/d' " +
os.path.join('/path/to' + 'prefs.js"))
Since updated to Firefox 12, every time I launch Firefox with a particular profile with Selenium (in python and Mac OS 10.7) it pops up the "checking compatibility of add-ons" dialog, and sometimes this dialog would stay up forever and I have to force-quit it. After forcing quit it, a new instance of the Firefox would continue to launch and finishes the rest of the Selenium script successfully though.
I have tried setting extensions.checkCompatibility to false. This fixed it if I launched Firefox normally, but not if I launch it with Selenium. Any idea on how to suppress this dialog? Thanks!
This dialog is shown only once whenever Firefox is updated. The reason it is shown each time for you is probably that Selenium creates a new profile each time. If you set extensions.lastAppVersion preference to "12.0" (or whatever the current Firefox version is) then Firefox will no longer think that it has been updated and won't show this dialog. However, it should be easier to add a extensions.showMismatchUI preference and set it to false, this will suppress this dialog (but not the other upgrade actions).
Side-note: extensions.checkCompatibility preference no longer does anything starting with Firefox 3.6, it is a version-specific preference in the current Firefox versions. So you would have to set extensions.checkCompatibility.12.0 preference instead. That disables compatibility checking for extensions completely however, not just the dialog you are concerned about.
I have tried setting extensions.checkCompatibility to false. This fixed it if I launched Firefox normally, but not if I launch it with Selenium.
The reason it won't when you launch it with Selenium is the Firefox Driver will create a temporary profile in the temporary files directory, slowing down tests and taking up unnecessary space.
Create a profile for your test purposes and set what you need. Full instructions to create the SeleniumProfile can be found at https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
In Java I have the following:
protected WebDriver createFirefoxDriver() {
File proFile = new File("C:\\Users\\<username>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xxxxxx42.SeleniumProfile");
FirefoxProfile ffProfile = new FirefoxProfile(proFile);
WebDriver ffDriver = new FirefoxDriver(ffProfile);
return ffDriver;
}
Do this to remove the "checking for addon's compatibility" Dialog. This is based on the Windows operating system..
Create a temporary FF Profile and start the server with that profileas shown below.
java -jar selenium-server-x.x.x.jar -firefoxProfileTemplate "/path/to/the/temp/profile"
Now use the following code.
import com.thoughtworks.selenium.*;
public class Test {
public static void main(String ar[]) {
Selenium sel = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/");
sel.start();
}
}
Now in the Run command type "%TEMP%" and you can see there a folder with same name as the selenium session. Copy the folder contents and replace them with your temp profile Contents.
Follow the steps below to remove the Addons compatibility.
1 . Create a new FF Profile
2 . Set the FF Profile as per required settings
3 . Just run a sample program of selenium such that it invokes firefox.
4 . Now you can find a folder with the same name as Selenium Session created somewhere in your sytsem. ( Most probably in the directory where the Temporary Content is saved)
5 . Copy the folder contents and replace them with the newly created profile.
Now you can use the newly created profile whenever required. Whenever FF is updated , always check whether the existing addons are compatible with the Existing version by once invoking firefox with the Profile.
I'm using Selenium to buid a project about automation testing but I have some problem with these lines of code :
String exePath = "Browser\\firefox5.0.1\\firefox.exe";
var firefoxProfile = new FirefoxProfile();
m_browser = new FirefoxDriver(new FirefoxBinary(exePath), firefoxProfile);
m_browser.Navigate().GoToUrl(url);
I can't set firefox url with these codes. But if I use InternetExplorer instead, I can set IE url. I don't know where the problem is
Plz help me. Thank you so much!
If you want to use the chrome driver , you will have to set a property as follows -
System.setProperty("webdriver.chrome.driver","chrome driver path");
You can download the chromedriver.exe for your OS from the following location - http://code.google.com/p/chromedriver/downloads/list
To set up the firefox driver, the Firefox binary is assumed to be in the default location for your particular operating system such as for windows - %PROGRAMFILES%\Mozilla Firefox\firefox.exe (reference - http://code.google.com/p/selenium/wiki/FirefoxDriver)
If firefox is in it's default location you don't have to specify the firefox binary path. But if want to do that, check out this link - FirefoxBinary(java.io.File pathToFirefoxBinary) to make sure your constructors are correct.