2

I'm trying to generate a random name when logging in, through a function in Python. The problem is that it doesn't consider it as a function, but as a plain text, though i've imported the library and called it explicitly. Here's the Python function in file Generators.py:

import random

letters = [chr(ord('a')+i) for i in range(26)]

def generate_name():
    name = ""
    for i in range(9):
        name = name + random.choice(letters)
    return "Testing_Mark[" + name + "]"

And here's the Robot file:

*** Settings ***
Library     Generators.py
Library     Selenium2Library

*** Variables ***
${User}                     Generators.Generate Name
${Password}                 1234
*** Test Cases ***
Organisation Test
    Open Browser    http://mywebsite.com/login     googlechrome
    Log In
    [Teardown]  Close Browser

*** Keywords ***
Log In
    Wait Until Page Contains    Log in
    Input Text          //input[@name="name"]        ${User}
    Input Password      //input[@name="password"]     ${Password}
    Click Button        //button[@type="submit"]
    Wait Until Element Is Visible   //span[@class="alert-description"]
    Sleep   3

What am I doing wrong? I know Robot should recognize the above function as a keyword, but still can't figure out why it is not. Both files are in the same folder.

3
  • Can I ask why you're creating your own, when there is a good FakerLibrary that does this, and much more, for you? Commented Jan 29, 2018 at 16:34
  • I didn't know there is such library. I'm a newcomer in Robot but Thx for the advice, i might need that :) Commented Jan 29, 2018 at 18:16
  • In the FakerLibrary Documentation the returned values can be set your your specific locale; i.e. set it to NL and you get Dutch names, street names Social Security numbers etc. When set to DE and you get the same but then German. Commented Jan 29, 2018 at 19:23

1 Answer 1

2

Variable table only assigns values as is, keywords are not executed in variables table.

Quotation from Robot Framework User Guide:

Their (variables table) main disadvantages are that values are always strings and they cannot be created dynamically. If either of these is a problem, variable files can be used instead.

So your ${User} is now Generators.Generate Name. As string. Move

${User}                     Generators.Generate Name

into the test case.

*** Test Cases ***

Organisation Test
    ${User}                     Generators.Generate Name
    Open Browser    http://mywebsite.com/login     googlechrome
    Log In
    [Teardown]  Close Browser
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this too, and i get "Organisation Test | FAIL | No keyword with name 'Generators.Generate Name' found. "
Sorry, i'm stupid. Turns out i was modifying a copy of the Generators.py file and that's why it didn't recognize this keyword. Thanks, worked like a charm :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.