Robotframework for loop 继续下一个测试 [英] Robotframework for loop continue with next test

查看:41
本文介绍了Robotframework for loop 继续下一个测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

*** 设置 ***图书馆操作系统图书馆流程库字符串测试模板我的运行测试*** 变量 ***@{MyList}= item items*** 测试用例 ***#name 类型配置文件测试[XXXXX_1] 常规测试.out Profile mode.out[标签] TEST-XXXXX*** 关键词 ***我的运行测试[文档] 运行套件[参数] ${type} ${profile} ${file} ${test}: FOR ${data} IN @{MyList}\ 数据准备好时\ 并运行工具\ 并获得成功\ 并且测试套件配置已更新\ 并再次运行测试工具\ 然后发布测试状态数据准备好了登录控制台数据准备就绪"工具已运行登录到控制台工具已运行"运行关键字并返回停止测试这很有趣"获得成功登录控制台获取成功"测试套件配置已更新登录控制台测试套件配置已更新"测试工具再次运行登录控制台再次运行测试工具"发布测试状态登录控制台发布测试状态"停止测试[参数] ${msg}登录控制台 ${msg}失败 ${msg}

根据它,我正在使用 for 循环为列表中的所有项目运行一组关键字.现在我遇到的情况是,对于列表中的一个项目,评估失败,我必须将该测试标记为失败,但希望测试套件继续执行列表中的下一个项目.

因此假设列表中有 3 个项目并且测试用例在列表中的 2 秒内失败,那么代码应该返回主 for 循环[不继续使用其他关键字用于第二个项目]并开始第三个项目的测试用例.

>

我观察到使用关键字 Fail 和其他人会停止整个测试套件.有没有办法做到这一点?

解决方案

如果将测试模板中的 for 循环提取到测试用例中并使用

I have below code:

*** Settings ***
Library     OperatingSystem
Library     Process
Library     String
Test Template    My Run Test
*** Variables ***
@{MyList}=   item  items

*** Test Cases *** 
#name                        type                   profile          file                 test
[XXXXX_1]                   General                test.out         Profile             mode.out 
          [Tags]    TEST-XXXXX   


*** Keywords *** 
My Run Test
    [Documentation]    Run the suite
    [Arguments]       ${type}     ${profile}     ${file}    ${test}
    : FOR  ${data}  IN   @{MyList}
    \         When data is ready
    \         And tool is ran
    \         And get was success 
    \         And test suite config is updated 
    \         And testing tool is again run 
    \         Then publish test status    

data is ready
     Log to Console     "Data is ready"
tool is ran
     Log to Console     "tool is ran"
     Run Keyword And Return    Stop Test          "This is fun"
get was success 
     Log to Console     "get was success"
test suite config is updated 
     Log to Console     "test suite config is updated"
testing tool is again run 
     Log to Console     "testing tool is again run"
publish test status 
     Log to Console     "publish test status"

Stop Test     
    [Arguments]       ${msg}     
    Log To Console    ${msg}
    Fail              ${msg}

As per it I am running a set of keywords for all items in a list using for loop. Now I have a situation that for an item in list a evaluation failed and I have to mark that test as failure but want the test suite to continue with next items in list.

Hence assume there are 3 items in list and test case fails for 2 second item in list then code should return back to main for loop [not continue with other keyword for 2nd item] and start test case for 3rd item.

What I observer that using keyword Fail and others stops the whole test suite. Is there a way to achieve this?

解决方案

If you extract the for loop from the test template into the test case and use Templates with for loops, you could make the iterations independent from each other.

For example with the following modifications:

*** Test Cases *** 
[XXXXX_1]
    FOR  ${data}  IN   @{MyList}
    #   list item  type       profile     file       test
        ${data}    General    test.out    Profile    mode.out
    END


*** Keywords *** 
My Run Test
    [Documentation]    Run the suite
    [Arguments]       ${data}    ${type}     ${profile}     ${file}    ${test}
    When data is ready
    And tool is ran
    And get was success 
    And test suite config is updated 
    And testing tool is again run 
    Then publish test status

This would be the output:

这篇关于Robotframework for loop 继续下一个测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