如何验证Robot Framework中的每个测试用例

时间:2015-10-12 06:58:27

标签: robotframework

如何在Robot Framework中验证每个测试用例。就像我有3个字段名称,编号和加入日期和保存按钮,所有都是必填字段。

第一个案例 - >我将输入数字和加入日期,然后单击保存按钮,然后验证消息将显示“请输入名称”

第二种情况 - >我将输入名称和加入日期并单击“保存”按钮,然后验证消息将显示“请输入数字”

第三种情况 - >我将输入名称和号码,然后单击“保存”按钮,然后验证消息将显示“请输入加入日期”

第四种情况 - > 1000已经添加然后如果我输入名称,数字,加入日期点击保存按钮验证消息将出现“重复员工编号”

如果我使用测试模板

,如何处理这种情况需要使用“测试模板”
*** Settings ***
Documentation     A test suite containing tests related to invalid login.
...
...                     These tests are data-driven by they nature. They use a single
...                   keyword, specified with Test Template setting, that is called
...                    with different arguments to cover different scenarios.
...
...                    This suite also demonstrates using setups and teardowns in
...                    different levels.
Test Template     Invalid Data
Resource           resource.txt

*** Test Cases ***                           Number                     Name                    Join Date       
Empty Employee Number               ${EMPTY}                  Foo                       01 Apr 2015         
Empty Employee Name                  1000                         ${EMPTY}               01 Apr 2015
Empty Join Date                            1000                          Foo                        ${EMPTY}

*** Keywords ***
Invalid Data
      [Arguments]    ${employeenumber}    ${name}    ${doj}
      Enter Employee Number        ${employeenumber}
      Enter Employee Name           ${name}
      Enter Join Date                     ${doj}
      Validation check for Invalid Data

Validation check for Invalid Data
       Page Should Contain        Please enter the Name
       Page Should Contain        Please enter the Number
       Page Should Contain        Please enter the Join Date  

如果我使用这样的话,那么第一个测试用例是Pass,测试用例的其余部分将是Fail,因为对于第二个测试用例,它将检查“Page Should Contain Please Please name name”但是对于第二个测试用例我们是已添加号码。如何处理Robot Framwork中的这类案例可以帮助我。

1 个答案:

答案 0 :(得分:1)

为要验证的内容添加另一个参数

*** Keywords ***
Invalid data
[Arguments]    ${employeenumber}    ${name}    ${doj}    ${expected}
...
Page should contain    ${expected}

*** Test Cases ***      Number    Name      Join Date     Expected       
Empty Employee Number   ${EMPTY}  Foo       01 Apr 2015   Please enter the name
Empty Employee Name     1000      ${EMPTY}  01 Apr 2015   Please enter the number
Empty Join Date         1000      Foo       ${EMPTY}      Please enter the Join Date