This is a migrated thread and some comments may be shown as answers.

random number used in byValue

3 Answers 120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jurij
Top achievements
Rank 2
Jurij asked on 27 Mar 2015, 10:36 AM
Hello, first time posting here. I have a case where I want to generate a random number and use it in byValue selection. To be more specific, first I want to generate a random number on the fly (I used your VB code found in: http://docs.telerik.com/teststudio/advanced-topics/coded-samples/general/generate-random-number), then use this number to pick the number available from the dropdown menu.

I searched all over the docs, here and found nothing that would be useful to me. Example what I have in the test:

1. ...

2. Extract selection 'ByValue' on 'PriceCat' into DataBindVariable $(PriceCatValue)

3. [Add_to_cart_CodedStep1] : Generate random number between 1-5 $(randomNr):
         
          Dim random As New System.Random()
          Dim randomNr As Integer = random.[Next](1, 5)

4. Select 'ByText' option '1' on 'PriceCat' - DataDriven: [$(PriceCatValue)] <- here I want to use randomNr instead of "option '1'", like for example "option '$(randomNr)'"

Hopefully I'm specific enough.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 01 Apr 2015, 08:07 AM
Hello Jurij,

You don't need to use both (i.e. Data Driven and the random number). You should use one of them.

Here is an example code how to achieve it with the random number:

Dim random As New System.Random()
Dim randomNr As Integer = random.[Next](1, 5)
yourSelectElement.SelectByText("option " + randomNr.ToString(), True)

This is the example of SelectByText. SelectByValue works in the same way.

Hope this helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Jurij
Top achievements
Rank 2
answered on 01 Apr 2015, 08:23 AM
You have made my day! Thank you, this works now as I have expected.

BR, Jurij
0
Boyan Boev
Telerik team
answered on 01 Apr 2015, 10:34 AM
Hi Jurij,

I very happy to hear that.

If you need additional assistance please let us know.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Jurij
Top achievements
Rank 2
Answers by
Boyan Boev
Telerik team
Jurij
Top achievements
Rank 2
Share this question
or