Search code examples
pythonrobotframeworkfaker

How can I use faker in conjunction with Robot Framework?


I've been trying to use the faker library to generate data without having it in my test cases as static data.

I have tried calling fake.md5(raw_output=False) directly from my keyword and also by creating a variable and assigning it this value, but neither has the intended effect. It seems that no matter what I do, the only output I'm getting during my test is fake.md5(raw_output=False).

What am I doing wrong?

Edit: My keyword (it writes to a specific field, this is just a test keyword to make sure I can use faker) -

Write username
    ${md5}=    MD 5
    ${my data}=    log    md5: ${md5}
    Input Text    a11y-username    ${my data}

Edit #2 - I realized I had missed out the log keyword, I have updated my code


Solution

  • The problem is in this statement:

    ${my data}=    md5: ${md5}
    

    Robot expects the first cell (or the first cell after a variable name) to be a keyword. So, in this case it thinks md5: ${md5} is a keyword, which it obviously is not. That is why you get the error No keyword with name 'md5: ${md5}' found.

    I don't know what you're expecting to do with that line of code. Your value is already in a variable, are you trying to copy it to another variable, or simply print it out?

    If your intention was to log the value, use the Log keyword:

    Write username
        ${md5}=    MD 5
        log  md5: ${md5}
    

    If you instead want to copy the value to another variable, you can use the Set Variable keyword:

    write username
        ${md5}=  MD 5
        ${my data}=  set variable  ${md5}
        Input Text  a11y-username  ${my data}