Search code examples
javamavenseleniumjenkinsgeckodriver

FAILED TO establish the default connection to the WindowServer error using GeckoDriver Firefox through Selenium Maven in Jenkins


So i am learning selenium and jenkins integration using java and maven. I had issues with chrome and jenkins and was told i should try the firefox webdriver. So this is what i did. However i get the following error when i run the build on jenkins: Can anyone help me with this? My script runs fine locally on the IDE.

I am also using a mac 10.13.6 (High Sierra), Firefox 70, Geckodriver v 0.26.0 , 3.141.59, Java eclipse ID and Maven 3.6.2

Please help and thanks!

1) JENKINS LOG

Started by user Eamo
Running as SYSTEM
Building in workspace /Users/Shared/Jenkins/Home/workspace/test
Parsing POMs
Established TCP socket on 59937
[Test] $ /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java -cp /Users/Shared/Jenkins/Home/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/Applications/apache-maven-3.6.2/boot/plexus-classworlds-2.6.0.jar:/Applications/apache-maven-3.6.2/conf/logging jenkins.maven3.agent.Maven35Main /Applications/apache-maven-3.6.2 /Users/Shared/Jenkins/Home/war/WEB-INF/lib/remoting-3.36.jar /Users/Shared/Jenkins/Home/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /Users/Shared/Jenkins/Home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 59937
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /Users/Eamon/eclipse-workspace/Test/pom.xml clean test
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< SeleniumTest:SeleniumTest >----------------------
[INFO] Building SeleniumTest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ SeleniumTest ---
[INFO] Deleting /Users/Eamon/eclipse-workspace/Test/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SeleniumTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ SeleniumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SeleniumTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ SeleniumTest ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/Eamon/eclipse-workspace/Test/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12:test (default-test) @ SeleniumTest ---
[INFO] Surefire report directory: /Users/Eamon/eclipse-workspace/Test/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
1575090370363   mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-foreground" "-no-remote" "-profile" "/var/folders/3n/x7zhpjbj00z7bm533_6x264r00008b/T/rust_mozprofileNeahYN"
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: telemetry
1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
1575090375045   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: about:reader*
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Tests run: 3, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 62.465 sec <<< FAILURE!

Results :

Failed tests:   startBrowser(Eamon.EamonTest): connection refused(..)

Tests run: 3, Failures: 1, Errors: 0, Skipped: 2

[ERROR] There are test failures.

Please refer to /Users/Eamon/eclipse-workspace/Test/target/surefire-reports for the individual test results.
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:16 min
[INFO] Finished at: 2019-11-29T21:07:17-08:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /Users/Eamon/eclipse-workspace/Test/pom.xml to SeleniumTest/SeleniumTest/0.0.1-SNAPSHOT/SeleniumTest-0.0.1-SNAPSHOT.pom
/Users/Eamon/eclipse-workspace/Test/pom.xml is not inside /Users/Shared/Jenkins/Home/workspace/Test/Users/Eamon/eclipse-workspace/Test/; will archive in a separate pass
channel stopped
Finished: UNSTABLE

2) My Code

public class EamonTest {

    public String baseUrl = "http://demo.guru99.com/test/newtours/";
    String driverPath = "/Users/Eamon/Desktop/geckodriver";
    public WebDriver driver;

    @BeforeTest
    public void startBrowser() {
        System.setProperty("webdriver.gecko.driver", driverPath);
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        driver = new FirefoxDriver(capabilities);

    }

    @Test
    public void navigateToUrl() {
        driver.get("http://demo.guru99.com/selenium/guru99home/");
    }

    @AfterTest
    public void endTest() {
        driver.quit();
    }

Solution

  • This error message...

    1575090370363   mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-foreground" "-no-remote" "-profile" "/var/folders/3n/x7zhpjbj00z7bm533_6x264r00008b/T/rust_mozprofileNeahYN"
    _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
    1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
    1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: telemetry
    1575090375044   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
    1575090375045   [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: about:reader*
    _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
    _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
    _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
    Exiting due to channel error.
    Exiting due to channel error.
    Exiting due to channel error.
    

    ...implies that the GeckoDriver was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session.

    Your main issue is the usage of deprecated constructor of FirefoxDriver Class as follows:

    In the current version of Selenium v3.141.59 the constructor FirefoxDriver(Capabilities desiredCapabilities) is deprecated.

    desiredcapabilities


    Solution

    You need to use the merge() method from MutableCapabilities Class to merge the DesiredCapabilities type object into FirefoxOptions type object and initiate the WebDriver and WebClient instance by passing the FirefoxOptions object as follows :

    @BeforeTest
    public void startBrowser() {
        System.setProperty("webdriver.gecko.driver", driverPath);
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        FirefoxOptions options = new FirefoxOptions();
        options.merge(capabilities);
        driver = new FirefoxDriver(options);
    

    References

    You can find a couple of relevant discussions in: