当你在cucumber下使用WebRat点击按钮时会发生什么

发布于 2024-09-03 05:06:48 字数 4105 浏览 6 评论 0原文

我正在尝试登录 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 中找不到等待页面的方法。

有人可以提供一些关于如何进行调试的提示吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2024-09-10 05:06:48

我使用本机 ruby​​ 确认了该行为,以排除任何 jruby 或 JVM 相关问题。

我重新配置了 webrat 以使用 Selenium,这样我就可以看到发生了什么。

发生的事情是登录后出现 302 重定向。 selenium 实现遵循重定向,但 mechanize 实现则不然。所以我正在解释重定向消息的正文,它当然是空的。

因此,我通过明确访问我期望重定向的页面来伪造重定向,结果发现:它有效!

I confirmed the behaviour using native ruby to exclude any jruby or JVM related issues.

I reconfigured webrat to use Selenium so I could see what was happening.

What happened was that after login there is a 302 redirect. The selenium implementation is following the redirect, but the mechanize implementation does not. So I was interpreting the body of the redirect message which is of course empty.

So I faked the redirect by exlipcitely visit-ing the page where I expect to be redirect and lo-and-behold : it works!.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文