0

I've writed a simple E2E test using Selenium WebDriver in Java.

When I run this test using maven test, intellij idea throw me an error:

Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: LINUX

My OS is openSUSE Leap 15.2 and for test I wanted to use installed Mozilla Firefox 78esr:

ac@icarus:~> firefox -v
Mozilla Firefox 78.2.0esr

Firefox is installed from openSUSE repo in a default location.

I have do a research and I've set a property for webdriver.firefox.bin: System.setProperty("webdriver.firefox.bin", "path_to_firefox_binary"); to point it to installed firefox binary.

When I start this test again i've get a different error:

[ERROR] userShouldOpenLoginPage Time elapsed: 1.096 s <<< ERROR! java.lang.IllegalStateException: Specified firefox binary location does not exist or is not a real file: /usr/bin/firefox

For path I try: /usr/bin/firefox, /usr/lib64/firefox/firefox, /usr/lib64/firefox/firefox-bin.

To get path for firefox binary I use whereis command:

ac@icarus:~> whereis firefox firefox: /usr/bin/firefox /usr/lib64/firefox /usr/share/man/man1/firefox.1.gz

I try to fix this but nothing works, so I've downloaded firefox from mozilla site and point property to it. Now binary is found, but IJ throw me another error:

XPCOMGlueLoad error for file /home/ac/Pobrane/firefox/libxul.so: libdbus-glib-1.so.2: cannot open shared object file: No such file or directory Couldn't load XPCOM.

When I try running firefox normally everything works great - browser starts.

I've tried checking if I have libdbus-glib-1.so.2:

ac@icarus:~/Pobrane/firefox> ldd libxul.so | grep libdbus-glib-1.so.2
        libdbus-glib-1.so.2 => /usr/lib64/libdbus-glib-1.so.2 (0x00007fe4dd115000)
ac@icarus:~/Pobrane/firefox> ls -allh /usr/lib64/ | grep libdbus-glib-1.so.2
lrwxrwxrwx   1 root root    23 05-16 18:45 libdbus-glib-1.so.2 -> libdbus-glib-1.so.2.3.3
-rwxr-xr-x   1 root root  162K 05-16 18:45 libdbus-glib-1.so.2.3.3

Lib libdbus-glib-1.so.2 exist (is a symlink) and it point to libdbus-glib-1.so.2.3.3 so why I get error "cannot open shared object file"?

Anyone have an idea how to fix it?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
andy
  • 1
  • 1

1 Answers1

0

webdriver.firefox.bin is no more a valid property to be set through System.setProperty()

To set the path of the binary you need to use an instance of FirefoxBinary() and pass it to an instance of FirefoxOptions() as follows:

import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;

System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
FirefoxBinary binary = new FirefoxBinary(new File("/usr/bin/firefox"));
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
options.setLogLevel(FirefoxDriverLogLevel.TRACE);
FirefoxDriver driver = new FirefoxDriver(options);
driver.navigate().to("https://www.google.com/");

Optimizing the code you can use:

System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
FirefoxOptions options = new FirefoxOptions();
options.setBinary(new FirefoxBinary(new File("/usr/bin/firefox")));     
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com/");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have changed the way that path for binary is passed to a webdriver instance, but this not fix anything in my case :/ – andy Sep 25 '20 at 12:49