我正在尝试登录 Java Web 应用程序。
登录页面具有以下 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 的新手,对 ruby 很陌生,现在我完全糊涂了。我不知道为什么 response.body 不见了。我不知道我在哪里。
我推测我必须等待页面请求,但所有文档都说 webrat 很好地等待所有重定向、页面加载等完成。(至少我认为我读过)。此外,我发现没有方法可以等待 webrat API 中的页面。
有人可以就如何进行调试提供一些提示吗?