Ask a Question

Trying to select a random value from a data source

bev77
New Contributor

Trying to select a random value from a data source

 Hi

 

I'm running a test whereby I fill out a form that requires first name, last name, email address. I don't want a data loop as I'm only completing the form out once. 

 I found this post which I thought was going to work.

https://community.smartbear.com/t5/TestComplete-Questions/Picking-a-random-row-from-a-dataset-as-par...

 

However when executing the test it fails for the following reason 'Unable to evaluate the operation's "Text" parameter. Error: ReferenceError: Variables is not defined'.

I've set my value in the test as per this post as a code expression

Variables.Names("Name", KeywordTests.addEmployeePage.Variables.CurrentNumber)

I'm new to TestComplete so not sure if I've done something wrong or its not possible to select a one off random value from a data source?

 
Thanks
Ian
 
 
 
3 REPLIES 3
ebarbera
Staff

Hi @bev77 - 

 

Would it be possible for you to send an image of the step in your testcase? My guess is it is some type of syntax issue .

 

Thanks,

Emma

bev77
New Contributor

Hi 

So I'm 1st setting a variable of 'CurrentNumber' to get a random number with this line of code

Math.floor(Math.random() * 100) + 1

 

Then I'm using the SetText operation with this command as a mode of Code Expression (which I'm assuming is the correct one to use?) to add the text from either a data table or excel spreadsheet that contains a list of names. I'm using the number variable 'CurrentNumber' to select the random name.

 

Variables.Names("Name", KeywordTests.addEmployeePage.Variables.CurrentNumber)

 

Hope this makes sense

Thanks

Ian

 

 

 

 
npaisley
Staff

Hi @bev77!

 

This is actually from an error in how the related post was built out. 

 

TestComplete will truncate the 'Values' to save screen real estate, this means the code snippet in the linked doc is technically incomplete. 

 

Below is what TC will show you of that code expression once you have clicked out of it, notice that it matches the doc;

npaisley_0-1652905997413.png

 

Though if we click on the 'Value' for the textBox step, we see the entire value = 

npaisley_1-1652906048512.png

 

The correct code expression should be = 'KeywordTests.Test1.Variables.Random(....'

 

Essentially we are missing the location of the variable in the image that is present in the linked doc.

 

Sorry for the confusion, I hope this helps to clear things up!


Regards,
Nick

Solutions Engineer @ SmartBear
cancel
Showing results for 
Search instead for 
Did you mean: