jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

Window#pid for adapter :autoit returns empty string. #3

Closed BurdetteLamar closed 13 years ago

BurdetteLamar commented 13 years ago

Window#pid for adapter :autoit returns an empty string. For adapter :win_ffi, it returns an integet pid.

The code at adapter/autoit/window.rb is this:

  def pid
    @@autoit.WinGetProcess(hwnd)
  end

It would be better as:

  def pid
    @@autoit.WinGetProcess(title).to_i
  end

Here's a test that can be run in the spec directory:

  require 'spec_helper'

  describe RAutomation::Windows do

    [ :win_ffi, :autoit ].each do |adapter|
      title = SpecHelper::DATA[:window1_title]
      it "#pid with adapter=#{adapter} should return a positive integer" do
        window = RAutomation::Window.new(
          :adapter => adapter,
          :title => title
        )
        pid = window.pid
        puts "adapter=#{adapter} class=#{pid.class} value='#{pid}'"
        pid.should > 0
      end
    end

  end

Failing result on my machine:

adapter=win_ffi class=Fixnum value='2028'
.adapter=autoit class=String value=''
F

Failures:

  1) RAutomation::Windows #pid with adapter=autoit should return a positive inte
ger
     Failure/Error: pid.should > 0
     ArgumentError:
       comparison of String with 0 failed
     # ./pid_bug.rb:14

Finished in 3 seconds
2 examples, 1 failure
jarmo commented 13 years ago

This is actually already fixed in master https://github.com/jarmo/RAutomation/commit/6255d2caa20538f492bd9ff8663bfd3eaaf50d2a

It's not yet released into gem though.