Generate Random Number
I would like to generate a random number in Test Studio. This number will be used in an input control or for a similar purpose.
Solution
This is possible with a coded solution. The .NET Framework provides the System.Random class which can be used to generate random numbers.
In this example, we'll navigate to this Telerik demo page and use the DataPager control to navigate to a random page number between 1 and 10.
ActiveBrowser.NavigateTo("http://demos.telerik.com/aspnet-ajax/datapager/examples/firstlook/defaultcs.aspx");
System.Random random = new System.Random();
int randomPage = random.Next(1, 11);
Find.ByExpression<HtmlInputText>("id=~TextBox_text").Text = randomPage.ToString();
Find.ByExpression<HtmlInputControl>("id=~GoToPageButton").Click();
ActiveBrowser.NavigateTo("http://demos.telerik.com/aspnet-ajax/datapager/examples/firstlook/defaultcs.aspx")
Dim random As New System.Random()
Dim randomPage As Integer = random.[Next](1, 11)
Find.ByExpression(Of HtmlInputText)("id=~TextBox_text").Text = randomPage.ToString()
Find.ByExpression(Of HtmlInputControl)("id=~GoToPageButton").Click()