Robotframework-RED-关键字封装

Keywords的封装有一般两种方式,当前测试集中封装与单独作为一个资源文件进行封装;下面分别举个简单例子来说明下:

第一种方式:suite中封装


先写下简单的一点脚本:

*** Variables ***
${a} null
${b} null
*** Test Cases ***
first-case
	log	 ${a}+${b}

编写与运行截图如下:

Robotframework-RED-关键字封装

Robotframework-RED-关键字封装

接下来在当前suite中,编写下Keywords并引用,脚本如下:

*** Variables ***
${a} null
${b} null
*** Keywords ***
SUM
 ${a} Set Variable A
 ${b} Set Variable B
 Set Suite Variable ${a}
 Set Suite Variable ${b} 
*** Test Cases ***
first-case
 SUM
	log	 ${a}+${b}

Robotframework-RED-关键字封装

Robotframework-RED-关键字封装

第二种方式:Keywords单独在资源文件中


kw.robot脚本里面有个sum关键字,具体如下:

*** Keywords ***
SUM
 ${a} Set Variable A
 ${b} Set Variable B
 Set Suite Variable ${a}
 Set Suite Variable ${b} 

Robotframework-RED-关键字封装

1.kw.robot与demo-suite.robot在同一级别的目录中,demo-suite.robot脚本如下:

*** Settings ***
Resource kw.robot
*** Variables ***
${a} null
${b} null
*** Test Cases ***
first-case
 SUM
	log	 ${a}+${b}

2.kw.robot与demo-suite.robot在不在同一级别的目录中,demo-suite.robot脚本如下:

*** Settings ***
Resource ../kw/kw.robot
*** Variables ***
${a} null
${b} null
*** Test Cases ***
first-case
 SUM
	log	 ${a}+${b}

目录结构与脚本运行,如下图

Robotframework-RED-关键字封装

Robotframework-RED-关键字封装

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

测试界

您的支持是我前进的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值