这是一个示例,我进入容器并拉出所有链接以查看点击,导航到页面,然后断言页面标题、url 和面包屑都包含容器内链接中的文本。您可以添加一个 if 语句来评估链接是否包含特定文本,如果有,请单击它。
从库文件
def pull_text_and_href_from_continent_link
@continents.each do |continent|
find(".continents li.#{continent}").hover
page.should have_selector(".#{continent} .continent-wrapper", :visible => true)
page.all(:css, '.continents .continent-wrapper a').each do |nav_link|
@array.push(:text => nav_link.native.attribute("text"), :href => nav_link[:href])
end
end
end
来自规范文件(这是一个不使用 cuke 的套件,但代码仍然相似)
it "should have the right page title, url, and breadcrumbs" do
@array.each do |info|
if info[:text].include?('See all')
pp "Skipping the see all link for this container"
else
visit_page_logged_out(info[:href])
assert_correct_page_url info[:href]
assert_country_breadcrumbs remove_specials(info[:text])
assert_page_title info[:text]
end
end