CapturePlayback Example


Capture/Playback Example

Now it's your turn to sit in the driver's seat. Check to see if you have the Minesweeper game on your PC. In Windows XP, go to All Programs\Games\Minesweeper. This game tests your skill at identifying the locations of mine placed on a grid. The random placement of mines on the field is not under your control, so that part of the game is not a good candidate for capture/playback testing. However, you can change some game options that affect the size of the game board. Those will be the subject of this automation example.

Before starting the automation process, put a Minesweeper shortcut (icon) on your Desktop. You can probably find one to copy at Documents and Settings\All Users\Start Menu\Programs\Games on your PC. This will make it easy to launch Minesweeper during recording and playback.

Note ‚  

It's not a good idea to have your automated test launch applications from the Windows "All Programs" menu. If any apps have been added or deleted since the time you made the test recording, the menu order will be different and the mouse will be happily clicking away at whatever is there. Nothing ruins your day like having apps uninstalled by an automated test.

If you haven't done so already, get the demo version of Vermont HighTest from their Web site and install it on your PC. After installation is successful, double-click the "Vermont Hightest" icon and you're ready to continue.

Minesweeper Test Capture

Before you start recording, review the following steps. Then select New from the Record menu or hit F11 to begin recording.

Your automated test should follow these steps:

  1. Double-click the Minesweeper icon to start the game. Do a window capture of the initial minefield, shown in Figure 17.6.

  2. Click the Game menu and select Custom . Capture the region containing the three numeric boxes, as illustrated in Figure 17.7.

  3. Click inside each of the CustomField value boxes and change them to 20, 20, and 2. You can backspace to erase the existing digits and then type in your own. Do a capture of the new values. It's okay if you don't trace the region in exactly the same place you did the first time. The important thing is to get all of the boxes and their values. Figure 17.8 shows how the window should look prior to capturing the image of your new values.

  4. Click OK. This should take you back to an updated minefield window that uses your custom height and width values. Your minefield should look exactly like Figure 17.9. Capture this as a window.

  5. Now go back to the Game menu and select Custom again. Your window should look like Figure 17.10. Once again, capture a region containing the three custom values.


Figure 17.6: Initial Minesweeper game field.

Figure 17.7: Custom Field value area to capture.

Figure 17.8: New custom values to be captured.

Figure 17.9: Updated minefield using new custom values.

Figure 17.10: Revisited Custom Field window.

At this point you can click on the "stop" icon in the Record Bar. Go back to Vermont HighTest and finish recording by clicking the End selection from the Record menu. Update the test header information and save your file.

When you are done, your test file should look something like this:

 ;FileName: c:\documents and settings\administrator\desktop\vht test files\minetest1.inb ; ;Created: Thu Dec 23 01:11:26 2004 ;Author: Me ; ;Product: Game Testing All In One ;Abstract: Minesweeper automation example ; ActivateWindow("Shell_TrayWnd", "", NULL, 10.0) ActivateWindow("Progman", "Program Manager", NULL, 10.0) ActivateWindow("SysListView32", "FolderView", 1, 10.0) ClickListView(1, "Minesweeper", DBLCLK, 0.0) CompareScreen("Window 1") ActivateWindow("Minesweeper", "Minesweeper", NULL, 10.0) ClickMenu("&Game", 0.09) ClickMenu("&Game;&Custom...", 2.67) CompareScreen("Region 1") ActivateWindow("#32770", "Custom Field", NULL, 10.0) ClickEdit(141, 1, 0, 0.09) Keys("[Backspace]", 0.82) Keys("20", 0.37, 0.1) ClickEdit(142, 1, 0, 1.74) Keys("[Backspace]", 0.62) Keys("20", 0.51, 0.06) ClickEdit(143, 2, 0, 1.64) Keys("[Backspace][Backspace]", 0.64, 0.18) Keys("2", 0.79) CompareScreen("Region 2") ClickButton("OK", 1, 22.25) CompareScreen("Window 2") ActivateWindow("Minesweeper", "Minesweeper", 51249669, 10.0) ClickMenu("&Game", 0.13) ClickMenu("&Game;&Custom...", 1.94) CompareScreen("Region 3") 

Minesweeper Test Playback

Reset the Minesweeper field back to its original state ‚ in Beginner mode ‚ and close it. Select Run from the VHT playback menu or hit F12 to play your newly recorded test. Sit back and watch the magic. When you see the final window that you captured, you have reached the end of the playback. VHT will also pop up and have a log file available for you to analyze.

