📜 ⬆️ ⬇️

White - automation of functional testing of applications

There are many tools to automate the functional testing of applications. On the one hand, universal commercial packages, real monsters of automation - HP QuickTest Pro, SilkTest, TestComplete. On the other hand, specialized or “poor” in functionality free tools — Selenium (web applications), pyWinAuto, Win32 :: GuiTest, etc. But the real gem among free tools, in my opinion, is the Codeplex White Framework.

Not so long ago, it took automation of some .net application. At work, QuickTest Pro was adopted as the main automation tool, but for this particular project it was too expensive: the project was very small - only a few operations were subject to automation. I got up with the search for a free alternative.

The first would be tested barley Win32 :: GuiTest. He coped with the task, but the script code turned out to be too sloppy - it would be too hard to maintain it later. And here on the site codeplex'a was found White
It turned out to be so simple and convenient that it was decided to use it. This framework supports most standard Win32, WinForms, WPF (Silverlight), SWT controls. Under a cat an example of simple automation of the Calculator Windows XP.

What we do:
We add on the calculator two numbers 10 and 59, and make sure that the result is 69.
What you need:
1. Visual C # Express to build examples
2. UISpy to define the parameters of windows and controls. Included in the Windows 7 SDK .
3. Actually White Framework
4. NUnit . It is convenient to use it in order not to create your own UI or mechanism for reporting errors / successes.
')
Go %)

Create a CalcAutoTests project of type Class Library in Visual C # Express.
Add links to builds
1. Nunit.Framework
2. White.Core
3. White.Nunit

NUnit introduces attributes for classes and methods that facilitate writing tests, in this example we will use only some of them -
1. TestFixture - designates our class as a test suite;
2. TestFixtuteSetUp - indicates the method that is performed before executing the tests;
3. TestFixtureTearDown - indicates the method that is performed after the tests are run;
4. Test - test method

White can identify controls by several parameters — by inscriptions (window titles), by AutomationID — by the resource identifier of the control, by the type of control, by its index. Identification can take place either on one basis or on several with the logical condition “AND”. In our task, the numeric buttons, the “+” and “=” buttons can be identified by captions, and the result display field - by AutomationID. To identify this field, we will need UISpy.

image

Finally, when we are fully prepared, we write the test code for the set.

using System;<br> using System.Diagnostics;<br> using NUnit.Framework;<br> using Core;<br> using Core.UIItems.Finders;<br> using Core.WindowsAPI;<br> using Core.Factory;<br> using Core.UIItems;<br> using Core.UIItems.WindowItems;<br><br><br> namespace CalcAutoTests<br>{<br> [TestFixture]<br> public class CalcTestSet<br> {<br> private Application application;<br> private Window mainform;<br> private Button[] btnDigits;<br> [TestFixtureSetUp]<br> public void CalcStartup() <br> {<br> // <br> var psi = new ProcessStartInfo();<br> psi.WorkingDirectory = @"C:\Windows\"; <br> psi.FileName = @"calc.exe"; <br> // <br> application = Application.Launch(psi);<br> // . <br> // Windows "" <br> mainform = application.GetWindow( "Calculator" ,InitializeOption.NoCache);<br> // "read only", <br> // " " <br> btnDigits = new Button[10];<br> for ( int i = 0; i < 10; i++)<br> btnDigits[i] = mainform.Get<Button>(i.ToString());<br> }<br> [TestFixtureTearDown]<br> public void CalcShutdown() <br> {<br> // <br> application.Kill();<br> }<br> [Test]<br> public void testAddition()<br> {<br> int a = 10, b = 59;<br> // + = <br> var btnAdd = mainform.Get<Button>( "+" );<br> var btnExec = mainform.Get<Button>( "=" );<br> // AutomationID, UISpy <br> var tbResult = mainform.Get<TextBox>( "403" );<br> // 10 <br> btnDigits[1].Click(); //"1" <br> btnDigits[0].Click(); //"0" <br> btnAdd.Click(); // "+" <br> // 59 <br> btnDigits[5].Click(); // "5" <br> btnDigits[9].Click(); // "9" <br> btnExec.Click(); // "=" <br> var result = tbResult.Text; // <br> int ires = int .Parse(result,System.Globalization.NumberStyles.Float);<br> // ? <br> Assert.AreEqual(a + b, ires);<br> }<br> }<br><br>} <br><br> * This source code was highlighted with Source Code Highlighter .


We collect the project.

If NUnit is installed in the default directory, then go to the directory with the build result and use the following line to run the tests:

“C: \ Program Files \ NUnit 2.5.2 \ bin \ net-2.0 \ nunit-console.exe” CalcAutoTests.dll

And enjoy the way the calculator itself presses the% buttons)

This synthetic test didn’t reveal one-tenth of the functionality of White, but I hope it showed that it is not necessary to use expensive commercial tools to automate applications. You can always find a free alternative in which the recorder may be missing (I know that White theoretically has it, but it cannot be compared with QTP recorder), developed reporting tools (they are easy to do), integration with industrial testing support systems . But it will have one indisputable advantage - the cost of licenses, which is very important for small projects.

Source: https://habr.com/ru/post/67455/


All Articles