What happens when you click a button using WebRat under cucumber
- by Peter Tillemans
I am trying to login to a Java web application.
The login page has the following 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>
I use the following script:
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
This gives the following in the log file :
[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
So apparently the response.body disappeared after clicking the submit button. I can see from the server log files that the script does not arrive on the Project page.
I am new to webrat and quite new to ruby and I am now thoroughly confused. I have no idea why the response.body is gone. I have no idea where I am.
I speculated that I had to wait for the page request, but all documentation says that webrat nicely waits till all redirects, pageloads, etc are finished. (At least I think I read that). Besides I find no method to wait for the page in the webrat API.
Can someone give some tips on how to proceed with debugging this?