0

I want to run the headless browser and below is the code for same. However when i ran it. it shows "Error: no DISPLAY environment variable specified"

try {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.driver", "INFO");
profile.setPreference("webdriver.log.file", targetDir + File.separator + "firefoxSeleniumServer.log");
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv;text/plain");
if(platform.equalsIgnoreCase("linux")) {
DesiredCapabilities desiredCap = DesiredCapabilities.firefox();
profile.setPreference("browser.download.dir",System.getProperty("user.dir")+ File.separator + "target");
System.setProperty("webdriver.gecko.driver", "/test/geckodriver/geckodriver");
System.setProperty("webdriver.firefox.bin","/usr/bin/firefox/firefox");
desiredCap.setCapability("headless", true);
driver = new FirefoxDriver();
}

However when i set the display it shows unable to open firefox on DISPLAY:99

Also i tried setting the xvfb as well. But that also did not work.

As i am using gekco driver here, do i need to do some more configurations.

J.vik
  • 103
  • 2
  • 11
  • you do all of the work for creating a profile and capabilities, but then you instantiate FirefoxDriver() without using them! – Corey Goldberg Sep 19 '18 at 16:31

1 Answers1

0

I think you are supposed to provide the DesiredCapabilities object as a parameter to the FirefoxDriver constructor:

References

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • For selenium3 above is deprecated. I tried with following as well but still facing the same issue. `binary = new FirefoxBinary(new File("/bin/firefox/firefox")); options.setBinary(binary); driver = new FirefoxDriver(options);` – J.vik Sep 19 '18 at 10:34
  • But did you try it with the deprecated class anyway? – Stephen C Sep 19 '18 at 10:59