Rasilio
13 years agoNew Contributor
Confusing script result
Ok, just starting out with SOAPUI and trying to learn my way around it and I am seeing some very unusual results with a script test step which is designed to generate a random alpha-numeric string and set a property equal to it.
Here is the code...
int chrType = 0;
StringBuffer sb = new StringBuffer();
for (int x = 0; x < 7; x++)
{
chrType = (int)(Math.random()*3);
switch (chrType) {
case 0: sb.append((char)((int)(Math.random()*10)+48));
case 1: sb.append((char)((int)(Math.random()*26)+97));
case 2: sb.append((char)((int)(Math.random()*26)+65));
}
}
testRunner.testCase.testSuite.setPropertyValue('MyProp', sb.toString())
Now according to everything I know this should always give me an 8 character alpha numeric string, however here were the results I got on 5 consecutive runs...
2pUeR7sF0cLtSJmM
FP4mZ1xDgW4rQ1xN
IwLRAeIpKU
NbX3nT7lVLKT
TCC7sFR9sPF
So the randomization is all working, the problem is that I am getting a random number of characters every time.
Does anyone have any clues as to why this is happening?
Here is the code...
int chrType = 0;
StringBuffer sb = new StringBuffer();
for (int x = 0; x < 7; x++)
{
chrType = (int)(Math.random()*3);
switch (chrType) {
case 0: sb.append((char)((int)(Math.random()*10)+48));
case 1: sb.append((char)((int)(Math.random()*26)+97));
case 2: sb.append((char)((int)(Math.random()*26)+65));
}
}
testRunner.testCase.testSuite.setPropertyValue('MyProp', sb.toString())
Now according to everything I know this should always give me an 8 character alpha numeric string, however here were the results I got on 5 consecutive runs...
2pUeR7sF0cLtSJmM
FP4mZ1xDgW4rQ1xN
IwLRAeIpKU
NbX3nT7lVLKT
TCC7sFR9sPF
So the randomization is all working, the problem is that I am getting a random number of characters every time.
Does anyone have any clues as to why this is happening?