Mar*_*rzl 3 testing robotframework
我有一个在 python (myLibrary.py) 中实现的机器人库,它需要使用可变数量的参数(例如文件名)进行初始化:
class myLibrary:
def __init__(self, *files):
Run Code Online (Sandbox Code Playgroud)
我有一个 Robot 关键字文件 (myKeywords.txt),它正在使用该 python 库:
*** Settings ***
Library myLibrary.py ../folder1/fileA ../fileX
*** Keywords ***
myKeyword
pass
Run Code Online (Sandbox Code Playgroud)
在我将库参数静态放入 myKeywords.txt 文件的情况下,我的库正确初始化。
但是我想让 myLibrary 的这些参数是动态的,这样我就可以包含来自不同测试套件的 myKeywords.txt 并使用不同的参数对其进行初始化。
我正在寻找一个 myKeywords.txt 文件,它看起来像这样:
*** Settings ***
Library myLibrary.py @{arguments}
Run Code Online (Sandbox Code Playgroud)
我想在我的测试套件中定义 @{arguments} (因为它从测试套件到测试套件不同)并且在导入关键字文件时是这样的:
*** Settings ***
Resource configuration.txt // defines @arguments
Resource myKeywords.txt @{arguments}
*** Test Cases ***
myTest
Run Code Online (Sandbox Code Playgroud)
你不能完全按照你的意愿去做,因为机器人语法不允许你将变量传递给资源文件。但是,我认为没有任何理由传入 @{arguments}- myKeywords.txt 应该能够直接使用该变量。
这个设置对我有用:
配置.txt:
*** Variables ***
| @{arguments} | file1 | file2
Run Code Online (Sandbox Code Playgroud)
我的图书馆.py:
class myLibrary:
def __init__(self, *files):
self.files = files
def getFiles(self):
return self.files
Run Code Online (Sandbox Code Playgroud)
我的关键字.txt:
*** Settings ***
| # N.B. @{arguments} must be defined before importing this resource file
| Library | myLibrary.py | @{arguments}
*** Keywords ***
| Show files
| | ${files}= | myLibrary.getFiles
| | log to console | the files are ${files}
Run Code Online (Sandbox Code Playgroud)
测试套件:
*** Settings ***
| Resource | configuration.txt
| Resource | myKeywords.txt
*** Test Cases ***
| Display the list of configuration files
| | Show files
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4837 次 |
| 最近记录: |