It’s possible to learn a fair amount of actual software development just by testing applications – the way a development team works, at least one programming language, and how to solve problems as a programmer. I’m kind of in the weird position of providing an organisation with the ability to automate its software testing processes, despite this being an almost entirely new area to me.
I’ve got the core automation process nailed for individual scripts, I think – hit the record button, run through the application test manually, and replay the sequence of interactions later. Where LoadRunner was designed for load testing, Visual Studio (the ‘Ultimate’ edition) has something more suitable for testing GUIs and checking the data returned by the target application. Another difference is the test scripts can be Visual Basic or C# files.
I started out with a proof-of-concept project for a simple WordPress login and logout script. First, create a new ‘Coded UI Test Project’, under the Visual Basic or C# section. Either language is fine at this point.
The skeleton code will appear in the IDE, and the ‘Generate Code for Coded UI Tests‘ dialogue will give two options – the option we want is ‘Record actions, edit UI map or add assertions‘. When selected, a small UIMap panel will appear in the desktop, and this enables us to record a manual test, remove steps from the recorded sequence and focus tests on specific elements of the UI.
The Start Recording icon should be clicked before the target application is launched, and recording stopped/paused before the application is closed. Here I clicked the Start Recording icon, started up Internet Explorer and accessed https://xerocrypt.wordpress.com.
Next to the Record icon is another icon for Show Recorded Steps. We might want to look through this and remove any actions that weren’t part of the test we’re scripting.
If we’re happy with the sequence listed in the window, we click the ‘Generate Code’ icon, enter the method name, and click the ‘Add and Generate’ button. For some applications most the ‘Mouse hover’ actions can be removed first.
Back in the Visual Studio IDE, a script will appear as Visual Basic/C# code, but it’s not quite ready yet. The following steps are the really important bits for replaying the interactions and making the scripts portable.
1. Save the project, ideally by clicking ‘Save All’.
2. Under the ‘TEST‘ tab, select ‘Windows‘ then ‘Test Explorer‘. This will bring us down to the relevant code/method within the source file.
3. Then choose BUILD — Build Solution. Fingers crossed, it will build or compile with no errors.
4. Now, in order to replay the test, find the relevant method within the source file, right-click within it and select ‘Run Tests‘.
If done correctly, Visual Studio will use the script to replay all the interactions in gthe manual test, and finish with no errors.
At some point it might be necessary to modify the parameters, to customise the test script for a slightly different test.
The parameters and user input is stored in an XML file in the /obj/debug directory.
The way I found to do this is to go through the right pane, in the Class View window. Scroll down through the entries until you reach the project name, then find the [project name]params entry. After double-clicking that, another view will appear for that Public Class which contains the parameters accessible to the entire script.
The /bin/Debug directory is where the important project files are stored. There are two binaries for executing the test, plus an XML file that stores the test parameters. If you were to use these for automating other tests on another machine, it should be possible to run the script after changing the parameters as required in the (project-name).xml file.
Adding Assertions and Checking Values
Having got this working to test basic application functions, the next stage is to determine whether a target application is returning the correct output or displaying the correct text in dialogues. We do this by adding ‘assertions’. The following is a simple demonstration of this, using the calc.exe program.
Hit the ‘Start Recording‘ icon in the UIMap panel, open up the Calculator application, press some keys, then stop the recording.
Click the ‘Generate Code’ icon, and ‘Add and Generate’ to create the method.
After the code is generated, the target (centre) icon in the UIMap panel becomes active. Click and drag this to the calculator display box, which will then be highlighted. This will open the Add Assertion property list, and there will be listed the output of the calculator application. Right-click the output value entry (DisplayText value), and select ‘Add Assertion’.
And that’s it. Return to the Visual Studio code editing environment, then repeat the steps for running the test (save all, build, run inside test method).
I have uploaded