jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

Window#new with valid :hwnd always succeeds, regardless of other locators #1

Closed BurdetteLamar closed 13 years ago

BurdetteLamar commented 13 years ago

A call to method Window#new whose locators include a valid :hwnd always finds the window with the given hwnd, even if none of the other locators given match that window.

From the doc: "Use multiple locators, every locator will be matched (AND-ed) to the window."

Here's a test that produces the behavior by calling with a valid :hwnd, and with all other locators not matching the window. The assertion fails.

require 'test/unit' require 'rubygems' require 'rautomation'

class BugDemo < Test::Unit::TestCase

def setup thread = Thread.new { calc.exe } Thread.pass sleep 1 @@calculator_window = RAutomation::Window.new(:title => 'Calculator') end

def teardown @@calculator_window.close end

def test_bug_demo

This window should not be found,

# because all locators are invalid except :hwnd.
locators = {
  :class => 'NoSuch',
  :hwnd  => @@calculator_window.hwnd,
  :index => 1000000,
  :pid   => 1 + @@calculator_window.pid,
  :text  => 'NoSuch',
  :title => 'NoSuch'
}
window = RAutomation::Window.new(locators)
assert(!window.exists?, 'Window does not exist')

end

end

jarmo commented 13 years ago

To be honest, this is actually as it is meant to work since hwnd is unique. Due to that reason there's no point to even look at other locators if handle is specified. I guess this should be brought out better in the documentation...

BurdetteLamar commented 13 years ago

Possible language: If locator :hwnd is included, any other locators given are ignored; the window is found or not based only on the :hwnd locator.

jarmo commented 13 years ago

Used a slightly different wording - https://github.com/jarmo/RAutomation/commit/f1fb34e7c192147dd777332855aefcfce5d3bbc7