“机器人框架”的“字符串库”中的“生成随机字符串”关键字,用于分配给变量

时间:2014-03-03 01:50:54

标签: testing random automation robotframework browser-automation

我需要生成随机数并将其分配给变量一次,以便以后多次使用它。我找到了关键字Generate Random String,但我不知道如何将其应用于我的案例。

1 个答案:

答案 0 :(得分:7)

以下是一个例子:

*** 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}

以及执行它时得到的结果:

[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
[...]

另一个执行会生成另一个随机数:

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