DéjàClick Script Variables

A prerequisite for using this guide is to be familiar with DéjàClick recording and uploading. If you don't have the DéjàClick toolbar in your Firefox browser, and/or you have never used DéjàClick before, please go to the DéjàClick Quick Start Guide. After you have become comfortable with recording DéjàClick transactions, you'll be able to move on to this more advanced feature.

Script Variables Features

DéjàClick Script Variables are dynamic and can be pinned to a specific monitoring location. Here are several cases of special transaction monitoring requirements that Script Variables could be used to support:

  • Login using a different user_id from each AlertSite monitoring location
  • Execute a registration transaction that requires a unique email address using “built-in” variables
  • Use relative date variables to consistently populate reservations searches with future dates
  • Perform specialized keyword checks; navigate to a different URL depending on the monitoring location

Script Variables are accessed in the Properties Sidebar at the Script level. Variables are constructed from one or more tokens of the following types:

  • static text
  • random text
  • random number
  • auto-increment
  • relative date/time
  • dataset value
  • replay location
  • JavaScript code

The dataset value allows a .CSV type file (comma-separated values) to be imported into the script for referencing required input data when replaying on the local desktop. Other field separator characters may also be used in the dataset file.

  • Note: DéjàClick version 1.3.0.0 or greater is required to use script variables.

To make our examples simple, we'll use www.google.com.

Record a Transaction

First, record a transaction with DéjàClick. Click the Begin recording button Begin_recording.png to power on DéjàClick and start recording.

Click in the Google search bar, enter some text and click Google Search. We'll use name@domain.com for the initial search. When the search completes, click the green Stop Record/Replay button Stop_recording.png to stop recording, and then OK in the confirmation dialog. This records a script containing 2 actions and 2 events.

Click the Replay button Replay_all.png to replay the recording.

Open the Script Results sidebar by clicking the green checkmark Results_Sidebar.png in the DéjàClick toolbar.

The sidebar has 2 parts:

  1. DéjàClick step tree at the top
  2. The Results tab and Properties tab at the bottom

Sidebar_replay.PNG


There are 2 ways to add a Script Variable:

  1. Create it at the Script level,
  2. Create it or add it at the Event level on the Input event

Several steps are required to set up a Script Variable. Once you know what variables you want to use in your recording, it's a simple process.

Creating a Script Variable

To illustrate how to create a script variable, we'll outline the steps for using a random email address in the Google search bar.

Click the Properties tab in the DéjàClick sidebar script tree, and click on the top-level Script name in the tree view at the top.

The sidebar will present the list of properties at the Script level:

Script_level_properties.PNG


Click Variables to open the Script Variables property panel:

Variables_property_panel.PNG


Using this panel, we will construct the script variable from a series of tokens. Click the Add button to display the Add Script Variable dialog:

Add_SV_Dialog.PNG


Enter a name for the script variable - for our example, Random Email Address, then click the Add... button to display the Add Token dialog box:

Add_token.PNG


The Add Token dialog's Type dropdown list contains:

  • Static Text
  • Random Text
  • Random Number
  • Auto Increment
  • Relative Date/Time
  • Dataset Value
  • Replay Location

Note that the Parameters section changes depending on the Type.

We want to create the random email address script variable using 3 tokens:

  • a 4-character random text string,
  • a 3-digit random number, and
  • the static string @mydomain.com

Fill in the Add Token dialog as follows:

  1. Select Type: Random text
  2. Enter minimum length 4 characters
  3. Enter maximum length of 4 characters
  4. Leave the Location ID blank and click OK

Add the next token, the 3-digit random number. Click Add... and fill in the Add Token dialog as follows:

  1. Select Type: Random number
  2. Enter minimum value 0
  3. Enter maximum value 999
  4. Leave Location ID blank and click OK

Create the third and final token, a static string @mydomain.com. Click __Add...* to and fill in the Add Token dialog as follows:

  1. Select Type: Static text
  2. Enter @mydomain.com in the Value: field
  3. Leave Location ID blank and click OK

Click OK to save. The Add Script Variable dialog box will now contain:

All_3_tokens.PNG


Click the Preview... button to display a sample of what the variable will look like during replay, for example:

preview1.PNG


