| |
This post is a continuation of the previous post Automating Web UI testing with SWEA, C#, & NUnit (part 1).
So what is SWEA? SWEA is short for Software Explorer Automation and was developed by Alex Furman. SWEA allows you to record and playback Web browser activity and most importantly, export those recordings into C# or VB.NET. These recorded and exported scripts utilize Alex's SWExplorerAutomation API. Alex has an AWESOME Flash demo of the SWEA Designer here. After watching the demo once before I installed and then again once after, I was able to easily record a few pages of IA and was playing them back in IE. SWEA uses a simple concept called "Scenes" to group HTML elements and data in a page. A "Scene" contains the elements and data/text that you define in the page. The HTML elements in your recorded Scene can be set as active or inactive appropriately, which is very important when you have dynamic content. The coolest thing about a Scene is that when referenced, if the entire Scene is not present (all it's defined, active elements) SWEA will throw an exception. This is really cool because it can be used to do a very quick regression by simply navigating to all the Scenes on your site; the Scene does the validation, thus eliminating doing a bunch of Asserts in NUnit to validate elements on the page. The simplicity of this will become a bit more obvious when we get into code example in the next post.
As stated previously, the recorded scenes can be exported to C# or VB.NET, and it will also create a Visual Studio Project for you. With exported code and a VS project, you're only one step away from wrapping it with the NUnit framework and then driving IE from NUnit! Check out this sample C# recording of Google.com:
|
namespace SWExplorerAutomation.Examples { using System; using SWExplorerAutomation.Client; using SWExplorerAutomation.Client.Controls; using SWExplorerAutomation.Client.DialogControls;
public class CodeTemplate {
public static void explorerManager_DialogActivated(object sender, SWExplorerAutomation.Client.DialogScene dialogScene) { }
public static void explorerManager_DialogDeactivated(object sender, SWExplorerAutomation.Client.DialogScene dialogScene) { }
public static void explorerManager_Error(object sender, SWExplorerAutomation.Client.SWException errorException) { }
public static void Main() { SWExplorerAutomation.Client.ExplorerManager explorerManager = new SWExplorerAutomation.Client.ExplorerManager(); SWExplorerAutomation.Client.Scene scene; explorerManager.DialogActivated += new SWExplorerAutomation.Client.DialogActivatedEventHandler (SWExplorerAutomation.Examples.CodeTemplate. explorerManager_DialogActivated); explorerManager.DialogDeactivated += new SWExplorerAutomation.Client.DialogDeactivatedEventHandler (SWExplorerAutomation.Examples.CodeTemplate. explorerManager_DialogDeactivated); explorerManager.Error += new SWExplorerAutomation.Client.ServerErrorEventHandler (SWExplorerAutomation.Examples.CodeTemplate. explorerManager_Error); explorerManager.Connect(-1); explorerManager.LoadProject("C:\\Google.htp"); explorerManager.Navigate("http://www.google.com/"); scene = explorerManager["Scene_GoogleHome"]; scene.WaitForActive(30000); ((HtmlInputText)(scene["searchTextBox"])).Value = "QAInsight"; ((HtmlInputButton)(scene["btnSearch"])).Click(); Console.WriteLine("\n Press Enter to exit"); Console.Read(); explorerManager.DisconnectAndClose(); } } } |

The above example was recorded in about the 30 seconds and it does the following:
- Starts IE
- Loads Google.com
- Enters "QAInsight" into the search textbox
- Clicks the "Google Search" button
- Closes IE
Alex has done a great job with SWEA and has been very supportive of those who use it. Every since I've started using the SWEA Designer and SWExplorerAutomation API, Alex been quick to respond to all my questions and issues and he is continuously upgrading it (recent versions support IE7 and .NET 2.0).
In the next post I'll share with you how I integrated SWEA with NUnit and how I created a test framework that uses separate classes for test calls, navigation, and test execution.
Update 02/20/2006: Part 3 can be found here. |
|