测试失败 - 使用 SeleniumGrid 启动



Selenium Grid2 硒网格集线器 v.3.4.0 硒版本 3.4.0 铬版本 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)

我的远程驱动程序方法

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);
}

问题随机出现,但仅当我通过 Jenkins->Grid 运行测试时。当我在本地运行它们时,它们没有任何问题。对于上述问题,我在调用 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

一切都始于我升级版本的Selenium Grid(我尝试在不SG降级的情况下解决它(。 谁能帮忙?谢谢。

您提到您有以下内容作为您的中心配置

-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 

您已将-timeout配置为10 seconds这意味着当中心看到特定会话空闲超过10 秒时,将从服务器端清理该会话。

更糟糕的是,您设置了 30 秒的隐式超时remoteWebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

如果您查看堆栈跟踪,您会发现连接被拒绝错误都源于调用driver.findElements()的位置,implicit waits恰好影响此位置。

所以这里发生的事情是,你的代码要求 webdriver 服务器组件 (chromedriver/geckodriver/IEDriverServer( 等待 30 秒,如果没有立即找到元素(轮询(,并且在网格端,你已经配置了你的集线器并指示它清理任何空闲超过 10 秒的测试会话(即超过 10 秒没有发送 JSONWireProtocol 命令通过您对节点的测试(。因此,您的集线器会清理您的会话,最终也会删除您的浏览器和服务器组件,并且您的测试会尝试与不再存在的服务器通信。

要解决此问题,我建议您执行以下操作:

  1. 摆脱隐式等待,转而支持显式等待。
  2. 如果必须绝对使用隐式等待,请将-timeout值提高到更高的值或将其保留为默认值(即1800秒(

试一试,让我知道这是怎么回事。

附言 : 您也不需要代码中的Augmenter,因为您没有以任何方式丰富 Web 驱动程序,并且如果 Augmenter 发现它是RemoteWebDriver实例,它会返回相同的RemoteWebDriver(在您的情况下确实如此(

相关内容

  • 没有找到相关文章

最新更新