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