Permalink
Browse files

fix #click and button_spec to work as they worked originally

  • Loading branch information...
jarmo committed Jan 30, 2011
1 parent 36bbfa8 commit f006a1a396b18cd1d6febf5932b3ed2d5e60152a
Showing with 29 additions and 26 deletions.
  1. +1 −1 lib/rautomation/adapter/win_ffi/control.rb
  2. +26 −22 spec/button_spec.rb
  3. +2 −2 spec/spec_helper.rb
  4. +0 −1 spec/text_fields_spec.rb
@@ -30,7 +30,7 @@ def click
Functions.control_click(hwnd) &&
clicked = true # is clicked at least once
- block_given? ? yield : clicked && exists?
+ block_given? ? yield : clicked && !exists?
end
end
View
@@ -2,61 +2,65 @@
describe RAutomation::Button do
it "#button" do
- RAutomation::Window.new(:title => "MainFormWindow").
- button(:value => "&About").should exist
+ RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
+ button(:value => "Close").should exist
RAutomation::Window.wait_timeout = 0.1
expect {RAutomation::Window.new(:title => "non-existing-window").button(:value => "Something")}.
- to raise_exception(RAutomation::UnknownWindowException)
+ to raise_exception(RAutomation::UnknownWindowException)
end
it "#value" do
- RAutomation::Window.new(:title => "MainFormWindow").
- button(:value => "&About").value.should == "&About"
+ RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
+ button(:value => "Close").value.should == "Close"
RAutomation::Window.wait_timeout = 0.1
- expect {RAutomation::Window.new(:title => "MainFormWindow").button(:value => "non-existent-button").value}.
- to raise_exception(RAutomation::UnknownButtonException)
+ expect {RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).button(:value => "non-existent-button").value}.
+ to raise_exception(RAutomation::UnknownButtonException)
end
it "#exists?" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
- window.button(:value => "&About").should exist
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
+ window.button(:value => "Close").should exist
window.button(:value => "non-existent-button").should_not exist
end
it "clicking non-existing button raises exception" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
RAutomation::Window.wait_timeout = 0.1
expect {window.button(:value => "non-existent-button").click}.
- to raise_exception(RAutomation::UnknownButtonException)
+ to raise_exception(RAutomation::UnknownButtonException)
end
it "#click" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
- button = window.button(:value => "&About")
+ button = window.button(:value => "Close")
button.should exist
- button.click { |button| RAutomation::Window.new(:title => /About/i).exists? }
+ button.click
+
+ button.should_not exist
+ window.should_not exist
end
- it "#click with a block for defining successful click" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
+ it "#click with a block for defining successful click returning false raises a TimeoutError" do
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
RAutomation::Window.wait_timeout = 5
- button = window.button(:value => "not-there")
+ button = window.button(:value => "Close")
expect {button.click {false}}.
- to raise_exception(RAutomation::UnknownButtonException)
-# changed to UnknownButtonException due to:
-# expected RAutomation::WaitHelper::TimeoutError, got #<RAutomation::UnknownButtonException: Button {:value=>"not-there"} doesn't exist on window {:title=>"MainFormWindow"}!>
+ to raise_exception(RAutomation::WaitHelper::TimeoutError)
button.should_not exist
-# window.should_not exist
+ window.should_not exist
+ end
+ it "#click with a block for defining successful click returning true" do
RAutomation::Window.wait_timeout = 10
- window = RAutomation::Window.new(:title => "MainFormWindow")
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
button = window.button(:value => "Close")
button.should exist
button.click {|button| !button.exists? && !window.exists?}
+
button.should_not exist
window.should_not exist
end
View
@@ -10,7 +10,7 @@ def adapter
def navigate_to_simple_elements
main_window = RAutomation::Window.new(:title => "MainFormWindow")
- main_window.button(:title => "Simple Elements").click { RAutomation::Window.new(:title => "SimpleElementsForm").present? }
+ main_window.button(:value => "Simple Elements").click { RAutomation::Window.new(:title => "SimpleElementsForm").present? }
end
module_function :adapter, :navigate_to_simple_elements
@@ -48,7 +48,7 @@ def navigate_to_simple_elements
# Window 1 should have a text field with the specified class name.
:window1_text_field_class => "Edit",
# Adapter internal method invocation for getting title of window2
- :title_proc => lambda {|win| win.WinGetTitle("[TITLE:Explorer User Prompt]")}
+ :title_proc => lambda {|win| win.WinGetTitle("[TITLE:MainFormWindow]")}
},
:win_ffi => {
# Path to some binary, which opens up a window, what can be
View
@@ -2,7 +2,6 @@
describe RAutomation::TextFields do
-
it "Window#text_fields returns all text fields" do
SpecHelper::navigate_to_simple_elements

0 comments on commit f006a1a

Please sign in to comment.