jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

NoMethodError: undefined method 'hwnd' for :win10:Symbol #103

Closed srkrkalyan closed 8 years ago

srkrkalyan commented 8 years ago

Hi - I am trying to get the list of items in a list box of a desktop app using the List Box class under MsUia.

require 'rautomation' win10=RAutomation::Window.new :title => /part of the title/, :adapter => :ms_uia win10.exists? #Received True win10.minimize #Window Successfully minimized ListBox1 = RAutomation::Adapter::MsUia::ListBox.new :win10 :value => "value of 1st item in list box" #identified value of list box using a spying tool

Last line of above program returning below error. NoMethodError: undefined method 'hwnd' for :win10:Symbol

Could you please advise if I am missing anything?

leviwilson commented 8 years ago

The best way to look at some of the usages for various control is going to be in the specs. Here is the spec for ListBox controls for the ms_uia adapter.

enkessler commented 8 years ago

It looks like you passed in the symbol :win10 instead of the variable win10 that you had previously assigned a window object. That's why it doesn't have a #hwnd method. Commas between the window argument and the locator hash could also help.

srkrkalyan commented 8 years ago

Thank You ! I found what I am missing. One question though, can we use any set of property name and value as locators (identified by any spying tool) or only the specified locators viz., value, class, id, index should be used?

srkrkalyan commented 8 years ago

The line of code to identify the test object (button) is not throwing any error. At the same time, I am not able to call any method on the button object. Now I realized that my AUT (application under test) is developed in Java (not native windows forms/UI). So, I would like to know if I can use rautomation for automating desktop applications developed on either Java or .NET or power builder? Please advise

leviwilson commented 8 years ago

Can you interact with controls using UI Spy or other automation inspection tools? UIA Verify is another one.

If you can interact with something like that, then you can probably find a way to automate it. The amount that you are able to will depend on what is exposed to UIA. On Mar 3, 2016 12:11 AM, "srkrkalyan" notifications@github.com wrote:

The line of code to identify the test object (button) is not throwing any error. At the same time, I am not able to call any method on the button object. Now I realized that my AUT (application under test) is developed in Java (not native windows forms/UI). So, I would like to know if I can use rautomation for automating desktop applications developed on either Java or .NET or power builder? Please advise

— Reply to this email directly or view it on GitHub https://github.com/jarmo/RAutomation/issues/103#issuecomment-191587319.

srkrkalyan commented 8 years ago

Yes, I am able to identify and automate UI objects using licensed tools like HP UFT and Microsoft Coded UI. But, I have not tried with UI Spy/Inspect/UIA. I will also try with these inspection tools

The 'button' under test is not directly available on the 'window'. Instead 'Button' is available on a 'frame' within the window. So, can I still create a reference to the button (using Rautomation) as follows:

win10=RAutomation::Window.new :title => /part of the title/, :adapter => :ms_uia Button1 = RAutomation::Adapter::MsUia::Button.new win10, :text => "text/label on the button"

Also UI objects (as per HP UFT Object Spy) were identified as JRootPane, JFrame, JButton etc.,

enkessler commented 8 years ago

I am reminded of the time that I had to automate a desktop application that was nothing but un-inspect-able images but trying to pass itself off as something that hadn't gone out of style over a decade ago. Everything on the screen was essentially a lie. However, they were consistent lies and I managed to drive the thing with nothing more than RAutomation's ability to control the mouse and keyboard, it's ability to tell me the coordinates of the top level application window, and a pile of math.

Here's hoping that you never have to do the same thing.

leviwilson commented 8 years ago

If the objects that are exposed (the JFrame, JButton, etc.) are exposing UIA patterns that you can work with, then you'll probably fine. Though it's possible that RAutomation will not be your best bet. I have another gem, uia, that works much more closely with how UIA elements are exposed on a tree.

There is a better explanation as to why here.

enkessler commented 8 years ago

Have we considered having the UIA adapter use that uia gem under the covers?

leviwilson commented 8 years ago

I have, but with more talk with @jarmo I think he was thinking that it would be a replacement for it altogether.

enkessler commented 8 years ago

It might provide all of the functionality that the UIA adapter needs, sure, but shouldn't it not replace it all together because the point of the an adapter is to provide the same API as the other adapters? Unless the uia gem has the same API as RAutomation.

Or did you mean that RAutomation itself would become redundant because of the uia gem?

leviwilson commented 8 years ago

I think the latter.

enkessler commented 8 years ago

Granted, RAutomation is pretty much a Windows only gem because we never have made an adapter for another OS, but the design does allow for that eventuality.

So my two questions are: 'Is the scope of RAutomation changing such that it is no longer a Ruby Automation library but instead a Windows Automation library?' and 'Does the uia gem do everything that the current Windows adapters do such that there won't be a functionality loss and, by extension, no need for multiple Windows adapters?'

leviwilson commented 8 years ago

I don't think the scope of RAutomation is changing. You could use UIA to implement all of the facets of RAutomation now, I just haven't had the time to do it.

I don't know the answer to the last question; I personally only primarily use the ms_uia adapter as it has the most functionality to offer IMO. It's possible that there isn't really a need for multiple Windows adapters because the ms_uia covers most all use cases as far as I know.

srkrkalyan commented 8 years ago

Thanks for your inputs. It seems none of the desktop apps I am testing (built on Java Swing, .NET, Power Builder) are exhibiting UIA patterns. I used UI spying tools from windows SDK and the UI of these apps was identified as a _single frame _instead of individual controls (ie., button, check box, text box etc.,). So, I am not able to use either Rautomation or UIA.

Could you please advise if there is any other way I can use Ruby to automate the UI of these legacy desktop applications? If no better way available in Ruby, are you aware of any open source solution to automate these?

leviwilson commented 8 years ago

Yeah, in the absence of UI Automation patterns being exposed, the only other thing is to use the win32 driver to see what it exposes (though you'll be limited as well in what you can do).

I don't know of any other tool that you can use Ruby to automate; I don't know much about Java Swing, but if you control the apps you can expose UIA patterns yourself. I've done this in .NET applications (using UIA.Extensions) but I cannot speak to Java Swing apps.

Good luck.