Search code examples
robotframework

Split long argument to multiple lines in Robot Frameowrk


I have some manual steps in my robotframework tests and I would love to have nice readable code. Let's have some example:

*** Settings ***
Documentation    Hello world example.
Library          Dialogs

*** Test Cases ***
Hello world Test
    [Documentation]    My simple test
    Execute Manual Step    This is first line\nMy second have xxx xxx\nIt seems it is not possible to split this in the code...
    Execute Manual Step    Has it been working in previous step?

I would love to have something like

*** Settings ***
Documentation    Hello world example.
Library          Dialogs

*** Test Cases ***
Hello world Test
    [Documentation]    My simple test
    Execute Manual Step    This is first line and here goes the second.
    ...                    My second have xxx xxx
    ...                    It seems it is not possible to split this in the code...
    Execute Manual Step    Has it been working in previous step?

But it sadly thinks it is three arguments:

Keyword 'Dialogs.Execute Manual Step' expected 1 to 2 arguments, got 3.

Solution

  • @rasjani suggested a way how to do this in comment that turned out pretty easy to implement:

    resources/common.robot

    *** Settings ***
    Library    Dialogs
    
    *** Keywords ***
    Tell User
        [Arguments]    @{args}
        ${result} =    Catenate    @{args}
        Execute Manual Step    ${result}
    

    tests/hello.robot

    *** Settings ***
    Documentation    Hello world example.
    Resource         ../resources/common.robot
    
    *** Test Cases ***
    Hello world Test
        [Documentation]    My simple test
        Tell User    This is first line and here goes the second:
        ...          We are here splitting this in the code only
        Tell User    This is first line and here goes the second:\n
        ...          My second line\n
        ...          It seems it is working!
    

    Using SEPARATOR option for Catenate we can achieve the same result as the second usage without ugly \n if someone would want that:

    tests/hello.robot

    *** Settings ***
    Library    Dialogs
    
    *** Keywords ***
    Tell User
        [Arguments]    @{args}
        ${result} =    Catenate    SEPARATOR=\n    @{args}
        Execute Manual Step    ${result}
    

    This question on variable list argument handling was helpful in the process: Passing *args in Robot Framework