diff --git a/lib/motion/project/template/ios/spec-helpers/ui.rb b/lib/motion/project/template/ios/spec-helpers/ui.rb index a301bb18..f00cd321 100644 --- a/lib/motion/project/template/ios/spec-helpers/ui.rb +++ b/lib/motion/project/template/ios/spec-helpers/ui.rb @@ -288,12 +288,12 @@ module Bacon def view(label) return label if label.is_a?(UIView) - window.viewByName(label) || + UIApplication.sharedApplication.keyWindow.viewByName(label) || raise(Bacon::Error.new(:error, "Unable to find a view with label `#{label}'")) end def views(view_class) - views = window.viewsByClass(view_class) + views = UIApplication.sharedApplication.keyWindow.viewsByClass(view_class) if views.empty? raise(Bacon::Error.new(:error, "Unable to find any view of class `#{view_class.name}'")) end @@ -520,12 +520,6 @@ module Bacon [from, to] end - def _view(accessibilityLabel, error_message = nil) - return accessibilityLabel if accessibilityLabel.is_a?(UIView) - window.viewByName(accessibilityLabel) || - raise(Bacon::Error.new(:error, error_message || "Unable to find a view with label `#{accessibilityLabel}'")) - end - # This class wraps a block that will be executed on a GCD queue, but will # halt the main thread's call stack (while still handling the main thread's # runloop) until the block has completely finished its work. diff --git a/test/bacon-ui/spec/view_spec.rb b/test/bacon-ui/spec/view_spec.rb index 962cf8e7..40507fb9 100644 --- a/test/bacon-ui/spec/view_spec.rb +++ b/test/bacon-ui/spec/view_spec.rb @@ -99,7 +99,7 @@ describe "UIView extensions" do end end -describe "Bacon::Functional::API, concerning device events" do +describe "Bacon::Functional::API, concerning view helpers shortcuts" do tests SimpleViewController it "finds a view by its accessibility label" do @@ -120,6 +120,27 @@ describe "Bacon::Functional::API, concerning device events" do view(view).should == view end + it "finds a view on the current key window" do + begin + alert = UIAlertView.alloc.initWithTitle(nil, + message:'Overlapping all views', + delegate:nil, + cancelButtonTitle:'OK', + otherButtonTitles:nil) + alert.show + proper_wait(1) + + alertWindow = UIApplication.sharedApplication.keyWindow + alertWindow.should.not == @window + + view('OK').window.should == alertWindow + views(UIView).first.window.should == alertWindow + + ensure + alert.dismissWithClickedButtonIndex(0, animated:false) + end + end + it "raises if no view by label could be found after the `timeout` passes" do start = Time.now.to_i e = catch_bacon_error { view('Does not exist') }