0

Selenium Grid2 Selenium Grid Hub v.3.4.0 Selenium version 3.4.0 Chrome version v:59.0.3071.115

    org.openqa.selenium.WebDriverException: Connection refused (Connection refused)
Command duration or timeout: 674 milliseconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:437)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsById(RemoteWebDriver.java:457)
    at org.openqa.selenium.By$ById.findElements(By.java:210)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:189)
    at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$952ca716.findElements(<generated>)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:882)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-514.6.2.el7.x86_64', java.version: '1.8.0_111'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:437)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsById(RemoteWebDriver.java:457)
    at org.openqa.selenium.By$ById.findElements(By.java:210)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:189)
    at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$952ca716.findElements(<generated>)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:882)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:40)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:34)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.testng.junit.JUnit4TestRunner.start(JUnit4TestRunner.java:81)
    at org.testng.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:69)
    at org.testng.TestRunner$1.run(TestRunner.java:682)
    at org.testng.TestRunner.runWorkers(TestRunner.java:1005)
    at org.testng.TestRunner.privateRunJUnit(TestRunner.java:713)
    at org.testng.TestRunner.run(TestRunner.java:614)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:132)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:112)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:147)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:161)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:437)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsById(RemoteWebDriver.java:457)
    at org.openqa.selenium.By$ById.findElements(By.java:210)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
    at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:104)
    at com.sun.proxy.$Proxy6.findElements(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.findElements(EventFiringWebDriver.java:177)
    at org.openqa.selenium.remote.server.handler.FindElements.call(FindElements.java:50)
    at org.openqa.selenium.remote.server.handler.FindElements.call(FindElements.java:35)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

My remoteDriver method

private WebDriver getRemoteDriver(Browser browser) throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = getCapabilities(browser);
        desiredCapabilities.setCapability("platform", "LINUX");

        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        final RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);
        remoteWebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        remoteWebDriver.setFileDetector(new LocalFileDetector());

        return new Augmenter().augment(remoteWebDriver);
    }

Problem appears randomly, but only when I run my test through Jenkins->Grid. When I run them local they pass without any problems. With above problem I recevie error while invoking driver.quit()

    org.openqa.selenium.NoSuchSessionException: Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
 os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-514.6.2.el7.x86_64', java.version: '1.8.0_131'
    Driver info: driver.version: unknown
    Command duration or timeout: 70 milliseconds

Everything started when I upgraded version of Selenium Grid (I try to resolve it without SG downgrade). Can anyone help? Thanks.

Gokul
  • 788
  • 2
  • 12
  • 30
kpioro
  • 3
  • 2
  • *"Caused by: java.net.ConnectException: Connection refused (Connection refused)"* - this looks like network connectivity issues. – mkl Jul 31 '17 at 10:13
  • But other tests work fine. This issue appears randomly - mostly appears only for few tests. – kpioro Jul 31 '17 at 10:28
  • Couple of questions... 1. What do you mean by "it works when I run locally" ? Are you saying that it works fine when you kick off your tests via your IDE or a command prompt against the Grid ? 2. Your stacktrace indicates that your server is getting killed when a `findElements()` call is being triggered. So there's something that is introducing a delay and causing your node session to go idle for sometime. Does your hub start with some configuration or does it start by default. Share the command. 3. Why are you using `Augmenter` ? – Krishnan Mahadevan Aug 01 '17 at 09:08
  • @KrishnanMahadevan 1. It works fine when I run via IDE (IntelliJ). 3. What is better solution instead of Augmenter? – kpioro Aug 01 '17 at 09:56
  • @KrishnanMahadevan 2. I'm already working to try this on brand new server. The old one was pretty heavly loaded with other processes. Selenium-Grid hub runs on Jenkins. It's builded with docker configuration hub launched with : -browserTimeout 0 -debug false -help false -jettyMaxThreads -1 -port 4444 -role hub -timeout 10 -cleanUpCycle 5000 -host 172.18.0.1 -maxSession 5 -hubConfig /opt/selenium/config.json -capabilityMatcher org.openqa.grid.internal.utils.DefaultCapabilityMatcher -newSessionWaitTimeout -1 -throwOnCapabilityNotPresent true – kpioro Aug 01 '17 at 09:58
  • The rest of configuration: browserTimeout : 0 debug : false help : false jettyMaxThreads : -1 port : 4444 role : hub timeout : 10 cleanUpCycle : 5000 host : 172.18.0.1 maxSession : 5 hubConfig : /opt/selenium/config.json capabilityMatcher : org.openqa.grid.internal.utils.DefaultCapabilityMatcher newSessionWaitTimeout : -1 throwOnCapabilityNotPresent : true – kpioro Aug 01 '17 at 11:30
  • @KrishnanMahadevan I tried advice from other thread. I downgraded version of selenium and selenium-grid to 3.3.1. Everything seemed to work fine until one of the drivers (in grid) hans on POST session-execution and test timed-out after 20 min (on Jenkins). Can you provide any solution? – kpioro Aug 01 '17 at 12:27

1 Answers1

0

You mentioned that you have the following as your Hub configuration

-browserTimeout 0 -debug false -help false -jettyMaxThreads -1 -port 4444 -role hub 
-timeout 10 -cleanUpCycle 5000 -host 172.18.0.1 -maxSession 5 
-hubConfig /opt/selenium/config.json 
-capabilityMatcher org.openqa.grid.internal.utils.DefaultCapabilityMatcher 
-newSessionWaitTimeout -1 -throwOnCapabilityNotPresent true 

You have configured your -timeout to be 10 seconds which means the moment the hub sees that a particular session has been idle for more than 10 seconds it will be cleaned up from the server side.

To make matters worse, you have setup an implicit timeout of 30 seconds remoteWebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

If you look at your stacktrace, you would see that your connection refused errors are all stemming up from the place where a call to driver.findElements() is made and implicit waits impact exactly this place.

So what is happening here is, that your code asks webdriver server component (chromedriver/geckodriver/IEDriverServer) to wait for 30 seconds if an element is not immediately found (polling), and on the Grid side, you have configured your hub and instructed it to clean up any test sessions which has been sitting idle for more than 10 seconds (that is for more than 10 seconds there are no JSONWireProtocol commands being sent by your test to the node). So your hub cleans your session which eventually also gets rid of your browser and the server component, and your test tries to talk to a server that no longer exists.

To fix this, I would suggest you do the following :

  1. Get rid of your implicit waits and instead favor explicit waits.
  2. If you must absolutely use implicit waits, bump up your -timeout values to higher one or leave it at its default (i.e., 1800 seconds)

Give it a shot and let me know how that goes.

PS : You don't need the Augmenter in your code as well, because you aren't enriching the webdriver in any fashion and the Augmenter returns back the same RemoteWebDriver if it finds it to be a RemoteWebDriver instance (which is true in your case)

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • Thanks for pointing this out. I did it as you said and currently everything works fine in version 3.4.0. There was also problem with multiple builds of the same tests for different projects and lack of webdrivers on Selenium-grid, but I fixed it with throttle configuration on jenkins. – kpioro Aug 04 '17 at 09:16