The Gwen API provides a means for doing variable substitution at run time, so you can do things like share common component locators and further aid automation.

You can define a variable anywhere in the test file in the following way:

define {my_variable} as Anything you want

Any time you use the text {my_variable} anywhere in the test file, that occurrence will be replaced by the text that came after the word “as” when the test is run.

For example the following test with variables:

define {bottles_field} as input by name "bottlesField"
define {initial_bottles_value} as "99"

test "Test Variables"
url {base_url}/form4.html
browsers Chrome
begin test
	assert that {bottles_field} is {initial_bottles_value}
	clear {bottles_field}
	type "100" into {bottles_field}
	assert that {bottles_field} is "100"
end test

… result in the following test getting executed at run time:

test "Test Variables"
url {base_url}/form4.html
browsers Chrome
begin test
	assert that input by name "bottlesField" is "99"
	clear input by name "bottlesField"
	type "100" into input by name "bottlesField"
	assert that input by name "bottlesField" is "100"
end test