northwoodspd / uia

A ruby gem for interacting with automation elements in Windows
MIT License
17 stars 4 forks source link

What Ruby version or gems is required for Uia work? #14

Closed leoniv closed 6 years ago

leoniv commented 6 years ago

Hi! Great work. I'm playing with Uia but i have got "Segmentation fault":

C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/library/win32.rb:31: [BUG] Segmentation fault
ruby 2.5.1p57 (2018-03-29 revision 63029) [i386-mingw32]

-- Control frame information -----------------------------------------------
c:0033 p:---- s:0176 e:000175 CFUNC  :enum_child_windows
c:0032 p:0039 s:0169 E:001da0 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/library/win32.rb:31
c:0031 p:0016 s:0161 E:0002dc METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/finder.rb:80
c:0030 p:0159 s:0154 e:000153 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/finder.rb:25
c:0029 p:0006 s:0149 e:000148 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia.rb:20
c:0028 p:0013 s:0144 e:000143 BLOCK  test/test_helper.rb:12 [FINISH]
c:0027 p:0035 s:0141 e:000140 METHOD test/test_helper.rb:22
c:0026 p:0023 s:0133 E:002180 METHOD test/test_helper.rb:12
c:0025 p:0005 s:0129 e:000128 BLOCK  test/test_helper.rb:35 [FINISH]

Failure rises while find application window:

    def run_app
      @app = ChildProcess.build('notepad').start
-->      wait_until { Uia.find_element title: /блокнот/i }
      @app
    end

Gems:

ffi (1.9.25 x86-mingw32)
uia (0.6)

Thanks. Leonid.

leviwilson commented 6 years ago

I'm wondering if it's the unicode characters

On Sun, Aug 5, 2018, 11:51 AM Leonid Vlasov notifications@github.com wrote:

Hi! Great work. I'm playing with Uia but i have got "Segmentation fault":

C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/library/win32.rb:31: [BUG] Segmentation fault ruby 2.5.1p57 (2018-03-29 revision 63029) [i386-mingw32]

-- Control frame information ----------------------------------------------- c:0033 p:---- s:0176 e:000175 CFUNC :enum_child_windows c:0032 p:0039 s:0169 E:001da0 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/library/win32.rb:31 c:0031 p:0016 s:0161 E:0002dc METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/finder.rb:80 c:0030 p:0159 s:0154 e:000153 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia/finder.rb:25 c:0029 p:0006 s:0149 e:000148 METHOD C:/msys64/mingw32/lib/ruby/gems/2.5.0/gems/uia-0.6/lib/uia.rb:20 c:0028 p:0013 s:0144 e:000143 BLOCK test/test_helper.rb:12 [FINISH] c:0027 p:0035 s:0141 e:000140 METHOD test/test_helper.rb:22 c:0026 p:0023 s:0133 E:002180 METHOD test/test_helper.rb:12 c:0025 p:0005 s:0129 e:000128 BLOCK test/test_helper.rb:35 [FINISH]

Failure rises while find application window:

def run_app
  @app = ChildProcess.build('notepad').start-->      wait_until { Uia.find_element title: /блокнот/i }
  @app
end

Gems:

ffi (1.9.25 x86-mingw32) uia (0.6)

Thanks. Leonid.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/northwoodspd/uia/issues/14, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjD4uQzT9w0GcxwRjYTvl3m68axUQrMks5uNxSLgaJpZM4Vvbf2 .

leviwilson commented 6 years ago

I will try to take a look later on this afternoon and see if I can see what might be going on. It's been a while since I have maintained this gem but what you are trying should absolutely work.

leoniv commented 6 years ago

Unicode does not matter. I call #find_element with ascii title like so:

    def run_app
      @app = ChildProcess.build(PATH).start
      wait_until { Uia.find_element title: /MainFormWindow/i }
      @app
    end

but fault appears also.

I suppose it's ffi bug. I've replaced callback pointer to zero and "segmentation fault" error doesn't appear, but uia doesn't work too (:

    def find_window(parent, &block)
      found_window = nil
      window_callback = FFI::Function.new(:bool, [:long, :pointer], {convention: :stdcall}) do |handle, _|
        found_window = handle if block.call handle
        !found_window
      end
#      Win32.enum_child_windows parent, window_callback, 0
      Win32.enum_child_windows parent, 0, 0
      found_window
    end

Have you any idea? Thanks a lot for your time.

leviwilson commented 6 years ago

You're using the 32-bit version of ruby, correct? Not the x64?

leoniv commented 6 years ago

Of course ruby 2.5.1p57 (2018-03-29 revision 63029) [i386-mingw32]

leoniv commented 6 years ago

Solved (conditionally)

Cause of this is bug in the ffi gem.

Error is present in the ffi x86-mingw32 from v1.9.21 up to last v1.9.25 and reproduces in the Rubies:

Ruby v2.1 and v2.2 haven't tested.

From v1.9.4 up to 1.9.18, ffi working fine in the same Ruby versions as above, excluded Ruby v2.5. ffi less than v1.9.21 does not compatible with Ruby 2.5.

Conclusion. For perfectly using uia gem required:

Set this dependencys in your gemspec or Gemfile and enjoy.

For @leviwilson best regards and thanks for great work.

leviwilson commented 6 years ago

@leoniv thank you so much for finding that! I didn't think to bump that b/c I thought v1.9.4 was good to go (there was an issue like that before.

Good catch! Would you like to potentially send a pull request to lock it to those versions of FFI and we can close this issue? Thanks!

leviwilson commented 6 years ago

https://github.com/ffi/ffi/issues/302 was the original issue that I had bumped to v1.9.4

leviwilson commented 6 years ago

https://github.com/northwoodspd/uia/issues/7

leoniv commented 6 years ago

I'm understand what is happening less and less more ))

Bug is not in the ffi source bug in the ffi gem build!

I have built ffi v1.9.25 form sources at my laptop and it perfectly works without any fails.

Have you ideas what to do in this case?

May be whrites about it trobles in to the msys2 project? Who build gems for prodaction? My be problem on the my laptop only?

leviwilson commented 6 years ago

I would follow up with the FFI repository. You should reference the problem that I linked to you that I had before for reference and mention that you're seeing the same thing again.

They would better be able to tell you what's going on and why it's not working. I believe it has something to do when you call win32 functions that have callbacks for whatever reason (like enumerate windows does).

On Thu, Aug 9, 2018 at 10:53 AM Leonid Vlasov notifications@github.com wrote:

I'm understand what is happening less and less more ))

Bug is not in the ffi source bug in the ffi gem build!

I have built ffi v1.9.25 form sources at my laptop and it perfectly works without any fails.

Have you ideas what to do in this case?

May be whrites about it trobles in to the msys2 project? Who build gems for prodaction? My be problem on the my laptop only?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/northwoodspd/uia/issues/14#issuecomment-411786249, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjD4lgqkCZwWEE1sgZUylUspwOOhH3bks5uPE0HgaJpZM4Vvbf2 .

leoniv commented 6 years ago

I will to do so. I suppose this issue can be closed whitout lock. I will write about this problem in the uia README if you don't mind.

Thanks for your time again. Good luck.

leoniv commented 6 years ago

ffi/ffi#649