Your log of the playback should look similar to this:

 ************************************************************ * FileName:         c:\documents and settings\administrator\desktop\vht test files\minetest1.inb * Log Created on:   Thu Dec 23 01:11:44 2004 * * Playback Options: *     Play Speed: 50 *     Terminate on Failure: * *     Ignore During Compare: ************************************************************ ActivateWindow > "Shell_TrayWnd", "", NULL, 10.0...............Result: Success ActivateWindow > "Progman", "Program Manager", NULL, 10.0......Result: Success ActivateWindow > "SysListView32", "FolderView", 1, 10.0........Result: Success ClickListView > 1, "Minesweeper", DBLCLK, 0.0..................Result: Success CompareScreen > "Window 1".....................................Result: Failure ActivateWindow > "Minesweeper", "Minesweeper", 51249669, 10.0..Result: Failure ClickMenu > "&Game", 0.09......................................Result: Success ClickMenu > "&Game;&Custom...", 2.67...........................Result: Success CompareScreen > "Region 1".....................................Result: Success ActivateWindow > "#32770", "Custom Field", NULL, 10.0..........Result: Success ClickEdit > 141, 1, 0, 0.09....................................Result: Success Keys > "[Backspace]", 0.82.....................................Result: Success Keys > "20", 0.37, 0.1.........................................Result: Success ClickEdit > 142, 1, 0, 1.74....................................Result: Success Keys > "[Backspace]", 0.62.....................................Result: Success Keys > "20", 0.51, 0.06........................................Result: Success ClickEdit > 143, 2, 0, 1.64....................................Result: Success Keys > "[Backspace][Backspace]", 0.64, 0.18....................Result: Success Keys > "2", 0.79...............................................Result: Success CompareScreen > "Region 2".....................................Result: Success ClickButton > "OK", 1, 22.25...................................Result: Success CompareScreen > "Window 2".....................................Result: Success ActivateWindow > "Minesweeper", "Minesweeper", 51249669, 10.0..Result: Failure ClickMenu > "&Game", 0.13......................................Result: Success ClickMenu > "&Game;&Custom...", 1.94........................... Result: Success CompareScreen > "Region 3".....................................Result: Success ************************************************************ * Log Ended on: Thu Dec 23 01:13:03 2004 ************************************************************ 

Minesweeper Test Editing and Debugging

Hmm. All of the CompareScreen commands succeeded, but all of the ActivateWindow commands failed! After applying Rule 1, look up the syntax for ActivateWindow in the VHT User's Guide. You will find out that the third parameter is the window ID. Well, this number is created anew each time the Minesweeper application is started. The IDs recorded in your test are probably different than the ones listed in the preceding code. To ignore the ID value during playback, use your editing skills to change the IDs to NULL in all of the ActivateWindow commands. Here's what each one should look like:

 ActivateWindow("Minesweeper", "Minesweeper", NULL, 10.0) 

Now rerun the test and you should get a Success result for every command.

If you need help debugging, consult the VHT User's Guide for the syntax and operational details of any commands that fail. Chapter 6 specifically describes the debugging capabilities of VHT. If you're not sure why screen comparisons are failing, you can select Screenshot under the Compare menu in VHT. This gives you a list of the images that were captured for your test. The ones with a red X, like Window 1 shown in Figure 17.11, are the comparisons that failed. Click a failed item to see the image captured during playback of the test. Clicking the displayed image will toggle between the recently captured image and the test's reference image.


Figure 17.11: Screenshot compare list for failed Minesweeper test.

Minesweeper Test Modularity and Reuse

Isn't it annoying that you have to manually reset the Minesweeper game back to its initial state after running each automated test? You will waste time if you re-run the test and forget to reset and close the game. If many tests need to be run in sequence, the manual activity time would add up and defeat the whole purpose of automation. A way to deal with this is to automatically return the game to the proper state after you run each test. You could add a chunk of code at the end of every test, but a more efficient solution is to create a separate module that performs the cleanup. That module would get called by each of your Minesweeper tests. This approach costs only one additional line per test to call the cleanup routine.

The steps you need to implement in the cleanup module are as follows :

  1. Click OK to close the custom options window that was left open at the end of the original test (see Figure 17.10).

  2. Activate the Minesweeper window.

  3. Select the Game options and click Beginner.

  4. Close the Minesweeper window.

This is a good situation in which to use a LogComment statement at the beginning of the module. It will leave behind a textual note in the log file to explain what is happening.

In this case, explain that what is happening is only for the purposes of cleaning up and is not intended to test any particular functionality. Here's an example you can put at the beginning of your cleanup file:

 LogComment("Nothing more to check, just shutting down for next test...") 

That part was easy, but what about implementing the four cleanup steps? One strategy would be to capture the cleanup steps and then add the LogComment statement. You already know how to do that, so think about another possibility. Okay, time's up! You could enter the test code directly into the file. Take a look at what you have already captured and see if any of those operations are similar to the cleanup activities.

First, there's an example of clicking the OK button in the main test routine. The command is

 ClickButton("OK", 1, 12.25) 

Next, there are also commands to activate the Minesweepe r window. These are the ones you edited to use NULL instead of a specific window ID:

 ActivateWindow("Minesweeper", "Minesweeper", NULL, 10.0) 

