我可以在robotframework中使用关键字作为参数吗?

时间:2018-06-18 13:38:01

标签: robotframework keyword robotframework-ide

我想用Screen Should ContainScreen Should Not Contain替换$ {assertion_Keyword},所以我想把一个Argument作为关键字

check_element_and_its_representation      
    [Arguments]    ${assertion_Keyword}    ${payload}    ${on_click_payload}     
    ${assertion_Keyword}    ${payload}
    SikuliLibrary.Click    ${payload}    
    Screen Should Contain    ${on_click_payload} 

使用此代码我编码语法错误没有找到关键字: enter image description here

这个行动怎么可能?还有其他办法吗?

感谢。

1 个答案:

答案 0 :(得分:4)

Run Keyword命令可以帮助您。下面是一个基于示例代码的示例。我已经注释掉了Sikuli关键字,但保留了它们并添加了两个关键字来模拟在Sikuly图书馆中找到的关键字。

*** Test Cases ***
TC Screen Should Contain
    Check Element And Its Representation    Screen Should Contain    payload    on_click_payload

TC Screen Should Not Contain
    Check Element And Its Representation    Screen Should Not Contain    payload    on_click_payload


*** Keywords ***

Check Element And Its Representation      
    [Arguments]    ${assertion_Keyword}=Screen Should Contain    ${payload}=None    ${on_click_payload}=None     
    Run Keyword    ${assertion_Keyword}    ${payload}
    # SikuliLibrary.Click    ${payload}    
    # Screen Should Contain    ${on_click_payload} 

Screen Should Contain
    [Arguments]    ${var}
    Log    Screen Should Contain

Screen Should Not Contain
    [Arguments]    ${var}
    Log    Screen Should Contain