【发布时间】:2011-03-21 12:49:31
【问题描述】:
在 selenium 测试中,我打开了一个我无权访问的页面,我想验证显示的是错误页面而不是打开的页面。
检查这是否是错误页面很简单:
Assert.assertTrue(selenium.isTextPresent("HTTP Status 403"));
现在我通过web.xml 中的<error-page> 标记将默认JBoss 错误页面更改为自定义页面。在此之后,硒不起作用。它从isTextPresent() 抛出异常。当然页面上的文字也发生了变化,但在这里没关系。
堆栈跟踪是:
com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: doc.style is undefined
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at pl.softwaremill.common.test.web.selenium.screenshots.ScreenshotHttpCommandProcessor.doCommand(ScreenshotHttpCommandProcessor.java:31)
at com.thoughtworks.selenium.DefaultSelenium.captureEntirePageScreenshot(DefaultSelenium.java:679)
at pl.softwaremill.common.test.web.selenium.AbstractSeleniumTest.captureScreenshot(AbstractSeleniumTest.java:166)
at pl.softwaremill.common.test.web.selenium.AbstractSeleniumTest$1.doScreenshot(AbstractSeleniumTest.java:95)
... 27 more
com.thoughtworks.selenium.SeleniumException: ERROR: Couldn't access document.body. Is this HTML page fully loaded?
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
at com.thoughtworks.selenium.HttpCommandProcessor.getBoolean(HttpCommandProcessor.java:335)
at pl.softwaremill.common.test.web.selenium.screenshots.ScreenshotHttpCommandProcessor.getBoolean(ScreenshotHttpCommandProcessor.java:92)
at com.thoughtworks.selenium.DefaultSelenium.isTextPresent(DefaultSelenium.java:499)
at za.co.fnb.commercial.dms.uitests.view.debtor.DebtorInsuranceAnnexurePage.<init>(DebtorInsuranceAnnexurePage.java:18)
at za.co.fnb.commercial.dms.uitests.view.debtor.UploadDebtorFilesPage.submit(UploadDebtorFilesPage.java:45)
at za.co.fnb.commercial.dms.uitests.view.debtor.UploadDebtorFilesSeleniumTest.shouldStoreFileEvenIfParseFails(UploadDebtorFilesSeleniumTest.java:145)
pl.softwaremill.common.test.web.selenium.screenshots.ScreenshotHttpCommandProcessor 只是将工作委托给com.thoughtworks.selenium.HttpCommandProcessor
因为错误消息显示“此 HTML 页面是否已完全加载?”你可以认为页面没有完全加载,但确实如此。我在debug中试了一下,给了一些时间让页面加载,也加载了,但是还是出现这个错误。
【问题讨论】:
-
不知道...有趣的部分是“doc.style 未定义”。要检查的事情:自定义错误页面是否有效 html 并因此被浏览器解析?您使用哪种浏览器进行测试?在 firefox 中,firebug 会告诉你关于 doc.style 的什么信息?莫里茨
-
页面是有效的 HTML,它在 Chrome 和 Firefox 中是可解析的(可见的)。 doc 未定义,但在每一页上都是相同的。我试过 document.style - 它也是未定义的,也在“普通”页面上。
标签: web-applications jboss selenium integration-testing