There is no exact match for cleanup step 4 in the main test file, but there is something that is close. In the main test file there are commands that choose the Custom option from the Game menu. This requires two steps: selecting the Game menu and then selecting Custom from the option list. Since you want the Beginner option, change "Custom" to "Beginner" like so:

 ClickMenu("&Game", 0.11) ClickMenu("&Game;&Beginner", 1.13) 

Last but not least, you need to provide some way to close the Minesweeper window. Since you've seen the ActivateWindow command, it may not be too much of a leap to guess that there is a CloseWindow command. A quick check of the VHT User's Guide reveals that indeed there is. Just add the window name and you're all set to go. Here's what the complete cleanup should look like, after filling in your header information:

 ;FileName: c:\documents and settings\administrator\desktop\vht test files\minesweepercp\ cleanmine.inb ; ;Created: Thu Dec 23 10:58:57 2004 ;Author: Me ; ;Product: Game Testing All in One ;Abstract: Reusable script to shutdown Minesweeper after each test ; LogComment("Nothing more to check, just shutting down for next test...") ClickButton("OK", 1, 12.25) ActivateWindow("Minesweeper", "Minesweeper", NULL, 10.0) ClickMenu("&Game", 0.11) ClickMenu("&Game;&Beginner", 1.13) CloseWindow("Minesweeper") 

To use this routine, Call it from the main test file. Since it's in its own file, use the filename as the call parameter. You should add this line to the end of the main test. Don't forget the .inb file extension.

 Call("cleanmine.inb") 

Now you can run the main test file and it will call the cleanup file. When your automated test ends, Minesweeper has been put back into Beginner mode and closed up for the next test. The test produces a single test log that incorporates the results of the main test file and the external cleanmine routine. Your results should look like the following:

 ************************************************************ * FileName:         c:\documents and settings\administrator\desktop\vht test files\minesweepercp\minetest3.inb * Log Created on:   Thu Dec 23 13:14:43 2004 * * Playback Options: *     Play Speed: 50 *     Terminate on Failure: * *     Ignore During Compare: ************************************************************ ActivateWindow > "Shell_TrayWnd", "", NULL, 10.0...............Result: Success ActivateWindow > "Progman", "Program Manager", NULL, 10.0......Result: Success ActivateWindow > "SysListView32", "FolderView", 1, 10.0........Result: Success ClickListView > 1, "Minesweeper", DBLCLK, 0.0..................Result: Success CompareScreen > "Window 1".....................................Result: Failure ActivateWindow > "Minesweeper", "Minesweeper", NULL, 10.0......Result: Success ClickMenu > "&Game", 0.09......................................Result: Success ClickMenu > "&Game;&Custom...", 2.67...........................Result: Success CompareScreen > "Region 1".....................................Result: Success ActivateWindow > "#32770", "Custom Field", NULL, 10.0..........Result: Success ClickEdit > 141, 1, 0, 0.09....................................Result: Success Keys > "[Backspace]", 0.82.....................................Result: Success Keys > "20", 0.37, 0.1.........................................Result: Success ClickEdit > 142, 1, 0, 1.74....................................Result: Success Keys > "[Backspace]", 0.62.....................................Result: Success Keys > "20", 0.51, 0.06........................................Result: Success ClickEdit > 143, 2, 0, 1.64....................................Result: Success Keys > "[Backspace][Backspace]", 0.64, 0.18....................Result: Success Keys > "2", 0.79...............................................Result: Success CompareScreen > "Region 2".....................................Result: Success ClickButton > "OK", 1, 12.25...................................Result: Success CompareScreen > "Window 2".....................................Result: Success ActivateWindow > "Minesweeper", "Minesweeper", NULL, 10.0......Result: Success ClickMenu > "&Game", 0.13......................................Result: Success ClickMenu > "&Game;&Custom...", 1.94...........................Result: Success CompareScreen > "Region 3".....................................Result: Success Call > C:\Documents and Settings\Administrator\Desktop\VHT TEST FILES\MinesweeperCP\cleanmine.inb ...Result: Success Nothing more to check, just shutting down for next test... LogComment > "Nothing more to check, just shutting down for next test..."...Result: Success ClickButton > "OK", 1, 12.25...................................Result: Success ActivateWindow > "Minesweeper", "Minesweeper", NULL, 10.0......Result: Success ClickMenu > "&Game", 0.11......................................Result: Success ClickMenu > "&Game;&Beginner", 1.13............................Result: Success CloseWindow > "Minesweeper"....................................Result: Success ************************************************************ * Log Ended on: Thu Dec 23 13:15:37 2004 ************************************************************ 



Game Testing All in One
Game Testing All in One (Game Development Series)
ISBN: 1592003737
EAN: 2147483647
Year: 2005
Pages: 205

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net