Skip to content

Instantly share code, notes, and snippets.

@lenny
Created December 30, 2009 17:31
Show Gist options
  • Save lenny/266218 to your computer and use it in GitHub Desktop.
Save lenny/266218 to your computer and use it in GitHub Desktop.
When I select the following previous correspondence items:
| type | date | filename |
| CTA | 01Jan09 | EMAIL |
When /^I select the following previous correspondence items:$/ do |table|
checkboxes = PreviousCorrespondenceSteps.get_checkboxes_for(table)
checkboxes.each {|b| b.set(true) }
end
class PreviousCorrespondenceSteps
extend Capybara
def self.get_checkboxes_for(table)
raise "unsupported criteria" unless (table.headers - %w(type date note filename)).empty?
checkboxes = []
table.hashes.each do |criteria|
row = all("//*[@id='prev-corr-selection-table']//tr").find do |tr|
if type = criteria['type']
next unless tr.find('//td', :text => /\b#{type}\b/)
end
if date = criteria['date']
next unless tr.find(:text => date)
end
if note = criteria['note']
next unless tr.find(:text =>/#{note}/)
end
true
end
raise "#{criteria.inspect} not found" unless row
checkboxes << row.find("//*[contains(@class, 'file-item')]//input[@type='checkbox']")
end
checkboxes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment