Forum Discussion
I don't think the data generator wizard will help. In my case, I have a web form I am trying to fill out. There are 3 fields for Year, Make and Model of a vehicle. These 3 fields are combobox fields (Selects, whatever you call them) and I simply need to pick any value available in them.
- boroop9 years agoOccasional Contributor
Building on murugans1011's answer...
The way to do this in a keyword test (which is painful and likely why they've ignored you for over a year) is to setup an integer variable (ensure you set it up as an integer!) that you can populate with a code snippet (yes, you'll need code either way; get over it :smileyhappy: ).
Use the Set Variable Value command in your keyword test and populate it with a code expression of Math.floor((Math.random() * 3) + 1) (this is jscript so it should work similarly in your language in TestComplete)
This will set a random number between 1-3. Want it to be between 1 & 5? Change the 3 to a 5. :smileywink:
Then change the learned combobox selection command to use a variable rather than text. Point it to your variable you setup up above... and this should replay just fine in a keyword test.
Here's my sample:
- boroop9 years agoOccasional Contributor
The better way to do this (in my opinion) is to setup a function that you can call many times. I pass in a set of valid combobox selections, separated by commas, and let the function choose one of them at random and then return it to me.
function ChooseARandomStringValue(StringValues) { // Split the passed in StringValues and put them into an array var IndividualStrings = StringValues.split(","); // Get the arrays length HowMany = IndividualStrings.length; // Pick a random number between 1 - <<<the number of passed in values>>> i = Math["round"](Math["random"]()*(HowMany-1)+1) // The random string is found in the array (zero offset) WhichString = IndividualStrings[i-1]; // Return the single value from the list return WhichString; }
Call it like this: ChooseARandomStringValue("One,Two,Three,Four,Five")
The ComboBox selection command then uses the "Last Operation Result" to choose the proper value (One, Two, Three, Four or Five)(which is passed back as the WhichString return value).
Back in the TestComplete UI, you can drag and drop the script into your keyword test and choose your function from the popup. Set the values to be passed in and let it run.
Congratulations! You just invented the wheel! Now reuse it, don't reinvent it each time. :smileywink:
Related Content
- 4 years ago
- 12 years ago
Recent Discussions
- 9 hours ago