【问题标题】:"Generate Random String" keyword in String Library of Robot Framework for assigning to variableRobot Framework字符串库中的“生成随机字符串”关键字用于分配给变量
【发布时间】:2014-03-03 01:50:54
【问题描述】:

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

【问题讨论】:

  • 为什么生成随机字符串不合适?
  • 哦,我的意思是我不知道如何应用它。对不起)
  • 好的,那你的情况如何?你能发布你迄今为止尝试过的东西吗?通常,您只需将该关键字的输出分配给一个变量并照常使用该变量。所以${random strig} Generate Random String
  • 我想用随机密码创建一个用户,将其分配给变量并在使用此密码登录后。

标签: testing random automation robotframework browser-automation


【解决方案1】:

这是一个例子:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2011-06-30
    • 2014-03-07
    相关资源
    最近更新 更多