在变量定义中使用变量 [英] Using Variables in Variable definition
问题描述
我试图将变量放入变量中,但它不起作用.我搜索了谷歌并尝试了很多东西,但没有成功.
我希望这个问题不是愚蠢的":
我做错了什么?
I am trying to get variables into variables but it wont work. I searched google and tried a lot of stuff but it did not wor out.
I hope this question ist not "dumb":
What am I doing wrong ?
*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
*** Variable ***
${year} Get Time return year
${month} Get Time return month
${day} Get Time return day
${output} ${CURDIR}\Testing\Tests\SRV\csdb_@{year}-@{month}-@{day}.log
*** Testcases ***
Textfile should have a line saying the service is started
${errors} = Grep File ${output} Test
推荐答案
来自 机器人框架用户指南:
最常见的变量来源是测试用例中的变量表文件和资源文件.变量表很方便,因为它们允许在与测试其余部分相同的位置创建变量数据,并且所需的语法非常简单.它们的主要缺点是值始终是字符串并且无法创建动态.
The most common source for variables are Variable tables in test case files and resource files. Variable tables are convenient, because they allow creating variables in the same place as the rest of the test data, and the needed syntax is very simple. Their main disadvantages are that values are always strings and they cannot be created dynamically.
为了执行您想要的操作,您需要在关键字中定义变量.例如:
In order to do what you want, you'll need to define the variables in a keyword. For example:
*** Keywords ***
Get Output
${year}= Get Time year
${month}= Get Time month
${day}= Get Time day
${output}= Set variable ${CURDIR}/Testing/Tests/SRV/csdb_${year}-${month}-${day}.log
[Return] ${output}
*** Testcases ***
Textfile should have a line saying the service is started
${output}= Get Output
${errors} = Grep File ${output} Test
注意:您可以在对关键字的一次调用中获取所有三个部分的数据,如下所示:
Note: you can fetch all three parts of the data in a single call to the keyword, like so:
${year} ${month} ${day}= Get Time year month day
用空格分隔的格式有点难读,但是变量名必须用两个或多个空格隔开,但年月日"应该只有一个.
It's a bit hard to read with the space-separated format, but the variable names must each be separated by two or more spaces, but "year month day" should have only one.
这篇关于在变量定义中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!