Forum Discussion
6 Replies
- flightvanNew ContributorHi Mark,
in your case I would prefer to click on the first item in combobox object, like this: comboboxObj.ClickItem(0). Otherwise, instead of zero, you can use random integer value from items count range by writing code snippet in language that you selected. - murugans1011Regular ContributorAs Ivan suggested if u want to click random item. then u can get the max no.of combobox items and generate random integer to click random item something lik this
[VBScript]
max=combobox.wItemCount-1 'gets the total no.of items
min=0
Randomize
rndNo=(Int((max-min+1)*Rnd+min))
combobox.ClickItem(rndNo) 'Clicks the random item
- TanyaYatskovskaSmartBear Alumni (Retired)Hi Mark,
To generate random data, you can use TestComplete's Data Generator. Read the "Data Generator Wizard" article for more information. - mfoster711Regular ContributorIvan or Murugan, how do I do either of those from a Keyword Test?
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.- boroopOccasional 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:
- boroopOccasional 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
- 3 years agoramprabhus
- 12 years agos5h
Recent Discussions
Check PopupMenu exists
Solved7 hours agomfoster711- 2 days agosimonaferrara
- 2 days agomacheshmeh