2

在我的 Web 应用程序中,我必须更新 25 个字段才能创建用户。Excel 中的测试数据有一个包含 100 个用户的列表,其中包含所有 25 个字段的必填信息。

使用 Robot 框架,测试脚本的编写方式是从 excel 中读取单行(单个用户信息)并更新 Web 应用程序中的所有相应字段。

如果我只想更新 10 个字段(或“n”个字段),如何在脚本中处理它?在此处输入图像描述

注意:要更新的字段可能会根据测试用例而改变。

4

1 回答 1

1

根据我对您的情况的了解,这对机器人来说不是一件容易的事。但是,有一个相当简单的方法来处理这个问题,方法是拥有一个通用测试脚本和特定于案例的 excel 文件。

  1. FieldName使用并TabName能够在页面上找到输入来填充您的 excel 电子表格。我这样做的方法是:

表格1

  1. 使用 ExcelLibrary 将 TabName、FieldName 和 Value 检索到一个列表中(你似乎比我更熟悉它的使用,所以我把它留给你)。作为此步骤的结果,您将获得一个包含 3 个项目的列表,例如${SingleFieldOfSingleUser} # ['Tab1', 'Field1', 'aaa']

  2. 现在创建这些字段的列表:

        \  Insert Into List  ${SingleUser}  ${ColIndex}  ${SingleFieldOfSingleUser}
    
  3. 无需手动遍历每个可能的输入字段,而是使用通用自定义关键字:

        :FOR  ${UserAttribute}  IN  @{SingleUser}
        \  Input Attribute Into User Form  ${UserAttribute}
    
  4. 关键字可能如下所示:

    Input Attribute Into User Form
        [Arguments]  ${Attribute}
        # Try switching to the correct Tab. If already there, don't break upon error
        Run Keyword And Ignore Error  Click Element  ${Attribute[0]}
        # Input Value
        Input Text  ${Attribute[1]}  ${Attribute[2]}
    
  5. 利润!您现在可以根据要更新的字段提供包含任意数量列的 Excel 电子表格。

在这里,我为您留下一个完整的代码清单模型:

*** Keywords ***

(...)

Read Column Data For User
    ${SingleUser}  Create List

    :FOR  ${ColIndex}  IN RANGE  ${COLCOUNT}
    ( ... Excel-related code here ... )
    \  ${SingleFieldOfSingleUser}  Create List  ${TabName}  ${FieldName}  ${Value}
    \  Insert Into List  ${SingleUser}  ${ColIndex}  ${SingleFieldOfSingleUser}

    :FOR  ${UserAttribute}  IN  @{SingleUser}
    \  Input Attribute Into User Form  ${UserAttribute}

    (...)

Input Attribute Into User Form
        [Arguments]  ${Attribute}
        Run Keyword And Ignore Error  Click Element  ${Attribute[0]}
        Input Text  ${Attribute[1]}  ${Attribute[2]}

附言 你真的不需要这么多 FOR 循环和列表来使这个东西工作,但我试图让我的解决方案尽可能接近你的原始编码模式,以防它有一些隐藏的个人价值。

于 2016-03-07T14:27:59.210 回答