Robotframework

Robotframework-RED-关键字封装

2019-10-18  本文已影响0人  测试界

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

第一种方式:suite中封装

先写下简单的一点脚本:

*** Variables ***

${a} null

${b} null

*** Test Cases ***

first-case

log ${a}+${b}

编写与运行截图如下:

接下来在当前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}

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

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

*** Keywords ***

SUM

${a} Set Variable A

${b} Set Variable B

Set Suite Variable ${a}

Set Suite Variable ${b}

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}

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

上一篇 下一篇

猜你喜欢

热点阅读