如何验证链接指向正确的图像并具有正确的目标和标题
我在 Rails 2.3.9 应用程序中使用水豚和黄瓜。
这是我的 html 代码
<a href="http://twitter.com/dorelal" target="_blank" title="twitter">
<img alt="twitter" src="/images/social/twitter.png?1284129939" />
</a>
我想验证以下项目
image should be ending with twitter.png
image alt should be "twitter"
link should have href "http://twitter.com/dorelal"
link should have target "_blank"
link should have title "twitter"
I am using capybara with cucumber in rails 2.3.9 application.
Here is my html code
<a href="http://twitter.com/dorelal" target="_blank" title="twitter">
<img alt="twitter" src="/images/social/twitter.png?1284129939" />
</a>
I want to verify following items
image should be ending with twitter.png
image alt should be "twitter"
link should have href "http://twitter.com/dorelal"
link should have target "_blank"
link should have title "twitter"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Capybara 现在支持检查 href 的功能。
https://github.com/jnicklas/capybara/pull/207
Capybara now supports the ability to check for href.
https://github.com/jnicklas/capybara/pull/207
验证链接的最佳方法是让您的驱动程序单击它,然后检查它是否到达正确的页面。这将使您更有信心您的应用程序不会错误地出错、重定向等。对于不明智地单击测试中的链接的特殊情况(例如:如果链接不在现场),我使用此步骤:
如果如果您收到“参数数量错误(2 为 1)”,请更新您的 Capybara 版本。 :href =>最近添加了“bar”选项。
The best way to verify a link is to have your driver click it and then check that it made it to the right page. That will give you more confidence that your app isn't incorrectly erroring, redirecting, etc. For the exceptional cases where clicking the link in a test is ill-advised (ex: if the link goes offsite), I use this step:
If you get "wrong number of arguments (2 for 1)", update your Capybara version. The :href => 'bar' option was added recently.