Created
November 16, 2012 10:06
-
-
Save jmoody/4086130 to your computer and use it in GitHub Desktop.
cucumber steps for testing rows in table view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# examples of usage | |
# Scenario: the activities home view should have the right stuff on it | |
# Then I should see navbar with title "Coping Skills" | |
# Then I scroll down until I see the "recommendation" row limit 1 | |
# Then I should see that the "recommendation" row has text "Recommendation" in the "title" label | |
# Then I should see that the "recommendation" row has text "custom selection based on your current needs" in the "details" label | |
# | |
# Then I scroll down until I see the "random" row limit 1 | |
# Then I should see that the "random" row has text "Random" in the "title" label | |
# Then I should see that the "random" row has text "random selection from all the skills" in the "details" label | |
# | |
# Then I scroll down until I see the "some other" row limit 1 | |
# Then I should see the rows in this order "lied, purged, skipped meals" | |
Then /^I should see "([^"]*)" in row (\d+)$/ do |cell_name, row| | |
res = query("tableViewCell index:#{row}", :accessibilityIdentifier).first | |
unless res.eql? cell_name | |
screenshot_and_raise "expected to see '#{cell_name}' in row #{row} but found '#{res}'" | |
end | |
end | |
Then /^I should see the rows in this order "([^"]*)"$/ do |row_ids| | |
tokens = row_ids.split(",") | |
counter = 0 | |
tokens.each do |token| | |
token.strip! | |
macro %Q|I should see "#{token}" in row #{counter}| | |
counter = counter + 1 | |
end | |
end | |
Then /^I scroll (left|right|up|down) until I see the "([^\"]*)" row limit (\d+)$/ do |dir, row_name, limit| | |
scroll_until_i_see_row dir, row_name, limit | |
end | |
def scroll_until_i_see_row (dir, row_id, limit) | |
unless row_exists? row_id | |
count = 0 | |
begin | |
scroll("scrollView index:0", dir) | |
sleep(STEP_PAUSE) | |
count = count + 1 | |
end while ((not row_exists?(row_id)) and count < limit.to_i) | |
end | |
unless row_exists?(row_id) | |
screenshot_and_raise "i scrolled '#{dir}' '#{limit}' times but did not see '#{row_id}'" | |
end | |
end | |
Then /^I should see that the "([^"]*)" row has text "([^"]*)" in the "([^"]*)" label$/ do |row_id, text, label_id| | |
should_see_row_with_label_with_text row_id, label_id, text | |
end | |
def should_see_row_with_label_with_text (row_id, label_id, text) | |
unless row_with_label_and_text_exists? row_id, label_id, text | |
actual = query("tableViewCell marked:'#{row_id}' child tableViewCellContentView child label marked:'#{label_id}'", :text).first | |
screenshot_and_raise "expected to see row '#{row_id}' with label '#{label_id}' that has text '#{text}', but found '#{actual}'" | |
end | |
end | |
def row_with_label_and_text_exists? (row_id, label_id, text) | |
arr = query("tableViewCell marked:'#{row_id}' child tableViewCellContentView child label marked:'#{label_id}'", :text) | |
(arr.length == 1) and (arr.first.eql? text) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment