September 14, 2009

Think Outside the Window

Helix ALM
A good test case describes the steps to be taken to perform a particular test. Most of these steps will involve the application under test, but there are also typically some set-up tasks to do prior to running the test, and clean-up tasks once the test is complete. These tasks may include copying over a fresh set of test data, clearing the browser cache, or killing off any hanging application processes. When you automate a test case you are focused on capturing your interactions with the application and verifying the application’s response, so the set-up and clean-up tasks usually get done manually. By thinking outside of the (application) window you can easily add many of these tasks to a script, saving you even more time. The QA Wizard Pro scripting language supports a statement that easily lets you work outside of your application window. The RunCommand statement allows a script to launch an executable from the DOS command line, similar to the Run option on the Start Menu. Essentially, it runs Windowssystem32cmd.exe and executes whatever is specified as the ExecutablePath argument, with options to specify WorkingDirectory and CommandLineArguments arguments if needed. A script executing the RunCommand statement will wait for the command to complete and return a code that can be used with branching logic if desired. For example, you can use RunCommand to determine if a file exists, so the application does not try to access a non-existent file but prints a warning message instead. The CommandLineArguments argument can be used to pass file names or any information required by the executable being launched. You can build a string of arguments using variables for flexibility, or simply pass values that allow the executable to be opened in a certain mode. Some examples where RunCommand can be used:
  • Run C:\windowssystem32cmd.exe and the DOS copy command to copy a file containing the baseline test data
  • Run C:\windowssystem32taskkill.exe to kill any hanging app processes prior to running a script
  • Run C:\windowssystem32rundll32.exe to clear browser history settings such as cookies and passwords
  • Run a DOS batch file (.bat) to perform a sequence of actions
Running DOS commands from the command line requires both the command and arguments to be in quotes. Some basic examples can be found here and modified: Running DOS Commands from the Command LineRunBackgroundCommand statement is also available, which allows the executable to be run in parallel with the script. RunBackgroundCommand does not set a return code so it can’t be used for branching, but might be used to launch an older legacy system whose data the application relies on. A little additional work outside the window can make testing a breeze!