Search code examples
pythonselenium-webdriverrobotframework

Passing named arguments to test template in Robot framework


I am using the following code in Robot framework in Python

*** Settings ***
Library    SeleniumLibrary

Test Template    Create New Guest of Specified Type

*** Test Cases ***
Verify creation of new guest of type Today
    guest_details = &{TodayGuestDetails}    schedule_type = Today    guest_type = Visitor
    
*** Keywords ***
Create New Guest of Specified Type
    [Arguments]    ${guest_details}=guest_details    ${schedule_type}=schedule_type    ${guest_type}=guest_type
    Fill Guest Details    ${guest_details}
    
*** Variables ***
&{TodayGuestDetails}    firstname=Test    lastname=Guest    [email protected]

What is wrong with the above code? I am getting error Resolving variable '${guest_details = {'firstname': 'Test', 'lastname': 'Guest', 'email': '[email protected]'}}' failed: Variable '${guest_details }' not found.


Solution

  • The guest_details were getting stored inside a dictionary, so I had to do this

    *** Test Cases ***
    Verify creation of new guest of type Today
        schedule_type = Today    guest_type = Visitor   guest_details = &{TodayGuestDetails}    
        
    *** Keywords ***
    Create New Guest of Specified Type
        [Arguments]    ${schedule_type}    ${guest_type}    &{dict}
        Set Suite Variable    ${guest_details}    ${dict["guest_details"]}
        Fill Guest Details    ${guest_details}