水豚 selenium 和 JavaScript Destroy
我正在使用 Rails 2.3.5,这就是我所做的。我安装了最新的黄瓜、黄瓜导轨和水豚。
rails demo
cd demo
ruby script/generate cucumber --rspec --capybara
ruby script/generate feature post title:string body:text published:boolean
ruby script/generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber
所有测试都通过了。现在我想使用 Javascript 进行测试。
情况
Scenario: Delete post
Given the following posts:
|title|body|published|
|title 1|body 1|false|
|title 2|body 2|true|
|title 3|body 3|false|
|title 4|body 4|true|
When I delete the 3rd post
Then I should see the following posts:
|Title|Body|Published|
|title 1|body 1|false|
|title 2|body 2|true|
|title 4|body 4|true|
此时,这就是我在顶部添加@javascript 的
。现在,当我运行 rake cucumber 时,我会看到一个确认页面。但在我点击之前什么也没有发生。
我需要做什么才能自动单击“确定”并继续进行测试。
I am using rails 2.3.5 and this is what I did. I have latest cucumber, cucumber-rails and capybara installed.
rails demo
cd demo
ruby script/generate cucumber --rspec --capybara
ruby script/generate feature post title:string body:text published:boolean
ruby script/generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber
All the tests are passing. Now I want to test using Javascript.
At this time this is how scenario looks like
Scenario: Delete post
Given the following posts:
|title|body|published|
|title 1|body 1|false|
|title 2|body 2|true|
|title 3|body 3|false|
|title 4|body 4|true|
When I delete the 3rd post
Then I should see the following posts:
|Title|Body|Published|
|title 1|body 1|false|
|title 2|body 2|true|
|title 4|body 4|true|
I added @javascript at the top.
Now when I run rake cucumber then I see a confirmation page. But nothing happens until I click.
What do I need to do so that OK is clicked automatically and test proceeds ahead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,这是一种黑客攻击,但我认为现在这是唯一的方法:
您必须将此步骤放在触发确认弹出窗口的步骤之前(点击链接)。它将修改标准警报并确认行为以始终返回 true。因此您不必自己单击“确定”按钮。
Well its kind of a hack, but I think right now its the only way:
You have to put this step right in front of the one that triggers the confirm popup (follows the link). It will modify the standard alert and confirm behaviour to always return true. So you do not have to click the "OK" button yourself.
我对托比亚斯的解决方案实施了一个变体。
我想要像
当我点击客户“Alice Angry”的“删除”链接时
这样的步骤,所以我有以下内容:完整的解释可以在我在这里写的博客文章中找到< a href="http://davidsulc.com/blog/2011/07/10/cucumber-tweaks/" rel="nofollow">http://davidsulc.com/blog/2011/07/10/cucumber-tweaks / (包括用于测试 HTML 容器中内容的有用步骤定义)。
I've implemented a variation on Tobias's solution.
I wanted to have steps like
When I follow the "Delete" link for customer "Alice Angry"
, so I have the following:The full explanation can be found in the blog post I wrote about it here http://davidsulc.com/blog/2011/07/10/cucumber-tweaks/ (including a helpful step definition for testing content within HTML containers).
感谢史蒂文提供的解决方案,以下是我对其进行修改的方法,使其读起来更好一些:
Thanks to Steven for his solution, here's how I modified it so that it reads a little better: