【问题标题】:How to troubleshoot intermittent org.openqa.selenium.TimeoutException: timeout如何解决间歇性 org.openqa.selenium.TimeoutException:超时
【发布时间】:2017-11-02 03:38:14
【问题描述】:

我们利用 Selenium 进行网站 UI 自动化测试。我们建立了一个由 10 台机器组成的实验室,安装了 Windows 7 作为唯一的操作系统。自动化测试 (>800) 将每天平均分配给这些机器一次。但是,我们在不同的测试用例中间歇性地遇到以下超时错误。乍一看,似乎是由于尝试加载和呈现页面时超时。但是,当我们手动打开该页面时,我们从未体验过这种情况。

我阅读了 google 组和这个网站上的几篇帖子,但没有一篇为我的问题提供解决方法。基本上,我正在寻找一种更好的方法来解决这个超时异常,以找到明确的 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$$11355ca6.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$$429c9f75.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$$11355ca6.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$$429c9f75.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$000(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)
: 

祝福,

精飞

【问题讨论】:

  • 你是如何设置实验室的?你用的是酱实验室还是网格?据我了解,它无法找到某些页面元素。这可能会发生,因为它要么试图在加载这些元素之前找到这些元素,要么其他可能的原因是连接速度慢。您是否尝试添加等待和 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id())); 来检索元素?

标签: selenium selenium-webdriver selenium-chromedriver timeoutexception


【解决方案1】:

软件版本:

仔细查看日志可以发现以下关于您的 Test Bed 的信息:

  1. Selenium Version:2.39.0
  2. Chromedriver Version:2.33
  3. Chrome Version : 61.0

我建议您将Selenium Version 升级为 v3.6.0,如 Selenium 3.x 中的许多功能已添加/升级​​/弃用Selenium 2.39.0。使用最新版本后,对于 SO 志愿者来说,调试变得很容易。

错误分析:

仔细查看错误同时描述了 java.lang.AssertionErrororg.openqa.selenium.TimeoutException。我确定您必须使用 JUnitTestNG 进行断言。第一步也是最重要的一步是交叉检查 Java 版本和 Junit/TestNG 版本兼容性。最后,TimeoutException 迫使我交叉检查某个参数的可用性,该参数作为输入参数传递给 Assertion/Validation

【讨论】:

  • 请问如何升级Selenium的版本?绑定到chromedriver吗?
  • 很好 @DebanjanB,我同意升级到 Selenium 3 可能会有所作为。 machinarium,要升级,你需要下载新版本并从seleniumhq.org/download安装它
【解决方案2】:

这类问题可能令人沮丧。以下是我在调试此类问题时尝试回答的几个问题:

  • 超时异常是否发生在您的代码中的同一点 每当你遇到这个,还是在不同的地方?
  • 总是相同的操作超时,还是不同的操作?代码可能正在尝试对尚不可见的元素执行操作。
  • 相同的页面,还是不同的页面?
  • 问题是发生在一天中的特定时间,还是发生在服务器上的其他活动会导致应用程序变慢时?
  • 代码是否对页面的当前状态做出假设?如果是这样,您可能希望为您的自动化制定一条规则,即始终检查元素是否可见/可点击/启用,然后再对它们执行一些操作。如果这些假设是错误的,但未经检查,您最终会遇到令人困惑的失败。

我的自动化框架广泛使用了 WebDriverWait,并且我尝试在达到超时的情况下包含有用的消息,帮助我找出问题的根源

【讨论】:

  • 对您的建议的回答: 1. 超时异常不会发生在同一个地方,而是在尝试打开我们的收银页面相同的 url 时跨越不同的类 2. >99% 是超时异常,很少发生它是“没有会话 xxx”(不记得确切的错误消息) 3. 相同的页面,不幸的是也许幸运 4. 没有时间模式发生的事件,每当发送案例时,机器都是专用的,所以我不认为存在这样的争论 5. 不,我们只是尝试打开它但失败了。调用 RemoteWebDriver.get(url) 失败
猜你喜欢
  • 2011-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-22
  • 2017-10-31
  • 1970-01-01
  • 2010-10-05
相关资源
最近更新 更多