Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
2.8k views
by Contributing Tester (92 points)
edited by
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.net.URL;

public class FirefoxOptionsDebug {
    private RemoteWebDriver driver;
    private String firefox = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";

    @BeforeClass
    public void beforeClass() throws IOException {
        String grid = "192.168.241.131";

        DesiredCapabilities caps = DesiredCapabilities.firefox();
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(firefox);
        caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
        driver = new RemoteWebDriver(new URL(String.format("http://%s:4444/wd/hub", grid)), caps);
    }

    @Test
    public void testMethod() {
        driver.get("http://www.google.com");

    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }
}

 

 

I am getting error message as

 

java.lang.IllegalStateException: Specified firefox binary location does not exist or is not a real file: C:\Program Files (x86)\Mozilla Firefox\firefox.exe

	at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
	at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:46)
	at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:162)
	at org.openqa.selenium.firefox.FirefoxOptions.getBinaryOrNull(FirefoxOptions.java:202)
	at org.openqa.selenium.firefox.FirefoxOptions.toString(FirefoxOptions.java:590)
	at java.lang.String.valueOf(String.java:2994)
	at org.openqa.selenium.remote.DesiredCapabilities.shortenMapValues(DesiredCapabilities.java:279)
	at org.openqa.selenium.remote.DesiredCapabilities.toString(DesiredCapabilities.java:268)
	at com.google.common.base.Joiner.toString(Joiner.java:455)

 

 

 

It seems that FF Binary is not readable

I tried to give all permissions to said folder, however with no luck.

1 Answer

0 like 0 dislike
by

I believe you don't really need to specify the path at first place if your Firefox browser is installed at the default location.

I suspect that the escape character "\" is getting void. Can you use your path as given below and try again?

C:\\\\Program Files (x86)\\\\Mozilla Firefox\\\\firefox.exe

Also, make sure that the location is valid. 

by Contributing Tester (12 points)
So how do you solve the problem , if the install location is not default ? Im using Selenium 3 and its no possible for me to use it with Firefox Portable with a not default path.

I get same exception as the thread owner.
by The go-to Tester (181 points)
You can use FirefoxOptions,

FirefoxOptions options = new FirefoxOptions();
        options.setBinary("Path to your ff binary");

and you can pass it to webdriver as below.

caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options); //caps is DesiredCapability.
        driver = new RemoteWebDriver(new URL(String.format("http://%s:4444/wd/hub", grid)), caps);

Hope that helps!
by Contributing Tester (12 points)
Ok i finally can start Firefox Portable but the next Problem is , its not starting to test a url

Following code

FirefoxOptions options = new FirefoxOptions();
options.setBinary(new FirefoxBinary(new File(config.getFf_path())));
options.setProfile(new FirefoxProfile(new File(config.getFf_profile())));
                       

            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
            capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
            System.setProperty("webdriver.gecko.driver", config.getGeckodriver_path());
            driver = new FirefoxDriver(capabilities);
            driver.manage().window().maximize();
            driver.get(this.url);

My code never passes after the code line "driver = new FirefoxDriver(capabilities). It just starts Firefox Portabe, show me my profile directory but dont do driver.manage and no driver.get(this.url)...its just stopped. No timeout nothing.
by The go-to Tester (181 points)
Please raise new issue as a new question at https://softwaretestingboard.com/qna/ask with more description.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...