Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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

1 Answer

0 votes
by (62.9k points)

If you cannot reinstall the Firefox browser or if you could not make the choice of the location during installation, you can even specify the location of the existing binary as given below.

File pathBinary = new File("your\\location\\to\\the\\firefox.exe");

FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);

FirefoxProfile firefoxProfile = new FirefoxProfile();       

WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);

If you have installed Firefox at a custom location, uninstall existing firefox and install it at a default location.

"C:\Program Files (x86)\Mozilla Firefox\"

Your firefox should be under "Program Files (x86)" NOT "Program Files" or any other custom location.

There are two steps to stop docker application containers:

First, stop the running containers using docker-compose stop

Second, remove the stopped containers using docker-compose rm -f

Stop the application containers using docker-compose stop:

# cd /home/myapp/

# docker-compose stop

Stopping web ... done

Stopping data ... done

Stopping myapp ... done

Remove the application containers using docker-compose rm -f:

# cd /home/myapp/

# docker-compose rm -f

Going to remove web, data, myapp

Removing web ... done

Removing data ... done

Removing myapp ... done

Note: If you don’t specify -f in the above command, it will prompt you for Y/N before removing it.

Since you’ll be doing this frequently, combine both of the above stop and rm, as shown below.

In this case, since we have “&&”, which will execute the 2nd command only after the 1st command is successful. So, it will do “rm -f”, only after stopping the docker containers successfully.

 # docker-compose stop && docker-compose rm -f

Stopping web ... done

Stopping data ... done

Stopping myapp ... done

Going to remove web, data, myapp

Removing web ... done

Removing data ... done

Removing myapp ... done

I hope this helps!

Browse Categories

...