In Selenium Grid I am trying to execute a simple program and I'm getting Cannot find firefox binary in PATH
though I have added the binary path in my code.
My code and the error are given below. Kindly need help. Thanks in advance.
Code
package Sample;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class sample1 {
WebDriver driver;
String BaseURL,NodeURL;
@BeforeTest
public void beforeTest() throws MalformedURLException {
BaseURL="www.google.com";
NodeURL="http://192.168.10.162:5566/wd/hub";
DesiredCapabilities capa =DesiredCapabilities.firefox();
capa.setBrowserName("firefox");
capa.setCapability("binary", "C:\\Users\\praveenraj.d\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
capa.setPlatform(Platform.ANY);
driver=new RemoteWebDriver(new URL(NodeURL),capa);
}
@Test
public void f() throws InterruptedException {
driver.get(BaseURL);
System.out.println(driver.getTitle());
Thread.sleep(50000);
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Error
[TestNG] Running:
C:\Users\praveenraj.d\AppData\Local\Temp\testng-eclipse-1233453386\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeTest beforeTest
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Command duration or timeout: 97 milliseconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at Sample.sample1.beforeTest(sample1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55)
at org.openqa.selenium.firefox.FirefoxDriver.getBinary(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:107)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:216)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:170)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
SKIPPED CONFIGURATION: @AfterTest afterTest
SKIPPED: f
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@93b52b: 27 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3ba002: 22 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@fa930d: 6 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1f9c5c8: 6 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@197f158: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms
This question is related to
java
selenium
selenium-webdriver
selenium-grid
The easiest thing to do is have your grid nodes register the Firefox binary path as part of the node config. It uses the same capabilities that the client has, but allows you to pick the browser by name and let the node find it.
Please also note that the capability you want is "firefox_binary" and not "binary". You can see the full list of Firefox capabilities at this wiki page:
java -jar selenium-server-standalone-2.53.1.jar -Dwebdriver.firefox.bin="C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
Put selenium jar file on desktop, go to cmd and run the above command.
Make sure that firefox must install on default place like ->(c:/Program Files (x86)/mozilla firefox OR c:/Program Files/mozilla firefox, note: at the time of firefox installation do not change the path so let it installing in default path) If firefox is installed on some other place then selenium show those error.
If you have set your firefox in Systems(Windows) environment variable then either remove it or update it with new firefox version path.
If you want to use Firefox in any other place then use below code:-
As FirefoxProfile is depricated we need to use FirefoxOptions as below:
New Code:
File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
The full working code of above code is as below:
System.setProperty("webdriver.gecko.driver","D:\\Workspace\\demoproject\\src\\lib\\geckodriver.exe");
File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.co.in/");
Download geckodriver for firefox from below URL:
https://github.com/mozilla/geckodriver/releases
Old Code which will work for old selenium jars versions
File pathBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
I had the same issue in C# using 64-bit Windows and the 64-bit Firefox browser which doesn't seem to work on Selenium. If you are using the 64-bit browser, try the 32-bit one.
Surprisingly, the 32-bit Firefox browser runs on 64-bit Windows just fine.
Edited to clarify the intent of my post.
This is due to RemoteWebDriver used in code, It tries to invoke firefox browser in node machine, If you have specified firefox binary location in "PATH" environment variable of node machine, It will open firefix browser on executing it from Hub.
I've just had this issue without changing PATH.
My PC is Win7, 64-bit system, If you are also using 64-bit system, you may want to try:
It must be under "Program Files (x86)" NOT "Program Files"
Hope it can help.
Another option is to configure the server rather than the test client.
Configure the slave node service so that it knows where the firefox is. Install location can change from node to node, or even need multiple services running on a node to support access to different versions of FF.
java -jar "selenium-server-standalone-2.2.0.jar"
-Dwebdriver.firefox.bin="C:\FirefoxCollection\Mozilla Firefox 36.0\firefox.exe"
I have also face same issue on Windows 10-64 bit OS.
When I am installed firefox on my PC its installed location is "C:\Program Files\Mozilla Firefox\firefox.exe" instead of "C:\Program Files (x86)\Mozilla Firefox", because OS is 64 bit,
So I just copy & paste "Mozilla Firefox" folder in "C:\Program Files (x86)" folder and execute selenium scripts, its work for me.
You should change environment variable and add there path to firefox.exe. The same could be done programmatically How can I set/update PATH variable from within java application on Windows?. I had the same problem on Win8.
Did you add firefox to your path after you have started the selenium server? If that is the case selenium will still use old path. The solution is to tear down & restart selenium so that it will use the updated Path environment variable.
To check if firefox is added in your path correctly you can just launch a command line terminal "cmd" and type "firefox" + ENTER there. If firefox starts then everything is alright and restarting selenium server should fix the problem.
System.setProperty("webdriver.gecko.driver", "D:\\Katalon_Studio_Windows_64-5.10.1\\configuration\\resources\\drivers\\firefox_win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
DriverFactory.changeWebDriver(driver)
You need to add gecko driver
if you are using firefox v50
and above.
Use the following sample code :
File pathToBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver","C:\\Users\\Downloads\\selenium-java-3.0.1\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
This issue may be because of the incompatibility of firefox driver and your firefox browser version. Download the latest version of firefox driver which is compatible with the updated Firefox browser version.
File pathToBinary = new File("C:\\user\\Programme\\FirefoxPortable\\App\\Firefox\\firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
I didn't see the C# anwer to this question here. The trick is to set the BrowserExecutableLocation property on a FirefoxOptions instance, and pass that into the driver constructor:
var opt = new FirefoxOptions
{
BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe"
};
var driver = new FirefoxDriver(opt);
Source: Stackoverflow.com