I'm working on some scripted GUI test for a windows C# .net app. I'm using Ruby to drive the testing and my feet are officially wet in the realms of WIN32API - but I'm certainly not over-confident with it. As a mater of fact, I feel like I'm missing some fundamental understanding. At this point, the only way I know how to gain access to different controls is through the combination of control class and maybe some identifying text.
My problem is, the application I have to test has a series of several buttons - all of which contain an icon and no text.
Is there a method I could use to retrieve a specific button? I've played with the notion of doing this via relative positioning, but that kind of sucks, and I'm not super interested in it.
I have access to the source code; if there is some id开发者_如何学Centifying attribute/property that I can set, I'm more than willing. I'm just ignorant at this point.
I'm facing a very similar issue at the moment. You could try setting ids/automation ids on the form and its controls and then use ruby + ironruby + bewildr.
https://github.com/natritmeyer/bewildr
There is a great run through at DotNetDevDude: http://dotnetdevdude.com/Blog/2010/08/23/AutomatedWPFUITestingUsingIronRubyAndCucumberWithBewildr.aspx
Good luck.
Unfortunately it's probably not easy. You'd want to enumerate all the windows and their children and look for "clues" as to which one is the button you want somehow, all using the win32api.
An example of "enumerating all windows" can be found in win32screenshot (search for "window_titles").
http://github.com/rdp/win32screenshot
-r
UI Automation like this is a PITA. I don't know Ruby so I can't help you with specifics but I can provide some thoughs from the last gui based harness I wrote. It was done in C# and I utilized the System.Runtime.InteropServices to access various functions in the user32.dll.
I was then able to build various methods that obtained the handle of the various GUI elements. Often it was a matter of getting the handle of the parent window and then the associated children until I got the correct control, used the handle then to perform what ever function was needed on that control. A tool like Spy++ or WinID is very useful for seeing what the relationships between the child and parent controls are as well as figure out if you are getting the correct handle as you are building out your harness.
Sorry I can't directly help you.
Ok if there have icon then you can go on the page and view code. Then find out the button icon name in view code. You are get scr and alt parameter, then copy the name and past in following code.
ie.image(:src, /icon name/).click
or
ie.image(:alt, /icon name/).click
精彩评论