How to access variables from .yaml file to robot framework script?

12,255

you need to access the attributes of yaml file like ${DICT.one} more information here

https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/CreatingTestData/ResourceAndVariableFiles.rst#variable-file-as-yaml

your modified code

*** Settings ***
Variables    Myvariable.yaml

*** Test Case ***
Test
    Choose Topic
***Keywords****
Choose Topic
       Log   ${ACFC NEWS.Doc_Title}
       Log   ${ACFC NEWS.Open_Selector}

I am assuming you are running the script with below command

pybot -V myvariable.yaml sample.robot

This should solve your problem now.

Share:
12,255
Uday
Author by

Uday

Updated on July 15, 2022

Comments

  • Uday
    Uday almost 2 years

    I have Myvariable.yaml file and sample.robot file, I wanted to use the variables from .yaml file to robot file

    • Myvariable.yaml file:

         ACFC NEWS:
              Doc_Title:  XPath=//div[@class='ng-scope']
              Open_Selector:  xpath=//button[@class='btn btn-default ng-binding]
      
    • Sample.robot file

         ***Settings****
         Variables  Myvariable.yaml
      
         ***Keywords****
         Choose Topic:
              Input Text   ${Doc_Title}   "Some text"
              Click Button   ${Open_Selector}
      

    Error: Variable not found

    It would be great if any one can help me in solving this issue.

    • pankaj mishra
      pankaj mishra over 6 years
      your code is not properly formatted, always paste code with proper formatting
  • Uday
    Uday over 6 years
    Excellent the problem is solved now. Thank you o much for the help Pankaj