Click OK to dismiss the preview box, then click OK to complete the script variable construction. The Variables panel will now contain the Random Email Address script variable.

You can now select this script variable in the Event Input panel for the Input HTML Element event, which is the search field text:

Select_Event_Input.PNG


You can also add a Script Variable directly in the Event Input panel of an Input HTML Element event by clicking the icon to the right of the Select... field:

Create_from_Event.PNG


By using the script variable in place of the original search term, each replay will produce a search for a different email address:

Replay 1:

Search1.PNG


Replay 2:

Search2.PNG


Note the change in email address each time the recording is replayed, created by concatenating the 4-character token, 3-digit token, and static string @mydomain.com.

Additional Examples

Below are more examples for using script variables:

Script Variable as a Keyword

Under certain circumstances, your web page may render differently from one location to another. For example, say you monitor from Los Angeles - Level 3, NY - Peer 1, and London - AboveNet, and your page has the title Labor Relations, which you want to use as the keyword phrase.

However, when the page is tested in London, the title becomes Labour Relations because your hosting server detects that it's a UK location and renders the same content but with UK spellings. You can set up a script variable to select a different keyword when it's tested on the London monitoring station.

You will need to fill in the Location ID field in the Add Token dialog box. Location IDs are found in the Console Help dialog screen Monitoring Location IP Addresses.

After recording your script, do the following:

  • Click on the script name in the sidebar to get to script level
  • Click Variables in the Properties tab to open the panel
  • Click Add to open the Add Script Variable dialog box (same as in Example 1)
  • Enter a name for the variable, e.g., KW Labor or Labour
  • Click the Add... button to bring up the Add Token dialog box (same as in Example 1)
  • Leave the default Type Static text
  • In the Parameters field, enter the keyword Labor Relations
  • In the Location ID: box in the Limit token to field, enter 42 for Los Angeles
  • Click OK to add the token
  • Click Add... again in the Add Script Variable dialog and add another Labor Relations static token, but enter 70 in the Location ID: box for New York, then click OK to add the token
  • Click Add... one more time to create our third static token, but this time enter Labour Relations in the Parameter field, and 5010 for London in the Location ID: box, then click OK.
  • The Add Script Variable dialog will contain:

Variable_kw.PNG


  • Click OK to add the variable. The script sidebar will contain the new script-level variable:

Variable_kw_sidebar.PNG


Note the checkbox labeled Calculate variable only once (sticky value) in the Add Script Variable dialog. Checking this box will maintain the value of the variable throughout the recording. For example, if you want to use the same value in Steps 2, 5 and 8, check the box and the variable will be calculated in Step 2 and the same value used in Steps 5 and 8 during the same monitoring interval.

Next, let's create our Keyword Validation. Keywords may be added to either Actions or Events. In this example, let's add our keyword to the first event

  • Highlight the event Navigate URL (Event 1 of Action 1 in this example) and click Keyword Validation in the Properties tab to expand the property panel:

Variable_kw_property.PNG


  • Click Add to open the Add Keyword Validation dialog box
  • Check the box next to Use variable: and in the Select... dropdown, choose KW Labor or Labour

Select_Variable_kw.PNG


  • Click OK to add the script variable Keyword Validation

Variable_kw_set.PNG


Subsequent replay will succeed with keyword Labor Relations when monitored from LA or NY, and with Labour Relations when monitored from London.

Location-Limited Tokens

One monitoring strategy may be to populate your web form with different strings when monitoring at different locations. For this example, we'll use the Google Search script from Example 1. We'll construct a script variable using tokens that are limited by our 3 monitoring locations, Los Angeles (Location ID 42), New York (Location ID 70), and London (Location ID 5010).

For illustration purposes, our script variable will be created with 5 static string tokens:

ABC
DEF
GHI
JKL
MNO

String DEF will be limited to Los Angeles, GHI will be limited to New York, and JKL limited to London. Strings ABC and MNO will not be limited to a specific monitoring station. As such, the search strings you will see in the Google Search box are:

Location (ID)

Search String

Los Angeles (42)

ABCDEFMNO

New York (70)

ABCGHIMNO

London (5010)

ABCJKLMNO

