python-2.7 - 使用Robot Framework在同一文件中测试多个用户登录

标签 python-2.7 robotframework

我的目标是使用 Robot 获取登录凭据列表并迭代该列表,登录到页面并从本质上证明这些用户可以看到该页面。

根据我的发现,我需要使用模板,但是当您在同一个机器人文件中拥有要使用的所有值时,我还没有发现很清楚如何实现模板。

我一直在使用https://github.com/robotframework/QuickStartGuide/blob/master/QuickStart.rsthttp://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#data-driven-style

根据这个例子,他们有:

Templated test case
    [Template]    Example keyword
    first argument    second argument

它们没有明确显示设置数据以运行测试的示例。

这是我到目前为止所拥有的:

*** Settings ***
Documentation  Test Access Levels of the new Page
Library  Selenium2Library
Test Template  Security Login Test

*** Test Cases ***

All Users Login Test
  Security Login Test  Login Test
  User1  Pass1
  User2  Pass2
  User3  Pass3    

*** Keywords ***
Enter User Name
    input text  working_username_field    need_to_put_username_here
Enter Password
    input text  working_password_field    need_corresponding_password_here
Click Login
    click element  working_login_button
Enter Store Number
    input text  working_store_field working_store_number
Click Search
    click element  working_search_button
Login Test
        open browser  working_url Chrome
        enter user name
        enter password
        click login
        enter store number
        click search
        go to   working_sub_url

我不知道的是如何将这些参数放入我的关键字中,以便它会遍历每个参数。

我知道我可以使用一个文件来实现此目的,但这似乎稍微复杂一些,所以我想首先找到这种方法。

感谢您提供的任何帮助!

最佳答案

当您使用套件级模板时,每个测试用例通常是一行。第一列是测试用例名称,其他列是模板关键字的参数。

例如:

*** Settings ***
Test Template    Security Login Test

*** Test Cases ***
# test case name  # username                 # password      
Normal user       <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee84818bc09b9d8b9cae8b968f839e828bc08d8183" rel="noreferrer noopener nofollow">[email protected]</a>       test123
Admin user        <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="483b2924243166292c252126082d30292538242d662b2725" rel="noreferrer noopener nofollow">[email protected]</a>    abc123
Banned user       <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e7c716c776d307c7f7a796b675e7b667f736e727b307d7173" rel="noreferrer noopener nofollow">[email protected]</a>   knockknock

*** Keywords ***
Security Login Test
    [Arguments]  ${username}  ${password}

     Enter username  ${username}
     Enter Password  ${password}

     The rest of your code here...

Enter username
    [Arguments]  ${username}
    log  entering username '${username}

Enter password
    [Arguments]  ${password}
    log  entering password '${password}'

The rest of your code here...
    log  another keyword

关于python-2.7 - 使用Robot Framework在同一文件中测试多个用户登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44721165/

相关文章:

python - 机器人框架 : Unable to get keywords from class with __eq__ method

python - Robot Framework : How to know that variable is list, 字典或正则

python - 如果脚本停止工作但仍显示在主管下运行,如何重新启动脚本

python - 进行与 python 中的定义相关联的选择

python - python 执行程序在哪里?

java - 创建字典并将其作为映射传递给 Robot Framework 中的 Java 方法

list - 变量 '@{credentials}[0]' 的值不是列表或类列表

python - 使用 Python Azure SDK 列出 Azure 中的位置时出现错误

javascript - 如何在 robotsframework 中将 "10.000,50"这样的字符串转换为 float 10000.50

python - 是否可以在不使用 jenkins 上的 "PyAutoGUI"库的情况下使用键盘操作?