1
我正在尝试登录到Java Web应用程序。使用WebRat在黄瓜下单击按钮会发生什么
登录页面具有以下HTML:
<html>
<head><title>Login Page</title></head>
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password</h3>
<form name='f' action='/ui/j_spring_security_check' method='POST'>
<table>
<tr><td>User:</td><td><input type='text' name='j_username' value=''></td></tr>
<tr><td>Password:</td><td><input type='password' name='j_password'/></td></tr>
<tr>
<td><input type='checkbox' name='_spring_security_remember_me'/> </td>
<td>Remember me on this computer.</td>
</tr>
<tr><td colspan='2'><input name="submit" type="submit"/></td></tr>
<tr><td colspan='2'><input name="reset" type="reset"/></td></tr>
</table>
</form>
</body>
</html>
我使用下面的脚本:
Given /^I am logged in as (.*) with password (.*)$/ do | user, password |
visit "http://localhost:8080/ui"
click_link "Projects"
puts "Response Body:"
puts response.body
assert_contain "User:"
fill_in "j_username", :with => user
fill_in "j_password", :with => password
puts "Response Body:"
puts response.body
click_button
puts "Response Body:"
puts response.body
end
这给在日志文件中的以下内容:
[INFO] Response Body:
[INFO] <html><head><title>Login Page</title></head><body onload='document.f.j_username.focus();'>
[INFO] <h3>Login with Username and Password</h3><form name='f' action='/ui/j_spring_security_check' method='POST'>
[INFO] <table>
[INFO] <tr><td>User:</td><td><input type='text' name='j_username' value=''></td></tr>
[INFO] <tr><td>Password:</td><td><input type='password' name='j_password'/></td></tr>
[INFO] <tr><td><input type='checkbox' name='_spring_security_remember_me'/></td><td>Remember me on this computer.</td></tr>
[INFO] <tr><td colspan='2'><input name="submit" type="submit"/></td></tr>
[INFO] <tr><td colspan='2'><input name="reset" type="reset"/></td></tr>
[INFO] </table>
[INFO] </form></body></html>
[INFO] Response Body:
[INFO] <html><head><title>Login Page</title></head><body onload='document.f.j_username.focus();'>
[INFO] <h3>Login with Username and Password</h3><form name='f' action='/ui/j_spring_security_check' method='POST'>
[INFO] <table>
[INFO] <tr><td>User:</td><td><input type='text' name='j_username' value=''></td></tr>
[INFO] <tr><td>Password:</td><td><input type='password' name='j_password'/></td></tr>
[INFO] <tr><td><input type='checkbox' name='_spring_security_remember_me'/></td><td>Remember me on this computer.</td></tr>
[INFO] <tr><td colspan='2'><input name="submit" type="submit"/></td></tr>
[INFO] <tr><td colspan='2'><input name="reset" type="reset"/></td></tr>
[INFO] </table>
[INFO] </form></body></html>
[INFO] Response Body:
[INFO]
[INFO] Given I am logged in as pti with password ptipti # features/step_definitions/authentication_tests.rb:2
因此很明显,单击提交按钮后,response.body消失。我可以从服务器日志文件中看到该脚本没有到达项目页面。
我是新来的webrat和相当新的红宝石,我现在彻底困惑。我不知道为什么response.body不见了。我不知道我在哪里。
我推测我不得不等待页面请求,但所有文档都说webrat很好地等待,直到所有重定向,页面加载等完成。 (至少我认为我读过)。除此之外,我发现没有办法在webrat API中等待页面。
有人可以提供一些关于如何进行调试的提示吗?
似乎你在表单上同时具有“提交”和“重置”按钮。也许Webrat对于推动哪个按钮感到困惑? – zetetic 2010-05-28 18:30:32
是的,但是,这只会重置字段的值到原始值...我很难过....我会让周末做它的工作,并在周一重新访问它。 – 2010-05-28 23:51:42