0

I need to generate random number and assign it to the variable once to use it multiple times later. I found keyword Generate Random String but I don't know how to apply it for my case.

4
  • Why Generate Random String is not suitable?
    – Harri
    Mar 3, 2014 at 6:08
  • Oh, I mean I don't know how to apply it. Sorry)
    – Kirill
    Mar 3, 2014 at 9:11
  • Okay, then what is your case? Can you post what you have tried so far? In general you just assing the output of that keyword to a variable and use that variable as usual. So ${random strig} Generate Random String
    – Harri
    Mar 3, 2014 at 9:21
  • I want to create a user with random password, assign it to the variable and after log in with this password.
    – Kirill
    Mar 3, 2014 at 9:26

1 Answer 1

10

Here is an example:

*** Settings ***
Library  String

*** test cases ***
login with random string
    ${password} =  Generate Random String  8  [NUMBERS]
    login to system  login  ${password}

*** Keywords ***
login to system    
    [arguments]  ${login}  ${password}
    log to console  \nattempting to log with login ${login} and password ${password}

and what you get when you execute it:

[MBP]$ pybot ts.txt
==============================================================================
Ts
==============================================================================
login with random string                                              .
attempting to log with login login and password 30865042
login with random string                                              | PASS |
------------------------------------------------------------------------------
Ts                                                                    | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
[...]

another execution would generate another random number:

[MBP]$ pybot ts.txt
[...]
login with random string                                              .
attempting to log with login login and password 88780307
login with random string                                              | PASS |
------------------------------------------------------------------------------

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.