Search code examples
selenium-webdriveryamlrobotframeworkpyyaml

Robot Framework Parameterizing using yaml file


Hi can anybody help me parameterize the string word so it will fetch from my yaml. I tried to run however I'm getting an error it shows failed: Using YAML variable files requires PyYAML module to be installed. Typically you can install it by running pip install pyyaml. but I already install pyyaml on my local machine. your response is highly appreciated. Thank you so much

Expected Result: ${String} parameter should get the value from my robot.yaml (Ralph) value

VS Terminal Screenshot:

enter image description here

.robot screenshot

enter image description here

robot.yaml file screenshot: enter image description here

CMD Screenshot:

enter image description here


Solution

  • In robot.yaml define PYTHONPATH like this:

    PYTHONPATH:
      - .
      - string: "RALPH"
    

    Make sure you have installed PyYAML, then include robot.yaml and collections library in the robot file:

    Variables         path_to_file/robot.yaml
    
    Library           Collections
    

    After this you can extract string value inside the test like this:

    ${value} =     pop from dictionary     ${PYTHONPATH[1]}     string
    log to console   ${value}
    

    This will print:

    RALPH
    

    Second item in PYTHONPATH list is a dictionary, so you first need to access ${PYTHONPATH[1]} and then pop the needed key (in your case string) in order to return its value.