OWASP O2 Platform Blog

Simple Windows UIAutomation example

Here is a Windows UIAutomation example.

The script below will:

  • open up a new windows form (as a popup window),
  • add a textbox and button to it,
  • set an event handler on the button so that when it is clicked the text of the textbox will change
  • using O2’s API_GuiAutomation to get a reference to the window that was opened (which is running in the current process)
  • move the mouse to the button and click it
  • wait 2 seconds and close the popup window
var windowTitle = "UIAutomationTest - {0}".format(5.randomLetters());
var popupWindow = windowTitle.popupWindow();
var buttonText = "This is a button";
popupWindow.add_TextArea("this is some text inside this textbox")
           .insert_Right().add_Button(buttonText).fill().font_bold()
           .onClick(()=> popupWindow.control<TextBox>(true).set_Text("the button was clicked")); 
          
var currentProcess = Processes.getCurrentProcess();
var guiAutomation = new API_GuiAutomation(currentProcess);
var window  =  guiAutomation.window(windowTitle);
if (window.notNull())
{
    "got reference to window".info();
//    window.mouse();
    var button = window.button(buttonText);
    if (button.notNull())
    {
        "got reference to button".info();
        button.mouse_MoveTo().click();
    }
   
}
else
    "could not get window ref".error();

this.sleep(2000);   
popupWindow.parentForm().close();

return "ok";

//O2File:API_GuiAutomation.cs
//O2Ref:White.Core.dll 
 

June 18, 2011 - Posted by | Interoperability

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: