Variables in Scripts

Since Silk Test Workbench uses VB.NET as its scripting language, you can use VB.NET variables in scripts. A variable is a named alias that contains data that can be used and modified during playback.

During recording, any data input against a control is recorded as literal data. For example, when a WPF TextBox control has a value typed into it, the resulting code might look like the following:

.WPFTextBox("@automationId='CarType'").SetText("Ford")

This works, but the script can never use data other than the value Ford in the TextBox control. However, if Ford is replaced with a variable that represents that data, then whatever data is used in the variable will be placed in the TextBox control.

.WPFTextBox("@automationId='CarType'").SetText(sCarmake)

Using variables provides greater testing flexibility because data used in scripts does not have to be constant.

If you declare a variable without a type, Silk Test Workbench generates a message indicating that no type was specified. Silk Test Workbench then uses the Object data type is then used by default. You can use any acceptable VB.NET data type as a variable data type. Rules regarding declaration of VB.NET variables apply when using them in scripts.

For example:

Dim dSalesPrice As Double

Dim iQuantity As Integer

Dim sCarmake As String

When Silk Test Workbench records data input into controls, if the value recorded is in quotes (""), it is usually a String data type and can be replaced with a variable of the String data type.