Ask a Question

Data generator question

SOLVED
geneticmaterial
Contributor

Data generator question

Hi

our QA is writing some keyword tests and has asked for me to help provide a solution to give her a different name per keyword test. Sounds easy enough.

At project level, I have generated a list of 1000 firstnames and 1000 surnames using the 'Test > Generate Data' function, these were sent to file.

For each of these I have created a project level variable "from set" using each of those files so each data set has 1000 entries and set the 'generation mode' to random.

However, when I test this and use it in a setText operation it always gets the same value. As if the random selection of values is only ever done once.

 

Can anyone point me in the right direction?

 

I work with readyAPI and there's an almost identical function, however that DOES return a new value randomly from the set each call.

 

1 ACCEPTED SOLUTION

Accepted Solutions
geneticmaterial
Contributor

Re: Data generator question

Figured it out:

use

Project.Variables.randomFirst("randomFirst", Math.floor(Math.random() * 1154))

View solution in original post

7 REPLIES 7
geneticmaterial
Contributor

Re: Data generator question

What we are not doing here is data driven loops inside a single keyword test.

Simply, a new first name and surname will be provided per keyword test so they are differentiated when they are in our backend.

Hope that makes sense.

geneticmaterial
Contributor

Re: Data generator question

Wow, this is infuriating! I've tried almost EVERY single variation of getting data from that data generator in a variable being held on the project variables and even the local variables on the keyword test and literally it always comes back with the same value!

 

The only thing I can get to work here is instead of using a variable is to use setText operation and 'code execution' type using the following code:

Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5)

 

madness!

brumazz
Staff

Re: Data generator question

How are you changing the input of the field you are trying to data drive?

 

Could you provide a screenshot?

 
geneticmaterial
Contributor

Re: Data generator question

Hi, thanks for looking.

I think my issue might be how I am setting this. I can't find the correct syntax to use in the settext input.

save as table.png

save values from set and save as random generation.png

 

name the column and specify the number of rows to generate and save.png

 

the var.png

 

pick param.png

 

select cell.png

 

chosen value.png

 

table.png

 

if I use Project.Variables.randomFirst("randomFirst") I get "Danielle" everytime

Project.Variables.randomFirst("randomFirst", "") enters nothing

Project.Variables.randomFirst("randomFirst", 1) enters the 2nd in the array

using * is invalid.

Any ideas? Thanks

geneticmaterial
Contributor

Re: Data generator question

Figured it out:

use

Project.Variables.randomFirst("randomFirst", Math.floor(Math.random() * 1154))

View solution in original post

AlexKaras
Community Hero

Re: Data generator question

Hi,

 

Excuse me for the late reply...

You have got correct solution.

'Random' mode in the Data Generator just means that data will be generated in a random unordered sequence. But the resulting data table is accessed sequentially unless explicitly specified like in your code.

 

Minor improvement if you don't mind: in order to get rid of hardcoded 1154 value you may use the code like this - 

KeywordTests.CreateContactVerifyAndLogout.Variables.ListNames("FirstName",
Math.floor(Math.random() * KeywordTests.CreateContactVerifyAndLogout.Variables.ListNames.RowCount));

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
geneticmaterial
Contributor

Re: Data generator question

Ah, great, yes that's much more useful!

Thanks for the reply!

Dan

cancel
Showing results for 
Search instead for 
Did you mean: