robotframework - 在变量定义中使用变量

标签 robotframework

我试图将变量放入变量中,但它不起作用。我搜索了谷歌并尝试了很多东西,但没有成功。
我希望这个问题不是“愚蠢的”:
我做错了什么?

*** 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

最佳答案

来自robot framework user's guide :

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.

为了执行您想要的操作,您需要在关键字中定义变量。例如:

*** 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

注意:您可以在对关键字的一次调用中获取数据的所有三个部分,如下所示:

${year}  ${month}  ${day}=  Get Time    year month day

用空格分隔的格式阅读起来有点困难,但变量名必须用两个或多个空格分隔,但“年月日”只能有一个。

关于robotframework - 在变量定义中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29772879/

相关文章:

python - Robot Framework - 访客界面 - 如何获取关键字的关键字子项?

selenium - 机器人框架+Selenium : how to avoid "stale element" error (flaky test)?

python - 机器人框架处理身份验证弹出窗口

python - 在机器人框架中记录 HTML 请求

selenium - 如何获取机器人框架中的所有文本?

testing - Appium - 机器人框架 - 选择下拉

python - 当测试失败时,机器人框架在 log.html 中没有输出

java - 我们可以使用 Robot Framework 来自动化 Web 和移动应用程序来执行并行执行吗

robotframework - 如何在 Robot Framework 中修复 "No keyword with name ' 0 =' found"

xpath - 使用机器人框架查找属性为 'selected' 的选项标签