如何解决间歇性 org.openqa.selenium.TimeoutException: 超时
How to troubleshoot intermittent org.openqa.selenium.TimeoutException: timeout
我们将 Selenium 用于我们的网站 UI 自动化测试。我们建立了一个实验室,有 10 台机器安装 Windows 7 作为唯一的 OS。并且自动化测试(>800)将每天平均分配给这些机器一次。但是,我们在不同的测试用例中间歇性地遇到以下超时错误。乍一看,这似乎是由于尝试加载和呈现页面时超时。但是,当我们手动打开该页面时,我们以前从未遇到过这种情况。
我通读了 google 组和本网站上的几篇帖子,但其中 none 为我的问题提供了解决方法。基本上,我正在寻找一种更好的方法来解决此超时异常,以找到明确的 RCA 并一劳永逸地修复它。我期待我们可以通过一些开关或详细日志。当然,也欢迎其他建议或解决方案。
以下是超时错误的详细信息。您可以在那里找到版本和环境信息。
java.lang.AssertionError: org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.93 seconds
Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38'
System info: host: 'v244023117ZzttZ', ip: '10.244.23.117', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 0dd88a079e79fe8da9cc950ebf07e535
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir3804_7174, chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, locationContextEnabled=true, mobileEmulationEnabled=false, version=61.0.3163.100, pageLoadStrategy=normal, takesHeapSnapshot=true, databaseEnabled=false, cssSelectorsEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:276)
at com.hhop.bbs.base.ATSWebDriver.open(ATSWebDriver.java:827)
at com.hhop.bbs.fancytest.channel.method.AbstractIPaymentMethod.renderCashier(AbstractIPaymentMethod.java:49)
at com.hhop.bbs.fancytest.channel.method.AbstractIPaymentMethod.doPayment(AbstractIPaymentMethod.java:84)
at com.hhop.bbs.fancytest.actions.channel.TradePaymentAction.fire(TradePaymentAction.java:42)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver.driver(DefaultProcessDriver.java:35)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$FastClassBySpringCGLIB$355ca6.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$EnhancerBySpringCGLIB$9c9f75.driver()
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.runFailFastMode(TestFlowEngine.java:85)
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.execute(TestFlowEngine.java:58)
at com.hhop.bbs.fancytest.actions.comm.AbstractParentFlowExecuteAction.executeParentFlow(AbstractParentFlowExecuteAction.java:44)
at com.hhop.bbs.fancytest.actions.channel.TradeRefundPrepareAction.prepareForParentFlow(TradeRefundPrepareAction.java:51)
at com.hhop.bbs.fancytest.actions.comm.AbstractParentFlowExecuteAction.fire(AbstractParentFlowExecuteAction.java:27)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver.driver(DefaultProcessDriver.java:35)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$FastClassBySpringCGLIB$355ca6.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$EnhancerBySpringCGLIB$9c9f75.driver()
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.runFailFastMode(TestFlowEngine.java:85)
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.execute(TestFlowEngine.java:58)
at com.hhop.bbs.fancytest.testflow.LinkTestBase.run(LinkTestBase.java:155)
at com.hhop.bbs.testcase.channel.TradeInSaleFxRefundTestGroup2.doRefund(TradeInSaleFxRefundTestGroup2.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:758)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access[=11=]0(SuiteRunner.java:37)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
:
祝福,
静飞
这类问题可能令人沮丧。以下是我在调试此类问题时尝试回答的几个问题:
- 超时异常是否发生在您代码中的同一点
每当你遇到这个,还是在不同的地方?
- 超时总是同一个动作,还是不同的动作?该代码可能正在尝试对尚不可见的元素执行操作。
- 相同的页面,还是不同的?
- 问题是在一天中的特定时间出现,还是在服务器上有其他活动会导致应用程序变慢时出现?
- 代码是否对页面的当前状态做出假设?如果是这样,您可能希望为您的自动化制定一条规则,即在对元素采取某些操作之前始终检查元素是否为 visible/clickable/enabled。如果这些假设是错误的,但未经检查,您最终会遇到令人困惑的失败。
我的自动化框架大量使用了 WebDriverWait,我尝试在达到超时的情况下包含有用的消息,帮助我隔离问题的根源
软件版本:
仔细查看日志会发现有关您的 Test Bed
的以下内容:
Selenium Version
: 2.39.0
Chromedriver Version
: 2.33
Chrome Version
: 61.0
我建议您将 Selenium Version
提高到 v3.6.0
,如 Selenium 3.x
相对于 Selenium 2.39.0
,很多功能已经 added/upgraded/deprecated。一旦您使用了最新版本,SO 志愿者就可以轻松进行调试。
错误分析:
仔细查看错误同时描述了 java.lang.AssertionError
和 org.openqa.selenium.TimeoutException
。我确定您必须使用 JUnit
或 TestNG
进行断言。第一步也是最重要的一步是交叉检查 Java
版本 & Junit
/TestNG
版本兼容性。最后,TimeoutException
迫使我交叉检查某个参数的可用性,该参数作为 Assertion
[=59 的输入参数传递=]/Validation
.
我们将 Selenium 用于我们的网站 UI 自动化测试。我们建立了一个实验室,有 10 台机器安装 Windows 7 作为唯一的 OS。并且自动化测试(>800)将每天平均分配给这些机器一次。但是,我们在不同的测试用例中间歇性地遇到以下超时错误。乍一看,这似乎是由于尝试加载和呈现页面时超时。但是,当我们手动打开该页面时,我们以前从未遇到过这种情况。
我通读了 google 组和本网站上的几篇帖子,但其中 none 为我的问题提供了解决方法。基本上,我正在寻找一种更好的方法来解决此超时异常,以找到明确的 RCA 并一劳永逸地修复它。我期待我们可以通过一些开关或详细日志。当然,也欢迎其他建议或解决方案。
以下是超时错误的详细信息。您可以在那里找到版本和环境信息。
java.lang.AssertionError: org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.93 seconds
Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38'
System info: host: 'v244023117ZzttZ', ip: '10.244.23.117', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 0dd88a079e79fe8da9cc950ebf07e535
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir3804_7174, chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, locationContextEnabled=true, mobileEmulationEnabled=false, version=61.0.3163.100, pageLoadStrategy=normal, takesHeapSnapshot=true, databaseEnabled=false, cssSelectorsEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:276)
at com.hhop.bbs.base.ATSWebDriver.open(ATSWebDriver.java:827)
at com.hhop.bbs.fancytest.channel.method.AbstractIPaymentMethod.renderCashier(AbstractIPaymentMethod.java:49)
at com.hhop.bbs.fancytest.channel.method.AbstractIPaymentMethod.doPayment(AbstractIPaymentMethod.java:84)
at com.hhop.bbs.fancytest.actions.channel.TradePaymentAction.fire(TradePaymentAction.java:42)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver.driver(DefaultProcessDriver.java:35)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$FastClassBySpringCGLIB$355ca6.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$EnhancerBySpringCGLIB$9c9f75.driver()
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.runFailFastMode(TestFlowEngine.java:85)
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.execute(TestFlowEngine.java:58)
at com.hhop.bbs.fancytest.actions.comm.AbstractParentFlowExecuteAction.executeParentFlow(AbstractParentFlowExecuteAction.java:44)
at com.hhop.bbs.fancytest.actions.channel.TradeRefundPrepareAction.prepareForParentFlow(TradeRefundPrepareAction.java:51)
at com.hhop.bbs.fancytest.actions.comm.AbstractParentFlowExecuteAction.fire(AbstractParentFlowExecuteAction.java:27)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver.driver(DefaultProcessDriver.java:35)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$FastClassBySpringCGLIB$355ca6.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at com.hhop.bbs.fancytest.testflow.DefaultProcessDriver$$EnhancerBySpringCGLIB$9c9f75.driver()
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.runFailFastMode(TestFlowEngine.java:85)
at com.hhop.bbs.fancytest.testflow.TestFlowEngine.execute(TestFlowEngine.java:58)
at com.hhop.bbs.fancytest.testflow.LinkTestBase.run(LinkTestBase.java:155)
at com.hhop.bbs.testcase.channel.TradeInSaleFxRefundTestGroup2.doRefund(TradeInSaleFxRefundTestGroup2.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:758)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access[=11=]0(SuiteRunner.java:37)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
:
祝福,
静飞
这类问题可能令人沮丧。以下是我在调试此类问题时尝试回答的几个问题:
- 超时异常是否发生在您代码中的同一点 每当你遇到这个,还是在不同的地方?
- 超时总是同一个动作,还是不同的动作?该代码可能正在尝试对尚不可见的元素执行操作。
- 相同的页面,还是不同的?
- 问题是在一天中的特定时间出现,还是在服务器上有其他活动会导致应用程序变慢时出现?
- 代码是否对页面的当前状态做出假设?如果是这样,您可能希望为您的自动化制定一条规则,即在对元素采取某些操作之前始终检查元素是否为 visible/clickable/enabled。如果这些假设是错误的,但未经检查,您最终会遇到令人困惑的失败。
我的自动化框架大量使用了 WebDriverWait,我尝试在达到超时的情况下包含有用的消息,帮助我隔离问题的根源
软件版本:
仔细查看日志会发现有关您的 Test Bed
的以下内容:
Selenium Version
: 2.39.0Chromedriver Version
: 2.33Chrome Version
: 61.0
我建议您将 Selenium Version
提高到 v3.6.0
,如 Selenium 3.x
相对于 Selenium 2.39.0
,很多功能已经 added/upgraded/deprecated。一旦您使用了最新版本,SO 志愿者就可以轻松进行调试。
错误分析:
仔细查看错误同时描述了 java.lang.AssertionError
和 org.openqa.selenium.TimeoutException
。我确定您必须使用 JUnit
或 TestNG
进行断言。第一步也是最重要的一步是交叉检查 Java
版本 & Junit
/TestNG
版本兼容性。最后,TimeoutException
迫使我交叉检查某个参数的可用性,该参数作为 Assertion
[=59 的输入参数传递=]/Validation
.