优化Robot Framework测试场景:减少冗余,提升效率

问题描述 投票:0回答:1

我需要机器人框架方面的帮助。如何创建测试场景?我所说的测试场景是指将多个测试用例组合在一起。例如,如果我有以下测试用例:

1.登录后台

2.添加内容后端

3.后台编辑内容

4.查看前端内容部分

然后我有以下测试场景: 1.登录后台->添加后台内容->检查前端内容部分是否会更新 2.登录后台->后台编辑内容->查看前端内容部分是否会更新

好吧,现在我该如何在 Robot Framework 中编写这些内容呢?目前,在***测试用例***部分,我已经写出了2个测试用例:

  1. 登录后端 -> 添加内容后端 -> 检查前端内容部分是否会更新
  2. 登录后台 -> 编辑后台内容 -> 检查前端内容部分是否会更新

这两个测试用例都重复登录后端和检查前端内容部分命令。有没有办法减少代码冗余?例如,我可以将登录后端并检查前端内容部分编写为函数,然后稍后在 *** 测试用例 *** 部分中调用它们吗?

python automated-tests robotframework
1个回答
0
投票

当然,您可以将任何操作包装为

keyword
(RobotFramework 函数/方法的名称),然后重用它。

用户指南中有解释。

因此,

Login backend
Edit content backend
Frontend content section should be updated
可能是可以重复使用的关键字。 例如,非常高水平:

  1. 您可以拥有一个包含关键字的资源文件
    backend.robot
    ,例如:
*** Keywords ***
Login backend
  [Arguments]  ...
  ...

Edit content backend
  [Arguments]  ...
  ...

Frontend content section should be updated
  [Arguments]  ...
  ...
  1. 带有测试的文件示例,例如
    sanity.robot
    :
*** Settings ***
Resource  libs/backend.robot

*** Test Cases ***
Backend content could be added
  Login backend    <arguments here if any>
  Add content backend   <arguments here if any>
  Frontend content section should be updated  <arguments here if any>

Backend content could be edited
  Login backend    <arguments here if any>
  Edit content backend   <arguments here if any>
  Frontend content section should be updated  <arguments here if any>

© www.soinside.com 2019 - 2024. All rights reserved.