First, create a Script Variable called Location-Limited Search String and add 5 tokens:

  • From the Script Level, click Variables to expand the property panel, then click Add
  • In the Add Script Variables dialog, enter the Script Variable name and click Add
  • Leave Type as Static text
  • In the Parameters section, enter Value: ABC, leave the Location ID: field blank, then click OK
  • Click Add again, leave as Static text, enter Value: DEF, enter Location ID: 42, then click OK
  • Click Add, leave as Static text, enter Value: GHI, enter Location ID: 70, then click OK
  • Click Add, leave as Static text, enter Value: JKL, enter Location ID: 5010, then click OK
  • Click Add, leave as Static text, enter Value: MNO, leave Location ID: blank, then click OK

The Add Script Variable dialog will look like:

Loc_ltd_variable.PNG


Note the icon to the left of each token. The Location Limited token icons have a red "flag" indicator.

  • Click OK to add the variable. The script sidebar will contain the new script-level variable Location-Limited Search String.

The next step is to set the Event Input to use the script variable.

  • Click on the Input HTML Element event in the Scripts section of the sidebar
  • In the script Properties tab, click Event Input to expand the property panel
  • Check the box next to use script variable
  • Select Location-Limited Search String from the dropdown and click Apply

The sidebar will appear as:

Loc_ltd_sidebar.PNG


The script will produce different searches using the different search strings based on the monitoring location. We can simulate running from different locations by modifying a configuration option. Set the DéjàClick Display Level to Advanced, then:

  • Click on the Configure Options button Config_Options.png and select DejaClick Options
  • Click on the Replay Properties tab
  • Click Variable Options to expand the property panel
  • In the Default Location ID box, enter the desired Location ID ( 42 for LA, 70 for NY, 5010 for London)
  • Click OK to save

The DéjàClick Options dialog will look like this:

Variable_config_42.PNG


After changing the Default Location ID to 42, replay the script to produce:

Loc_42_replay.PNG


Change the Default Location ID to 70, and the replay will display:

Loc_70_replay.PNG


Change the Default Location ID to 5010, and the replay will show:

Loc_5010_replay.PNG


Example using Dataset Script Variable

NOTE: This feature is supported on the Desktop plug-in only. It is not supported in the AlertSite monitoring locations.

If your recording includes filling in a form, you can create a file, called a dataset, that contains the information for the form. Script variables can be configured to selectively parse the dataset for the data values to use.

As an example, we will record a few steps that includes filling out a form with multiple fields. We arrive at the page below by recording http://smartbear.com/products/web-monitoring/website-monitoring/alertsite-trial-sign-up and filling in the first 4 fields:

Dataset_step1.PNG


The first Input HTML Element event in Action 3 of the recording corresponds to the "all these words" field and the second Input HTML Element event corresponds to the field for "this exact wording or phrase". The search strings "name" and "type" are simply placeholders for the recording.

Create a text file with an equal number of comma-separated set of strings on two lines:

horse,tiger,mouse
palomino,white,tiny

Note: This file must reside in the directory configured for Datasets in the Configuration Options Paths dialog:

Config_opts_paths.PNG

To select a different location for Datasets, click on "Change..." next to the Dataset Folder field and select or create a different directory.


For this example, we'll call this text file dataset1.csv. The Dataset Script Variable will be configured to rotate through the first row for the first Input HTML event and the second row for the second Input HTML event.

First, let's import our dataset data into the script:

  • Click on the top step in the Script steps section of the sidebar to get to script level (Script Variable Example 2 in the screenshot above)
  • Click on the Properties tab in the lower section of the sidebar
  • Click on Datasets in the list of Properties to expand the item
  • Click the Add button to add dataset information

Add_dataset.PNG


  • In the Name field of the Add Dataset dialog, enter a name for your dataset, e.g., animals
  • Click Choose... to select the filename dataset1.csv you created above
  • Leave the Import dataset into script option checked
  • Click Preview... to verify the dataset looks correct
  • Click OK

