Generate Random Text

I would like to generate random text in Test Studio. This text will be used in an input control or for a similar purpose.


There are two possible approaches: with or without code.

Without code

See our article on the Extraction feature.

With code

The .NET Framework provides the System.Random class which can be used to generate random text.

In this example, we'll navigate to and enter random text into the search box.


//Define the length of the text
int length = 8;
//Define the included characters
string charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

Random random = new Random();
string randomText = new String(Enumerable.Repeat(charSet, length).Select(set => set[random.Next(set.Length)]).ToArray());

Find.ById<HtmlInputText>("sb_form_q").Text = randomText;

'Define the length of the text
Dim length As Integer = 8
'Define the included characters
Dim charSet As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Dim random As New Random()
Dim randomText As String = New [String](Enumerable.Repeat(charSet, length).[Select](Function([set]) [set](random.[Next]([set].Length))).ToArray())

Find.ById(Of HtmlInputText)("sb_form_q").Text = randomText
Find.ById(Of HtmlInputSubmit)("sb_form_go").Click()
In this article
Not finding the help you need? Improve this article