In Robot Framework, keywords cannot be nested directly inside other keywords—passing Get From Dictionary inside Log To Console will just print the literal words "Get From Dictionary" instead of running it.
Instead, use direct dictionary variable syntax inside Log To Console, or save the value to a variable first.
Option 1: Print Directly (Recommended)
You don't need Get From Dictionary at all if you just want to print a key's value to the console:
*** Test Cases ***
Print Dictionary Value
&{user}= Create Dictionary name=Alice role=Admin
Log To Console ${user}[name]
(Note: ${user.name} also works if the key has no spaces).
Option 2: Use Get From Dictionary on a Separate Line
If you specifically want to use Get From Dictionary (for example, to take advantage of its default= fallback argument), assign its output to a scalar variable first, then pass that variable to Log To Console:
*** Settings ***
Library Collections
*** Test Cases ***
Print Dictionary Value With Keyword
&{user}= Create Dictionary name=Alice role=Admin
${user_name}= Get From Dictionary ${user} name
Log To Console ${user_name}
Quick Tip on Console Output
Log To Console prints text without automatically adding a newline unless you include \n or leave it as the only output on that line. To make it easier to spot in your terminal logs, you can add a label:
Log To Console \nUser Name: ${user}[name]

No comments:
Post a Comment