Random selection is it possible?


#1

Hi guys,

Question !!! I have two users whose data are different and are packed in separate modules, depending on the user, the whole test process is different, is it possible to randomly select a user?

Best Irina


#2

Hi Irina,

In short, the answer is ‘NO; at least not easily’.

Script Developer was designed as tool for functional testing. In this context, it is strongly recommended that each test scenario is designed as strict linear sequence of atomic actions that tests no more than one feature or aspect of a feature. Otherwise, you’ll risk to dilute the meaning of your tests; you know that they are doing something but you do not exactly know what they test. This is especially true in case of failures.

So, when you say that the test process is different for both users then you have two different tests that both have their own test data.
And, this would also eliminate the need for conditional module calls as you know which modules to call beforehand.

Even if the test process would be the same, then you wouldn’t randomly select one user but define two data-sets and choose which sets should be used for running the test.

Hope that helps. If not, I’d like you to explain your use case in more detail (esp. what did mean with ‘packed into separate modules’?)

Thanks,
Hartmut


#3

Hi Hartmut,
“what did mean with 'packed into separate modules” I have not expressed myself clearly, sorry . I meant one Modul with different parameters for each user :slight_smile:

Thanks for your help ,

Irina


#4

Thanks for your explanation, Irina.
But my last comment still holds: as long as the test processes (or execution paths) differ for both users, you’ll have two separate tests.

Does this work for you or do you still have the need to a pick a user randomly?


#5

:slight_smile: Not real the need ,it was only my idea for testing two different checkout (CO) processes. And each CO functionality or process is depend on user-data. my idea was like : "randomly select User 1or User 2 —>>
IF User 1 read COmodule1 " or “IF User 2 read COmodule2” something like that

of course 2 test cases is an solution too :slight_smile:


#6

Well, even if you could select one user randomly, you cannot call modules dynamically. This means that would have to call both checkout modules in a row and each call has to be done conditionally in order to exclude one from the other:

  • Pick a user from the list [“bob”, “anne”].
  • COmodule1 IF ${user} == “bob”
  • COmodule2 IF ${user} == “anne”

And this code is definitely not easy to read, understand or maintain.

Thus, I strongly recommend to put this into two separate test cases OR export your scripts to Java which allows you to use nifty things such as loops, conditionals, data providers, randomization and much more.

For sake of completeness, if you really want to pick a user randomly, you can do it the hackish way via JavaScript as part of a storeEval command:

(function(){
  var users = ["bob", "anne"];
  return users[${RANDOM.Number(users.length)}]
}()

This option is only applicable when you have JavaScript programming skills and you know what you’re doing.


#7

Hartmut thanks a lot


#8

Hi Hartmut,

if i use "${RANDOM.Number(users.length)"i got all time “undefined” i tried with:
“return users[Math.floor(Math.random()*users.length)]” and it works :slight_smile:

Best , Irina


closed #9

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.