Golem.Purple Windows UI Automation Component Getting Started - ProtoTest/ProtoTest.Golem GitHub Wiki

=====

###Golem.Purple - Windows UI Automation Framework in CSharp

Golem.Purple is a component of Golem that uses Microsoft's Windows UI automation libraries. Golem wraps around the Windows UI automation packages to make the task of automating your WinForm, WPF or Silverlight application easier.

Golem.Purple locates elements in a similar fashion to the WebDriver component. Elements in the application under test can be located an xPath string that is derived from the application tree at run time. This makes finding elements in your application quick and dynamic.

When configured, Golem.Purple will attach to a current running process or start a new instance of the application under test. This is handled with entries in your your test project's app.config file.

===== ###Important Information In order for your Windows based application to be tested with Golem.Purple, the application must be either a Windows Forms application, a Windows WPF application or a Silverlight application. Accessibility access must be enabled for these applications in order for the Windows UI Automation libraries to be able to interact with the application.

It is essential that test engineers have access to the Window's development kit as well. Paticularly for an application that Microsoft provides called Inspect.exe. Inspect.exe is an application provided by Microsoft that allows users to inspect a running application to identify automation elements.

You can download the Windows SDK from here: http://www.microsoft.com/en-us/download/details.aspx?id=8279

Alternatively, ProtoTest has tools available that will inspect an application and build xPath locators for elements automatically. To get access to these custom tools, please contact [email protected].

===== ###Finding Elements with xPath Using inspect.exe, provided by the Windows SDK, users can view the application under test during run time. Seen here, users can view an application tree.

Inspect.exe

In our example, we can see that MSPaint allows for Windows UI automation, because we can see the application tree. We can build an xPath locator for the Help button in the 'Ribbon' pane. The xPath for this button would be:

Untitled - Paint/UIRibbonDockTop/Ribbon/Ribbon/{BLANK}/Ribbon/Help

The {BLANK} text needs to be put in the xPath when the UI automation element does not have a name. This can be configured, but there always must be a value present for {BLANK}.

=====

###Creating a Test

  • Create a new Class Library by selecting File > New > Project > Class Library
  • Right click on References > Manage NuGet Packages
  • Add package “ProtoTest.Golem”
  • Use the "driver." property to use a direct WebDriver command
  • Paste the following code into your class file, save the project/solution, and build
using MbUnit.Framework;
using ProtoTest.Golem.Tests.PageObjects.Google;
using ProtoTest.Golem.WebDriver;

namespace ProtoTest.Golem.Tests
{
    class Test : PurpleTestBase
    {
        [Test]
        public void TestPaint()
        {
            MSPaint_6.PaintWindow().PaintText("ProtoTest Purple");
        }
	}
}

=====

Configuring Tests

Through an App.Config:

  • Add an "Application Configuration File"
  • The following settings can be configured:
<?xml version="1.0"?>
<configuration>
  <appSettings>
     <add key="AppPath" value="%windir%\\system32\\mspaint.exe"/>
    <add key="ProcessName" value="Paint"/>
    <add key="Purple_WindowTitle" value="Untitled - Paint"/>
    <add key="Purple_BlankValue" value="!BLANK!"/>
    <add key="Purple_Delimiter" value="/"/>
    <add key="Purple_ValueDelimiterStart" value="{"/>
    <add key="Purple_ValueDelimiterEnd" value="}"/>
    <add key="Purple_ElementWaitTimeOutSeconds" value="30"/>
   </appSettings>
</configuration>

Through code:

[FixtureInitializer]
        public void init()
        {
            Config.Settings.purpleSettings.Purple_windowTitle = "Untitled - Paint";
            Config.Settings.purpleSettings.ProcessName = "Paint";
            Config.Settings.purpleSettings.Purple_blankValue = "!BLANK!";
            Config.Settings.purpleSettings.Purple_Delimiter = "/";
            Config.Settings.purpleSettings.appPath = "%windir%\\system32\\mspaint.exe";
            Config.Settings.purpleSettings.Purple_ElementTimeoutWaitSeconds = 30;
        }

=====

Executing a Test

From Within Visual Studio:

  • TestDriven.net plugin is required
  • Right Click on Test > Run Test (Should open browser and close it)
  • Right Click on Class or project to run all tests within

From Gallio Icarus:

  • Open Gallio Icarus
  • Click "Add" and navigate to our ProjectName.dll file located in the /bin/release or /bin/debug/ directory
  • Select tests to execute
  • Click Run