机器人框架:创建一个带有可选参数的关键字。参数的默认值应该来自脚本

Robot framework: create a keyword with optional argument. The argument's default value should come from a script

我正在尝试创建一个将默认参数作为 python 脚本方法的关键字,如下所示:

*** Settings ***
Library  SeleniumLibrary
Library  BuiltIn
Library  ./../python_scripts/folders.py

*** Keywords ***
Create subfolder inside mainfolder through right click
    [Arguments]  ${PARENT_FOLDER}=folders.get_last_folder
    press element  ${PARENT_FOLDER}
    right click and add folder
    basic folder creation process
    save folder
    assert created folder exists

问题是,当我 运行 这一步时,它输出 Element 'folders.get_last_folder' not visible after 5 seconds. 正确的语法是什么,以便将 ${PARENT_FOLDER} 的默认值作为方法的输出folders.get_last_folder()?

您不能 运行 函数在参数部分,folders.get_last_folder 被认为是一个字符串。您需要使用“运行 Keyword If”来有条件地设置变量,如下所示:

*** Keywords ***
Create subfolder inside mainfolder through right click
    [Arguments]  ${PARENT_FOLDER}=folders.get_last_folder
    ${PARENT_FOLDER}=    Run Keyword If    "${PARENT_FOLDER}" == "folders.get_last_folder"    folders.get_last_folder
    ...                  ELSE              Set Variable    ${PARENT_FOLDER}
    press element  ${PARENT_FOLDER}
    right click and add folder
    basic folder creation process
    save folder
    assert created folder exists