The dataset animals with the values in dataset1.csv is now associated with the script. The next step is to have two of the input fields configured to utilize the data in the dataset. So our next step is to create two script variables and assign them to the two input fields.

  • Click on the Input HTML Element line in the script tree window at the top of the sidebar; we'll use the First Name field Input Element for this example
  • Click Event Input in the Properties tab at the bottom of the sidebar to expand the item
  • Click the checkbox next to Use script variable
  • Click the Create a new script variable icon to the right of the Select... dropdown
  • Enter a name, e.g., animal names, in the Name field of the Add Script Variable dialog
  • Click the Add... button to add a token
  • In the Add Token dialog, select Dataset value from the Type dropdown
  • animals (2x3) will populate the Dataset parameter field since it was added at the script level (2x3 refers to the number of rows and columns in the dataset file)

Note: You may also add new datasets from within the Add Token dialog box if you desire.

  • Enter 1 in Start row, since this Input HTML Element uses the first row in the dataset file
  • Enter 0 in Increment next to Start row, since you want to stay on this row through each replay
  • Enter 1 in Start column, since this is the column you want to start with
  • Enter 1 in Increment next to Start column, since you want to move to the next column in this row with each replay

The Add Token dialog will look like this:

Add_dataset_token.PNG


  • Click OK to add the token to the script variable
  • Click OK to save the script variable within the script
  • Click Apply in the Event Input properties to apply the script variable to this input field

To use the dataset input for the Input HTML Element Last Name field, repeat the steps above with the difference being the name of the script variable and start row.

  • Click on the Last Name Input HTML Element line in the script tree at the top of the sidebar
  • Click Event Input in the Properties tab at the bottom of the sidebar to expand the item
  • Click the checkbox next to Use script variable
  • Click the Create a new script variable icon to the right of the Select... dropdown
  • Enter a name, e.g., attributes, in the Name field of the Add Script Variable dialog
  • Click the Add... button to add a token
  • In the Add Token dialog, select Dataset value from the Type dropdown ( animals (2x3) will already appear in the Dataset parameter field)
  • Enter 2 in Start row, since the second HTML Input Element field is for the second row in the dataset file
  • Enter 0 in Increment next to Start row, since you want to stay on this row through each replay
  • Enter 1 in Start column, since this is the column you want to start with
  • Enter 1 in Increment next to Start column, since you want to move to the next column in this row with each replay

The Add Token dialog will look like:

Add_dataset_token2.PNG


  • Click OK to add this token to the script variable
  • Click OK to save the script variable within the script
  • Click Apply in the Event Input properties to apply the script variable to this input field

You are now ready to replay the recording using the dataset values as input. Replay the recording 3 times, and you will see the two input fields change tokens automatically, as shown below:

First replay:

DS_replay1.PNG


Second replay:

DS_replay2.PNG


Third replay:

DS_replay3.PNG


To start with the initial set of tokens (horse, palomino), reset the current replay count as follows (this is entirely optional):

  • Click on the Configure Options button Config_Options.png in the DéjàClick toolbar
  • Select Configure Settings
  • Click on the Replay Properties tab
  • Click Reset on the Variable Options line

Additional Information

Reusability

Script variables and datasets, once created, may be reused in different parts of the recording by assigning them to additional input values or keywords. For example, here is a list of several script variables that were created:

Existing_variables.PNG


You can select to use a different set of variables for the HTML input in your script by simply clicking on the Input HTML Element you want the variable to appear in and select the new variable from the drop-down list.

Imported vs. External Datasets

There are two flavors of Datasets: Imported and External File. External dataset files must reside in the DéjàClick datasets subfolder prior to replay. By default, the folder is located in your Firefox profile folder under the dejaclick directory, but the path may be changed via the DéjàClick Options->Paths tab.

The dataset is designated as an external file if the Option Import dataset into script is deselected in the Add Dataset dialog (see Search using datasets above).

Internal datasets are imported directly into the script. Its referenced values remain static; any changes to the original source file will not affect subsequent script replays. Conversely, the external datasets reference an external file. Thus, if the file is ever modified, any referenced values that are updated will use the new values during subsequent script replays.

Here is the Datasets Properties sidebar at the Script Level with a description of the two different dataset types. The celebrities dataset is external and contains 3 sets of celebrity names:

2_DS.PNG celebrities.PNG

Setting the First and Last names in the form fields to use the external dataset with the original values displays the following on replay:

DS_replay4.PNG


After editing one of the values (last name of the first celebrity), the dataset looks like:

celebrities_mod.PNG


Replay with this new field value shows the modification:

DS_replay4_mod.PNG

 

Back to Top