diff --git a/gem/lib/frank-cucumber/core_frank_steps.rb b/gem/lib/frank-cucumber/core_frank_steps.rb index 6d6efa9..08d38ea 100644 --- a/gem/lib/frank-cucumber/core_frank_steps.rb +++ b/gem/lib/frank-cucumber/core_frank_steps.rb @@ -20,14 +20,14 @@ Then /^I should see a navigation bar titled "([^\"]*)"$/ do |expected_mark| quote = get_selector_quote(expected_mark) - check_element_exists( "navigationItemView marked:#{quote}#{expected_mark}#{quote}" ) + quoted_text = "#{quote}#{expected_mark}#{quote}" + navigation_title_exists_with_text("#{quoted_text}").should be_true, "expected to see a navigation bar titled #{quoted_text}" end -Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_mark| - quote = get_selector_quote(expected_mark) - wait_until( :message => "waited to see a navigation bar titled #{quote}#{expected_mark}#{quote}" ) { - element_exists( "navigationItemView marked:#{quote}#{expected_mark}#{quote}" ) - } +Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_title| + wait_until(message: "waited to see a navigation bar titled #{quoted_text}") do + navigation_title_with_text_exists(expected_title) + end end Then /^I wait to not see a navigation bar titled "([^\"]*)"$/ do |expected_mark| diff --git a/gem/lib/frank-cucumber/frank_helper.rb b/gem/lib/frank-cucumber/frank_helper.rb index 2c91374..433c503 100644 --- a/gem/lib/frank-cucumber/frank_helper.rb +++ b/gem/lib/frank-cucumber/frank_helper.rb @@ -155,6 +155,25 @@ def view_with_mark_exists(expected_mark) element_exists( "view marked:#{quote}#{expected_mark}#{quote}" ) end + # Indicate whether the title of the navigation bar matches the expected title. + # @param [String] expected_title the expected title of the navigation bar + # @return [Boolean] + def navigation_title_with_text_exists(expected_title) + quoted_text = "#{quote}#{expected_title}#{quote}" + + navFrame = frankly_map('view:"UINavigationBar"', 'frame').first + navCenter = navFrame["size"]["width"] / 2.0 + + frame = frankly_map("view:'UINavigationBar' view:'UINavigationItemView' marked:#{quoted_text}", 'frame').first + return false unless frame && frame["origin"] && frame["size"] + + left = frame["origin"]["x"] + right = frame["origin"]["x"] + frame["size"]["width"] + return false unless left && right && left < right + + (left < navCenter) && (navCenter < right) + end + # Assert whether there are any views in the current view heirarchy which contain the specified accessibility label. # @param [String] expected_mark the expected accessibility label # @raise an rspec exception if the assertion fails @@ -173,6 +192,26 @@ def check_view_with_mark_does_not_exist(expected_mark) check_element_does_not_exist( "view marked:#{quote}#{expected_mark}#{quote}" ) end + # Assert the title of the navigation bar. + # @param [String] expected_title the expected title of the navigation bar + # @raise an rspec exception if the assertion fails + # @raise an rspec exception if the navigation bar and its subview `UINavigationItemView` cannot be found + # @raise an rspec exception if the `UINavigationItemView` does not cover the center x of the navigation bar + def check_navigation_title_with_text_exists(expected_title) + quoted_text = "#{quote}#{expected_title}#{quote}" + + navFrame = frankly_map('view:"UINavigationBar"', 'frame').first + navCenter = navFrame["size"]["width"] / 2.0 + + frame = frankly_map("view:'UINavigationBar' view:'UINavigationItemView' marked:#{quoted_text}", 'frame').first + raise "Could not find navigation bar with title (#{expected_title})" unless frame && frame["origin"] && frame["size"] + + left = frame["origin"]["x"] + right = frame["origin"]["x"] + frame["size"]["width"] + raise "Expected title (#{expected_title}) not in center of navigation bar" unless left && right && left < right + + ((left < navCenter) && (navCenter < right)).should be_true, "Could not find navigation title in center of navigation bar matching text (#{expected_title})" + end # Waits for any of the specified selectors to match a view. #