【发布时间】:2011-07-12 07:09:22
【问题描述】:
请帮忙。
我有页面 login/auth.gsp
在正文中使用以下代码
<div id="page-wrap">
<div class="login-block">
<g:if test="${flash.message}">
<h3 class='login_message'>${flash.message}</h3>
</g:if>
<g:else>
<h3>IMMS Login</h3>
</g:else>
<form action='${postUrl}' method='POST' id='loginForm' class='cssform' autocomplete='off'>
<p>
<label for='username'><g:message code="auth.username.label" default="User Name"/></label>
<input type='text' class='text_' name='j_username' id='username'/>
</p>
<p>
<label for='password'><g:message code="auth.password.label" default="Password"/></label>
<input type='password' class='text_' name='j_password' id='password'/>
</p>
<p class="submit-wrap">
<input type='submit' value="${message(code: 'default.button.Login.label', default: 'Login')}"/>
</p>
</form>
</div>
<div class="image-block"></div>
</div>
在 test/functional/pages 目录下,我有 LoginPage
package pages
import geb.Page
class LoginPage extends Page {
static url = "login/auth/"
static at = {
userName.text() == ""
}
static content = {
userName { $("input", name : "j_username") }
password { $("input", name : "j_password") }
loginButton(to: IndexPage){ $(".submit-wrap").find("input").first() }
}
}
这是我的测试代码
import geb.spock.GebReportingSpec
import pages.*
import spock.lang.Stepwise
@Stepwise
class BaseSpec extends GebReportingSpec {
String getBaseUrl() {
return "http://localhost:8080/IMMS/"
}
def "open URL"() {
when:
to LoginPage
then:
at LoginPage
}
}
我运行测试但失败了。这是报告
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="0" failures="1" hostname="SGCDMSSVR" name="BaseSpec" tests="1" time="24.715" timestamp="2011-07-12T07:00:04">
<properties />
<testcase classname="BaseSpec" name="open URL" time="24.693">
<failure message="Condition not satisfied:
at LoginPage
|
false
" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: Condition not satisfied:
at LoginPage
|
false
at BaseSpec.open URL(BaseSpec.groovy:18)
</failure>
</testcase>
<system-out><![CDATA[--Output from open URL--
]]></system-out>
<system-err><![CDATA[--Output from open URL--
]]></system-err>
</testsuite>
有什么想法可以帮助我吗?是我遗漏了一些配置还是我的类似 jQuery 的导航不正确?
对于测试,我使用的是“功能测试开发”插件。
更新: 最初我使用的 GebConfig 正是来自 The sample. 我刚刚注意到默认驱动程序是 HTMLUnit。
当我使用命令控制台中的Functional Test Development 功能运行功能测试时。
grails develop-functional-tests
我选择了运行所有功能测试的选项。控制台显示测试失败。
当我将默认驱动程序更改为 Firefox 时。 它仍然失败,但我可以看到它自动打开 Firefox 浏览器并打开 URL:
http://localhost:8080/IMMS/login/auth.gsp
并且它无法打开 404 的 URL。我认为这就是测试失败的原因。
我尝试从 IDE 运行以下命令。
grails test-app -functional
它可以工作,并且打开了 firefox 浏览器,它执行了编写的测试脚本并通过了测试。
所以,我在这里修改标题。现在的重点是 grails 的功能测试开发插件。 也许你们中的任何人曾经尝试过这个插件并有答案? 谢谢。
PS:我可以修改问题吗?还是我应该在 stackoverflow 中创建新问题?
【问题讨论】:
-
这里在黑暗中拍摄,但可以尝试删除
LoginPage的url属性中的尾部斜杠(login/auth而不是login/auth/)。我不明白为什么 Geb 会在末尾添加.gsp。