-
-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Number token placeholder limit by length #245
Comments
@authorjapps I've picked this up I've created a HashMap to store all the numbers generated for a specific length in the current session. The only downside to the approach is that the user can't generate different IDs in the same step in a scenario but I don't see that as an issue from my side as the user could create another step to use a new random number. Main chunk of the code is below: I've tested the implementation using the `HelloWorldGitHubSuite" test and I've confirmed that a unique number is generated across all of the steps/scenarios. My only outstanding Q is what would be best to return if the user has ran out of unique numbers, i.e. ${RANDOM.NUMBER:1} and they have executed more than 9 tests then the next number would be 10 which is two characters long, I'm presuming it'd be easier to throw an exception or would you prefer a warning to be thrown? Maybe this is a Q for the OP @dinesh76in Thanks |
If random number generation of a fixed length is the requirement here then something like this can be done. public static void main(String[] args) {
int length = 3;
int lowerBound = (int) Math.pow(10, (length -1));
int upperBound = (int) Math.pow(10, length);
System.out.println("lower - > " + lowerBound );
System.out.println("upper - > " + upperBound );
int random = ThreadLocalRandom.current().nextInt(lowerBound, upperBound);
System.out.println("random --> " + random );
} Why we need a hashmap? Is there anything I am missing from the requirement? @dinesh76in @jneate |
@jneate, @santhoshTpixler , Thanks!
|
@jneate ,
That's the default behavior. That won't cause any issues(we are giving an extra handy stuff as part of this issue), e.g.
Even in case, a test-engineers want to make both random, he can simply execute a Java method anyways!
resolved as below(so we are good here I think),
And to keep the solution simple, it shd be good enough to use |
Sorry about the delay, my work was pretty hectic. @authorjapps @dinesh76in - Myself and @santhoshTpixler took the conversation offline in Gitter over the course of a few days, as @santhoshTpixler mentioned, the Random method doesn't guarantee uniqueness therefore if the generated number has to be unique then we need to keep track of the numbers previously generated hence the HashMap. Admittedly the chances are slim but in theory it could happen where the Java random method generates the same number twice, I'm more than happy to change the above implementation to use the Random method then we just need to be clear in the documentation that the We should also include the max LENGTH in the documents, using the @dinesh76in - Thanks for the update, it helped clarify a few things. |
@jneate you can raise a pull request with the discussed changes. |
Thank you both @jneate , @santhoshTpixler for the solution around this. @jneate , for the below issue, we will raise a Tech-Debt(you can pick it when you get chance)-
@santhoshTpixler, can you cover PR with unit tests, please? And a Wiki Page around this will help everyone as @jneate suggested!
Wiki(TODO) link is here: Already added an example into the http module. 👍 |
Available in version |
Hello Folks,
I am looking for a number token place holder which can resolve to a
random number
, but limited by length/size.e.g.
This will help me to create some custom ID etc where the number is just a suffix or prefix.
e.g.
The uniqueness need not be guaranteed across multiple session, but yes, (guaranteed) for the same JVM session
Update(21-Jun-2019, Friday):
In this case, my team(basically testers)'s responsibility is to make sure they choose a good length, rather than just 1 digit.
In a scenario having
n
number of steps, if this place holder is usedn
times, once in each step, then alln
places will be replaced by different random numbers(not the same onen
times).Our current test usecase is - we have a 2 digit random number requirements to generate people's identity with a
Text + Number
pattern, where we will randomize both text and numberThe text was updated successfully, but these errors were encountered: