0

Background: I am currently using Maven to download Selenium chrome driver from the remote repo in order to perform TestNG automations. When I am on corporate network, I receive the following error, which is seemingly terminating my connection everytime with the server upon initiation.

Code:

if(browserName.equalsIgnoreCase("chrome") )
{
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--no-proxy-server");
    //options.addArguments("--headless");
    options.addArguments("--window-size=1920,1080");
    options.addArguments("--disable-extensions");
    options.addArguments("--proxy-server='direct://'");
    options.addArguments("--proxy-bypass-list=*");
    options.addArguments("--disable-gpu");
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--no-sandbox");
    options.addArguments("--start-maximized");
    options.addArguments("--ignore-certificate-errors");        
    WebDriverManager.chromedriver().setup();
    driver= new ChromeDriver(options);
}

Error:

org.testng.TestNGException: java.net.SocketException: Unexpected end of file from server`
at org.testng.TestNG.parseSuite(TestNG.java:327)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:348)
at org.testng.TestNG.initializeEverything(TestNG.java:995)
at org.testng.TestNG.run(TestNG.java:1009)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)`
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: java.net.SocketException: Unexpected end of file from server
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:866)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:863)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1615)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:676)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1398)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1364)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:257)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1152)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1040)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:943)`
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
at java.xml/javax.xml.parsers.SAXParser.parse(SAXParser.java:197)
at org.testng.xml.XMLParser.parse(XMLParser.java:38)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
at org.testng.xml.Parser.parse(Parser.java:152)
at org.testng.xml.Parser.parse(Parser.java:233)
at org.testng.TestNG.parseSuite(TestNG.java:295)
... 10 more

As a work around, I have tried to install both root certificates from the Maven repo directly into my JRE Keystore but the error still perssts. The connection is only resumed when I am off the corporate network, then the driver intiates without issues.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Classical case of firewall blocking your request. On your corporate network firewall is enabled and your requests are getting blocked. – Saurabh Jhunjhunwala Mar 30 '22 at 20:00
  • you might try downloading the webdriver(s) yourself instead of using WebDriverManager. See if that's where the issue arises... if so, it seems like you need to set WebDriverManager to use the same proxy you are setting Chromedriver to use. – pcalkins Mar 30 '22 at 20:20

1 Answers1

0

Unexpected end of file implies that the remote server accepted the connection but the connection was closed without sending a response. The most possible reason is that the remote system is too busy to handle the request or that there's a network snag that randomly drops connections.

However, using Selenium this error occurs generally occurs due to either of the following reasons:

  • Firewall blocking the port used by ChromeDriver
  • Antivirus blocking the connection

Solution

Either of the following steps should solve your issue:

  • Whitelist the port(s) used by ChromeDriver
  • Disable the Antivirus on your test system.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352