1

I have an application that uses Selenium WebDriver to control FireFox. It runs as a Web Application under Tomcat - yes, this is a bit of an odd architecture, but there are good reasons for doing this.

I've been testing this on my MacBook and it's been working well. My code calls WebDriver, WebDriver calls gecko, Firefox runs, all is good.

I now move to a Centos-7 box, and hit a problem

org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host:'xxx', ip: 'a.b.c.d', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.el7.x86_64', java.version: '1.8.0_222' Driver info: driver.version: FirefoxDriver

I am using

  • Selenium: 3.141.59
  • Gecko: geckodriver 0.24.0 ( 2019-01-28)
  • Firefox: Mozilla Firefox 60.8.0

I have Xvfb installed and running.

My code simply calls

m_driver = new FirefoxDriver();

which I believe to be the current idiom.

I have added

JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"

to my tomcat.conf

I see references to this kind of problem from older versions of Firefox and Gecko, and an indication it may be a version problem, but as far as I can tell I'm at the latest versions of everything.

Suggestions for fix or getting some diagnostics please.

djna
  • 54,992
  • 14
  • 74
  • 117
  • I had forgotten one crucial fact: I'm running under Selinux, so there's an extra level of security. The Tomcat Java process does not have "name_connect" permissions for the ephemeral port it's using. A proper solution is to semanage permissions for Java to work with a set of ports. If and when I figure that out I'll post a formal answer. – djna Aug 21 '19 at 07:54

1 Answers1

1

I think you were pretty close. Though the following line in tomcat.conf looks perfect:

JAVA_OPTS="-Dwebdriver.gecko.driver=/opt/gecko/geckodriver"

But I am still not sure if -Dwebdriver.firefox.driver=/usr/bin/firefox is a requirement for you.

As per Class FirefoxDriver.SystemProperty the value of webdriver.firefox.driver refers to the Constant Field DRIVER_XPI_PROPERTY which is the System property that defines the location of the webdriver.xpi browser extension to install in the browser. If not set, the prebuilt extension bundled with this class will be used. Unless absolutely necessary this Constant Field must be left untouched.

So dropping -Dwebdriver.firefox.driver=/usr/bin/firefox will solve the issue.


Update

A bit more details about your usecase would have helped us to debug the issue in a better way. However as you have mentioned Xvfb is installed and running you need to take care of a couple of facts as mentioned below:

  • Ensure that if you are running Firefox on a system with no display you have to use headless mode.
  • The correct usage of headless mode with GeckoDriver v0.24.0 is:

    options.headless = True
    
  • There is no need for xvfb-run anymore if you set MOZ_HEADLESS=1 as follows:

    $ export MOZ_HEADLESS=1   # this way you only have to set it once
    

You can find a detailed discussion in How to make firefox headless programmatically in Selenium with python?

  • If you have changed your system path, take a System Reboot.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
  • Always execute your @Tests as a non-root user.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Yes, I feel close! I should have said, I only added that webdriver.firefox.driver item in desperation, the same problem occurs both with and without that :-( – djna Aug 21 '19 at 06:10
  • 1
    it's Selinux causing the issue. More detail when I figure out a complete solution. – djna Aug 21 '19 at 07:55
  • @djna Checkout the updated answer and let me know if that helps. – undetected Selenium Aug 21 '19 at 19:08
  • The capability problem was entirely due to selinux. I temporarily disabled that security and immediately hit a headless problem that MOZ_HEADLESS=1 fixed. All works now thanks. For a "correct" solution I just need to find the proper way to set selinux permissions to enable a set of ephemeral ports for selenium/gecko to use. – djna Aug 22 '19 at 07:29
  • @djna I think I have a solution for that as well. But that would be a different question :) – undetected Selenium Aug 22 '19 at 07:37
  • ...and Lo! There is another question ... ;-) – djna Aug 22 '19 at 08:29