【问题标题】:Selenium test in Internet Explorer always times out?Internet Explorer 中的 Selenium 测试总是超时?
【发布时间】:2014-09-30 17:03:59
【问题描述】:

我正在尝试通过 Selenium-RC/PHPUnit 在 Internet Explorer 中运行一个基本测试,它总是返回

# phpunit c:\googletest.php
PHPUnit 3.4.15 by Sebastian Bergmann.

E

Time: 35 seconds, Memory: 4.75Mb

There was 1 error:

1) Example::testMyTestCase
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete()
.
Timed out after 30000ms.


C:\googletest.php:17

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

Paul@PAUL-TS-LAPTOP C:\xampp
#

命令历史中的最后一个命令是 waitForPageToLoad(30000)。相同的测试运行良好并在 Firefox 中完成。如何让这个测试在 Internet Explorer 中运行和完成?

谢谢

【问题讨论】:

  • 我们可以看看你的测试是什么样的吗?
  • 如果您在Vista上使用IE7及以上版本,请尝试将被测站点添加到受信任站点

标签: selenium selenium-rc


【解决方案1】:

在 selenium 中有一个开放的错误会导致 waitForPageToLoad 有时在 IE 上超时。

http://jira.openqa.org/browse/SRC-552

它在 IE6 上被标记为发生,但我至少在 IE9 上遇到了同样的错误。

解决方法是等待,例如正在加载的页面上的特定 DOM 元素,而不是使用 waitForPageToLoad。例如:waitForVisible('css=#header')

【讨论】:

    【解决方案2】:

    尝试进入 Internet 选项并关闭安全选项卡下的保护模式。您可能还想降低 Internet 区域的安全级别。

    【讨论】:

    • 还没有机会尝试这个,因为自从我提出这个问题后,我又接到了另一项任务。当我尝试过时会更新。谢谢
    【解决方案3】:

    我已关闭保护模式,看起来很有帮助。

    【讨论】:

      【解决方案4】:

      如果可以自定义客户端驱动程序,以下是 Python 实现供您参考:

      def open(self):
          timeout = self.get_eval('this.defaultTimeout')
          self.set_timeout(0)
          self.do_command("open", [url,ignoreResponseCode])
          self.set_timeout(timeout)
          self.wait_for_page_to_load(timeout)
      
      def wait_for_page_to_load(self,timeout):
          # self.do_command("waitForPageToLoad", [timeout,])
          import time
          end = time.time() + int(float(timeout) / 1000)
          while time.time() < end:
              if self.get_eval('window.document.readyState') == 'complete': return
              time.sleep(2)
          raise Exception('Time out after %sms' % timeout)
      

      我只是使用 DOM 属性document.readyState 来确定页面是否已完全加载。

      IE 9+ intermittently throws a timeout error even the page is fully loaded,了解更多详情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-14
        • 2011-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多