如何用 Cucumber 测试某个单词是否是链接?
我想要这个自定义步骤:
Then I should see the link 'foo'
和他的相反:
But I should not see the link 'foo'
在页面中我可以有类似的内容:
lorem foo bar
或者
lorem <a href=''>foo</a> bar
我需要测试何时“foo”是链接,何时不是。谢谢。
I would like this custom step:
Then I should see the link 'foo'
and his opposite:
But I should not see the link 'foo'
In the page I can have something like:
lorem foo bar
or alternatively
lorem <a href=''>foo</a> bar
I need to test when 'foo' is a link and when isn't. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
已经有预定义的
Webrat
步骤可以执行此操作(或者至少非常相似)。来自web_steps.rb
和
There are already pre-defined
Webrat
steps which do this (or are at least very similar). Fromweb_steps.rb
and
使用 xpaths 可能会更幸运,你可以使用类似“//a/text()='foo'”的东西。你只需要为 webrat 启用 xpaths,我写了一篇关于在表中使用 xpaths 做类似事情的博客文章 http://www.opsb.co.uk/?p=165,它包含为 webrat 启用 xpath 所需的代码。
You might have more luck using xpaths for this, you could use something like "//a/text()='foo'". You just need to enable xpaths for webrat, I wrote a blog post about doing something similar with xpaths in tables here http://www.opsb.co.uk/?p=165, it includes the code required to enable xpaths for webrat.
尝试这样的事情(我还没有尝试运行它,所以可能需要进行一些小的调整):
Try something like this (I haven't tried running it, so minor tweaks might be needed):