下面是一个例子,我进入一个容器并将所有链接拉出来看到点击,导航到页面,然后声明页面标题,网址和面包屑都包含在链接内的文本容器。你可以添加一个if语句来评估一个链接是否有特定的文本,如果有的话,点击它。
从LIB文件
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
从规范文件(这是不使用一套黄瓜,但代码仍然是类似的)
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
为什么'@ dessert'包括本身? – tadman