robotframework - 为什么我会收到 "' If' is a reserved keyword"错误?

标签 robotframework

这是我第一次尝试在 Robot Framework 中使用 IF 条件,我发现它出奇地困难。我的测试失败并显示以下消息:'If' 是保留关键字。 是的,我想使用该关键字!

这是相关代码的片段。

    # Column lookup using ${heading}
    @{heading_list}  Create List
    @{header_element_list}  Get WebElements  ${table_headers_locator}
    FOR  ${element}  IN  @{header_element_list}
        Append To List  ${heading_list}  ${element.text}
    END
    ${col}  Get Index From List  ${heading_list}  ${heading}
    IF  ${col} < 0
        Fail  Heading '${heading}' not found in table.
    END

我在 PyCharm 工作,使用 Robot Framework 代码语法高亮插件。该插件似乎还认为 IF 条件有问题;请注意,它的关键字是浅蓝色的,而紧靠其上方的 FOR 循环中的关键字是橙色的。

enter image description here

我相信我的 IF 语句符合最简单的 IF 语句示例,如机器人框架文档所示:https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#advanced-features .请帮助我理解为什么不是这样。谢谢!

最佳答案

Bryan Oakley 写道:“看起来该插件尚未更新以支持机器人 4.x”,这让我进行了更深入的研究。我雇主的自动化团队指定了 Robot 3.1.2!这不是我能改变的。

在线文档指出 IF 表达式已添加到 Robot 4.0 的语言中。因此,我为 IF 语句突出显示的语法与我的预期不符是正确的——因为 Robot 3.x 不会以这种方式处理条件语句。

就我个人而言,我觉得奇怪的是,像 IF 表达式这样基本的东西实际上是一种尖端的语言功能。但是,了解 Robot 3.x 施加的限制后,我将设计一个解决方法。

关于robotframework - 为什么我会收到 "' If' is a reserved keyword"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67393953/

相关文章:

sql-server - SQL 查询 - "TypeError: sequence item 0: expected string, Decimal found"使用值

python - 配置解析 Robotframework

python - 机器人框架通过按键更改表格单元格值

javascript - 如何使用 Python、JavaScript 或 Robot Framework 和 Selenium 使用部分标题文本导航到新的浏览器窗口

selenium - selenium grid 只运行 Selenium 命令还是来自不同库的代码块

python - 机器人框架未从自定义库中找到自定义关键字

selenium-webdriver - 机器人框架调用带有空格的 add_argument

python - 机器人测试接收到的 unicode 与从 python 关键字发送的不同

python - 在robot framework中申请loop后,报错如下- Keyword name cannot be empty

python - 在 RobotFramework 中使用 Run Process 关键字的语法