May 9, 2009
Understanding Repository Variables
Repository variables can help you test dynamic attributes of Windows and Web applications. Repository variables, which are defined in the application repository for each version, can be used in any scripts recorded or run against the application. During playback, any instance of a variable is replaced with the default value set for the variable or the value selected when playback starts. The primary benefit of using repository variables is that you can maintain a reusable suite of test scripts without spending extra time modifying or creating new scripts every time an application changes. Repository variables also allow you to manage and access dynamic test data without maintaining multiple data sources. This article describes common uses for repository variables, where variables can be used, how variables are used during recording and playback, and how to create variables. [toc]
When to use repository variablesUse repository variables if you have multiple scripts that test the same data and the data changes based on application conditions and inputs. Dynamic data may include input values, URLs, window names, or application text. The following examples describe common uses for repository variables.
Web sites hosted on multiple serversYou may need to run the same scripts against multiple Web servers, such as development, test, and production servers. You can create a repository variable that contains each server address as a value and set the variable to prompt when recording or playback starts so users can select the address to use for the session. You can also use the variable in the URL to open the Web page. When you create a new Web application, you can automatically create a URLROOT repository variable. The URLROOT repository variable stores Web server addresses so you can easily run scripts against multiple servers.
Applications with multiple login credentialsAn application may include functionality that is only accessible when a specific username and password is used. Instead of maintaining multiple login scripts or modifying scripts to change static username and password values, you can create username and password variables. You can set the variables to prompt when recording or playback starts so users can select the appropriate login values.
Applications with dynamic controlsDynamic applications may have controls with properties that change frequently, such as window names. QA Wizard Pro may use these properties to locate controls during playback. If the expected value of a property selected as search criteria does not match the application during playback, scripts fail. To avoid this, you can create a repository variable for the dynamic property and specify the variable as the expected value in the application repository.
Where to use repository variablesYou can use repository variables in scripts, window and control expected values in the application repository, and Web application startup URLs.
In scriptsRepository variables are commonly used in scripts to replace static values in statements. For example, an application has a LOGIN_NAME repository variable and you want to replace any instance of a static username value in scripts with the variable name. In the GUI statement editor, you can select Expression as the value type and enter the variable name as the expression. The following example shows the LOGIN_NAME variable used in the Type Text statement.
Expected values for windows and controlsYou can use repository variables in the expected values used as search criteria to locate windows and controls during playback. For example, the URL for a hyperlink on a Web page changes based on the server address. If a property used as search criteria includes the URL, scripts will fail because the expected value does not match the actual Web page value. You can replace the static URL with a repository variable so QA Wizard Pro can successfully locate the hyperlink during playback. The following example shows how the URLROOT repository variable is used instead of the static server address in the Href property.
Web application startup URLsIf you add the URLROOT repository variable when you add a Web application, it is automatically used in place of the static URL in the application startup information. If you later decide to use a repository variable instead of a static URL, you can modify the URL in the application properties. Right-click a version and choose Properties. Replace the static portion of the URL with the repository variable name and use percent signs at the beginning and end of the name to indicate that the value is a variable. The following example shows the URLROOT repository variable used in a startup URL.
How repository variables are used during recordingRepository variables are only used during recording if the Auto-Record Substitution option is selected for the variable. Auto-record substitution automatically replaces any instance of the variable value in the script with the variable name. Any instances of the variable value in expected values for new controls captured during the recording session are also replaced with the variable name. For example, if you use the URLROOT repository variable with a default value of http://www.seapine.com and the Auto-Record Substitution option is selected for the variable, all instances of http://www.seapine.com are replaced with %URLROOT% during recording. You should only use auto-record substitution to replace unique values, such as Web server addresses. If the value is not unique, you may unintentionally replace the wrong value in scripts and the repository, which can cause scripts to fail.
How repository variables are used during playbackDuring playback, the default repository value or a selected value is used for each instance of the variable name. For example, if the default value for the URLROOT variable is http://www.seapine.com, any instance of URLROOT in the script or repository is replaced with http://www.seapine.com. Repository variables include a Prompt option, which provides flexibility to preset variable values when recording or running scripts. If the variable is set to prompt, the Enter Variable Values dialog box opens when recording or playback starts. You can use the default variable value displayed in the dialog box or enter or select a different value. If you use a different value, it is set as the new default variable value. The following example shows three variables and their default values in the Enter Variable Values dialog box.
How to create repository variablesYou can create the URLROOT repository variable to store Web server addresses when you create a new Web application or create a variable for any purpose in the application repository.
New Web application—URLROOTWhen you create a new Web application, the URLROOT repository variable is created by default. The variable value is the root URL for the server that hosts the application. The following screenshot shows the URLROOT repository variable created for a site. The URL used to open the site is www.wysicorp.com/products. When the application is created, the URLROOT variable replaces the server portion of the URL in the application startup information. The value stored in the repository will be %URLROOT%/products.
In the application repositoryYou can also create repository variables in the application repository.
- Select a version in the application repository and choose File > Properties.
- Click the Repository Variables tab.
- Enter or select the following information.
- Variable Name—Name that uniquely identifies the variable. The name must start with an alphabetic character, cannot contain spaces, and can only contain alphanumeric or underscore characters.
- Description—Purpose of the variable. Make sure you include enough information so other testers can understand how the variable is used when recording or running scripts.
- Value Type—Type of values stored in the variable. Text allows you to assign one value to the variable, which is used as the default value. List allows you to add multiple values to the variable.
- Default Value—Default value used when recording or running scripts. The value can be a text string, expression, or value from an associated datasheet.
- Auto-Record Substitution—Automatically replaces all instances of the variable value in scripts and expected values for new windows and controls captured and added to the application repository. Only select this option to replace unique values. If the value is not unique, you may unintentionally replace the wrong value, which can cause scripts to fail.
- Prompt—Displays a dialog box when recording or playback starts so users can enter the variable value to use for the session.
- Click OK to save the variable.