简体   繁体   中英

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

I am trying to make a keyword that takes as default argument a python script method, as seen below:

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

The problem is that when I run this step, it outputs Element 'folders.get_last_folder' not visible after 5 seconds. What is the correct syntax in order to have ${PARENT_FOLDER} 's default value as the output of the method folders.get_last_folder() ?

You can't run functions in Arguments section, folders.get_last_folder is considered to be a string. You need to use "Run Keyword If" to conditionally set variable, something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM