jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

Window#button sometimes (but consistently) fails to find a button. #4

Closed BurdetteLamar closed 12 years ago

BurdetteLamar commented 13 years ago

Window#button sometimes (but consistently) fails to find a button.

Here's some code that I've isolated and adapted from the suites I've been building to test RAutomation. It should run if placed in a file in directory spec. It's worth noting that the button was found for each of the single-valued locators, so we can (safely?) assume that the locator values are correct (for my machine).

Though this test does not demonstrate it, I saw no difference when :id and :index were given as strings rather than as integers.

require 'rautomation'
require 'rspec'

RSpec.configure do |config|

  config.before(:all) do
    @pid = IO.popen('calc.exe').pid
    RAutomation::WaitHelper.wait_until {RAutomation::Window.new(:pid => @pid).present?}
  end

  config.after(:all) do
    Process.kill(9, @pid) rescue nil
  end

end

describe RAutomation::Button do

  # Calculator button '1'.
  # These values could conceivably vary among versions of Calculator.
  klass = 'Button'
  id = 125
  index = 6
  value = '1'

  locators = [
    {},
    {:class => klass},
    {:id => id},
    {:index => index},
    {:value => value},
    {:class => klass, :id => id},
    {:class => klass, :index => index},
    {:class => klass, :value => value},
    {:id => id, :index => index},
    {:id => id, :value => value},
    {:index => index, :value => value},
    {:class => klass, :id => id, :index => index},
    {:class => klass, :id => id, :value => value},
    {:class => klass, :index => index, :value => value},
    {:id => id, :index => index, :value => value},
    {:class => klass, :id => id, :index => index, :value => value},
  ]

  locators.each do |locator|
    it "#button for locator #{locator.inspect}" do
      window = RAutomation::Window.new(:title => 'Calculator')
      button = window.button(locator)
      button.should exist
    end
  end

end

The result varies by adapter:

$ RAUTOMATION_ADAPTER=autoit rspec button_bug.rb
..........F..F..

Failures:

  1) RAutomation::Button #button for locator {:index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, 

@autoit_locators="[title:Calculator]">, @locators={:index=>6, :value=>"1"}, @button=#"Calculator"}, @autoit_locators="[title:Calculator]">, 

@locators={:class=>/button/i, :index=>6, :value=>"1"}, @autoit_locators="[regexpclass:(?i-mx:button);instance:7;text:1]">> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  2) RAutomation::Button #button for locator {:class=>"Button", :index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, 

@autoit_locators="[title:Calculator]">, @locators={:class=>"Button", :index=>6, :value=>"1"}, @button=#"Calculator"}, @autoit_locators="[title:Calculator]">, 

@locators={:class=>"Button", :index=>6, :value=>"1"}, @autoit_locators="[class:Button;instance:7;text:1]">> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

Finished in 1.08 seconds
16 examples, 2 failures
$ RAUTOMATION_ADAPTER=win_ffi rspec button_bug.rb
........F.FF.FFF

Failures:

  1) RAutomation::Button #button for locator {:id=>125, :index=>6}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:id=>125, :index=>6}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>/button/i, :id=>125, :index=>6}>> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  2) RAutomation::Button #button for locator {:index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:index=>6, :value=>"1"}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>/button/i, :index=>6, :value=>"1"}>> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  3) RAutomation::Button #button for locator {:class=>"Button", :id=>125, :index=>6}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:class=>"Button", :id=>125, :index=>6}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>"Button", :id=>125, :index=>6}>> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  4) RAutomation::Button #button for locator {:class=>"Button", :index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:class=>"Button", :index=>6, :value=>"1"}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>"Button", :index=>6, :value=>"1"}>> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  5) RAutomation::Button #button for locator {:id=>125, :index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:id=>125, :index=>6, :value=>"1"}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>/button/i, :id=>125, :index=>6, :value=>"1"}>> to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

  6) RAutomation::Button #button for locator {:class=>"Button", :id=>125, :index=>6, :value=>"1"}
     Failure/Error: button.should exist
       expected #"Calculator"}, @hwnd=6882536>, 

@locators={:class=>"Button", :id=>125, :index=>6, :value=>"1"}, @button=#"Calculator"}, @hwnd=6882536>, @locators={:class=>"Button", :id=>125, :index=>6, :value=>"1"}>> 

to exist
     # ./button_bug.rb:49:in `block (3 levels) in '

Finished in 0.98438 seconds
16 examples, 6 failures
jarmo commented 12 years ago

I'm not sure what to do with that.

I'm having same 4 specs failing for me with both adapters:

button for locator {:value=>"1"} (FAILED - 1)

button for locator {:value=>"1", :class=>"Button"} (FAILED - 2)

button for locator {:value=>"1", :index=>6} (FAILED - 3)

button for locator {:value=>"1", :class=>"Button", :index=>6} (FAILED - 4)

What Windows are you using? In what mode is the calculator in (e.g. standard, scientific...)?

jarmo commented 12 years ago

Closing this because of no feedback from the reporter.