0
我需要找到天气没有跟随链接存在于外部电子邮件,它不应该在任何内部电子邮件。Rails的测试,如果一个元素的属性存在或不
test "should have nofollow in external links and not in internal links in comment" do
visit @game_path
fill_in('comment_comment', :with => 'Please click link <a href='http://www.internallink.com/soccer'> internal link <a/> and click external link <a href='http://www.google.com'> external link <a/>
click_button('submit_comment')
assert page.has_no_css?('div.error'), "Error div found on page after posting comment"
assert page.has_content?('Please click link '), "Comment not found on page after posting"
ext = find(:xpath, "//a[@href='http://www.google.com']")
assert_equal(ext['rel'], "nofollow")
internal = find(:xpath, "//a[@href='http://www.internallink.com/soccer']")
assert_equal(internal.try(:rel), nil)
end
它在给出错误assert_equal(int.try(:rel), nil)
。 Anybuddy可以指导我解决问题吗?
我的最终目标是在用户评论进行测试,外部链接应该有相对=“nofollow的”属性存在或不?
什么是它给了错误? – dax
@dax错误是NoMethodError:未定义的方法'相对”为#<水豚::元素标记=‘A’> –
这可能有助于使事情变得更容易? http://samuelmullen.com/2011/12/use-capybara-add_selector-to-simplify-finding-link/ – dax