Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check if menu option selected
- Then /^"(.*)" should be selected in the "(.*)" menu$/ do |opt,menu|
- html = Nokogiri::HTML(page.body)
- menu_id = if !html.xpath("//select[@id='#{menu}']").empty? then menu else html.xpath("//label[contains(text(),'#{menu}')]").first['for'] end
- html.xpath("//select[@id='#{menu_id}']/option[contains(text(),'#{opt}')]").first['selected'].should_not be_blank
- end
- # Variant for dates
- Then /^"(.*)" should be selected as the "(.*)" date$/ do |date,menu|
- date = Time.parse(date)
- html = Nokogiri::HTML(page.body)
- menu_id = html.xpath("//label[contains(text(),'#{menu}')]").first['for']
- year, month, day =
- html.xpath("//select[@id='#{menu_id}_1i']").empty? ? %w[year month day] : %w[1i 2i 3i]
- Then %Q{"#{date.year}" should be selected in the "#{menu_id}_#{year}" menu}
- Then %Q{"#{Date::MONTHNAMES[date.month]}" should be selected in the "#{menu_id}_#{month}" menu}
- Then %Q{"#{date.day}" should be selected in the "#{menu_id}_#{day}" menu}
- end
- # 'should come before/should come after' for verifying orderings of things
- Then /^(.*):"(.*)" should come (before|after) (.*):"(.*)" within "(.*)"$/ do |tag1,val1,order,tag2,val2,sel|
- html = Nokogiri::HTML(page.body)
- elt1 = html.xpath("//#{sel}//#{tag1}[contains(.,'#{val1}')]").first
- elt2 = html.xpath("//#{sel}//#{tag2}[contains(.,'#{val2}')]").first
- sequence = (elt1 <=> elt2)
- if order =~ /before/
- assert sequence == -1
- else
- assert sequence == 1
- end
- end
- # tabular data
- Then /^I should see a row "(.*)" within "(.*)"$/ do |row, table|
- page.should have_css(table)
- @html = Nokogiri::HTML(page.body)
- @rows = @html.xpath("//#{table}//tr").collect { |r| r.xpath('.//th|td') }
- col_regexps = row.split('|').map { |s| Regexp.new(s) }
- @rows.any? do |table_row|
- match = true
- col_regexps.each_with_index do |regexp,index|
- match &&= table_row[index].content.match(regexp)
- end
- match
- end.should be_true, "Expected #{table} to contain a row matching <#{row}>"
- end
- Then /^I should see a table "(.*)" with rows? (.*)$/ do |table,all_rows|
- page.should have_css(table)
- all_rows.split(/, ?/).each do |row|
- Then "I should see a row #{row} within \"#{table}\""
- end
- end
- Then /^I should see a quantity menu for "([^\"]*)"$/ do |name|
- vtype = Vouchertype.find_by_name(name)
- page.should have_css("select.itemQty[name='vouchertype[#{vtype.id}]']")
- end
- Then /^the "([^\"]*)" menu should contain "([^\"]*)"$/ do |menu,choice|
- page.should(have_css("select[id=#{menu}]") || have_css("select[name=#{menu}]")) do |m|
- m.should have_css("option", :content => choice)
- end
- end
- Then /^I should see the "(.*)" message$/ do |m|
- page.should(have_css("div##{m}") || have_css("div.#{m}"))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement