Daniel-yip
17 years agoOccasional Contributor
How to transfer some output to properties
I was find a java coding and I want to use the output value for properties transfer, however I don't know how to do. Can you teach me? Thanks
import java.util.Random;
/** Generate random integers in a certain range. */
public final class RandomRange {
public static final void main(String[] args){
log("Generating random integers in the range 1..10.");
int START = 100;
int END = 256;
Random random = new Random();
for (int idx = 1; idx <= 10; ++idx){
showRandomInteger(START, END, random);
}
log("Done.");
}
private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Generated : " + randomNumber);
}
private static void log(String aMessage){
System.out.println(aMessage);
}
}
--------------------------------------------------
I was using following coding, but it not work.
def props = testRunner.testCase.getTestStepByName("Properties");
props.setPropertyValue("randomValue", randomNumber)
import java.util.Random;
/** Generate random integers in a certain range. */
public final class RandomRange {
public static final void main(String[] args){
log("Generating random integers in the range 1..10.");
int START = 100;
int END = 256;
Random random = new Random();
for (int idx = 1; idx <= 10; ++idx){
showRandomInteger(START, END, random);
}
log("Done.");
}
private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Generated : " + randomNumber);
}
private static void log(String aMessage){
System.out.println(aMessage);
}
}
--------------------------------------------------
I was using following coding, but it not work.
def props = testRunner.testCase.getTestStepByName("Properties");
props.setPropertyValue("randomValue", randomNumber)