PHPUnit Selenium2无法在测试中找到标记

时间:2014-12-28 04:41:43

标签: php selenium-webdriver phpunit

我正在使用PHPUnit(3.7.38),Selenium2(2.43.1-standalone)和Firefox(34.0)测试网站,并继续遇到Selenium无法找到标签的间歇性问题在页面上。如果我截取错误的屏幕截图,标签和内容就在那里,页面看起来好像是完全加载的。关于我试图加载的标签上确实没有AJAX可以说明问题。

这似乎发生在大约50%的时间和一些特定的测试中。同样,它似乎倾向于测试的特定行,但如果我注释掉有问题的行,通常会更改行。如果我在测试之间等待几分钟,它似乎没有错误地运行,但除此之外我找不到任何影响它的东西。

具体例外是:

PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Unable to locate element: {"method":"tag name","selector":"h2"}

Selenium Trace:

22:32:34.544 INFO - Executing: [find element: By.tagName: h2])
22:32:35.704 WARN - Exception thrown org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"tag name","selector":"h2"}
Command duration or timeout: 220 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'andrew-xubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-43-generic', java.version: '1.7.0_65'
Session ID: e842f08c-176e-4361-859b-8fc8e67b8d5c
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=34.0}]
    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:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByTagName(RemoteWebDriver.java:417)
    at org.openqa.selenium.By$ByTagName.findElement(By.java:330)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
    at com.sun.proxy.$Proxy1.findElement(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:184)
    at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:47)
    at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
    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)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"tag name","selector":"h2"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'andrew-xubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch:  'amd64', os.version: '3.13.0-43-generic', java.version: '1.7.0_65'
Driver info: driver.version: unknown
    at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///tmp   /anonymous8627931668853884881webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9618:26)
    at <anonymous class>.FirefoxDriver.prototype.findElement(file:///tmp/anonymous8627931668853884881webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9627:3)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///tmp/anonymous8627931668853884881webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:11612:16)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///tmp/anonymous8627931668853884881webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:11617:7)
    at <anonymous class>.DelayedCommand.prototype.execute/<(file:///tmp/anonymous8627931668853884881webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:11559:5)
22:32:35.706 WARN - Exception: Unable to locate element: {"method":"tag name","selector":"h2"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'andrew-xubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-43-generic', java.version: '1.7.0_65'
Driver info: driver.version: unknown`

1 个答案:

答案 0 :(得分:0)

看起来像是在增加Selenium等待修复元素的时间。将此代码添加到每个测试中会增加Selenium每次加载页面的时间。

function setUpPage() {
        $this->timeouts ()->implicitWait ( 3000 );
}