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