Reputation: 121
I am trying to run Selenium (FluentLenium) tests through a Jenkins Jobs which is setup on a Red-Hat Linux server. It's running a simple JUnit/WebDriver test and a maven build with a"mvn test" command within the project directory. The problem I'm facing is finding a driver to run it off of. The Jenkins engineer here put a geckodriver.exe for me at the path I specified. Although it doesn't really seem to help much.
Where my code is failing:
@Override
public WebDriver newWebDriver(){
System.setProperty("webdriver.gecko.driver", "/var/lib/jenkins/tools/gecko/geckodriver.exe");
return new FirefoxDriver();
}
org.openqa.selenium.WebDriverException:
Browser failed to start, test [ searchForGod(ok.TGoogle) ] execution interrupted.
Caused by: [ java.lang.IllegalStateException: The driver executable does not exist: /var/lib/jenkins/tools/gecko/geckodriver.exe]
+ ls /var/lib/jenkins/tools/gecko/
geckodriver
geckodriver-v0.16.1-linux64.tar.gz
I am aware that geckodriver needs a Firefox application to run. I was told that, since the linux server is non-GUI, a display port is setup to run Firefox. This display port is set on an environment variable on the linux server as DISPLAY = 99. Again though I'm lost on how to get my pom.xml or my java code to point to this. Currently I'm trying:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>PASS.class</include>
<include>TGoogle.class</include>
</includes>
<environmentVariables>
<DISPLAY>99</DISPLAY>
</environmentVariables>
</configuration>
</plugin>
</plugins>
None of this works and I am not making any progress. My only option now is to just setup my own Jenkins server on a linux boot and tried to get it work locally and then get our Jenkins engineer to use my setup. Although he claims I should be able to run it, since others have been able to through the Selenium Plugin submitting .html files. Although, I am having no luck and have exhausted all my options.
Versions:
Locally: Selenium WebDriver 3.5.3, Junit 4.9, Fluentlenium 3.4, Maven
Linux Server: He said that he was using a selenium-standalone-server.jar 2.44 (I know this will conflict for sure with my version of FluentLenium but I get the same exception without it so...), Red Hat Enterprise Linux Server release 7.2, geckodriver 0.19.1
UPDATE:
This following code worked for creating a connection to the server. The Firefox Version is now 52.4, geckodriver 0.16.1, Selenium 3.7.0, FluentLenium 3.4. This version configuration worked locally. And yes geckodriver wasn't an .exe. It was just geckodriver with no file extension.
@Override
public WebDriver newWebDriver(){
GeckoDriverService ds = new GeckoDriverService.Builder()
.usingDriverExecutable(new File("/var/lib/jenkins/tools/gecko/0.16.1/geckodriver"))
.usingFirefoxBinary(new FirefoxBinary(new File("/usr/bin/firefox")))
.withEnvironment(ImmutableMap.of("DISPLAY",":99")).build();
return new FirefoxDriver(ds);
}
Unfortunately Jenkins is now throwing:
[INFO] Running TGoogle
Nov 03, 2017 3:46:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.703 s <<< FAILURE! - in TGoogle
[ERROR] searchForGod(TGoogle) Time elapsed: 4.636 s <<< FAILURE!
java.lang.AssertionError
at TGoogle.searchForGod(TGoogle.java:29)
At least it's "connecting" now. Although it runs locally fine.
UPDATE 2: Finally works now. The configuration shown in the newWebDriver() method code is correct. I had an assertion wrapped in a page object instead of being directly in the JUnit @Test. Not sure why this made a difference (because it didn't within IntelliJ locally). Once I moved the assertion it worked!! Hooray, hope this helps someone.
Upvotes: 1
Views: 994
Reputation: 1804
Unpack the geckodriver tarball and specify path upto the extracted geckodriver file. Use the same version of selenium server that you have mentioned in your pom.xml . Install XVFB on the host linux machine.
Double check that the geckodriver executable version is compatible with Firefox browser version on host machine.
Upvotes: 1