0

I'm trying to figure out what am I doing wrong, I want to get the result of a specific python function.

This is my Resources.robot file:

*** Settings ***
Library                           resources_func.py

*** Keywords ***
Test Time
    ${time_delta}=                get time period        ${Time}
  • ${Time} is defined but isn't relevant to my question

and this is my python script:

import re
from dateutil.parser import parse

class TimeTests(object):
    def get_time_period(timestamp):
        timestamps = re.findall(r'[0-9][0-9]:[0-9][0-9]', timestamp)
        a = parse(timestamp[0])
        b = parse(timestamp[1])
        res = (b - a)
        res = res.seconds / 60
        return res

This is the error I'm getting:

No keyword with name 'get time period' found.

Any ideas?

2
  • 1
    rename filename resources_func.py to classname : resources_func.py > TimeTests.py and try again. Commented Oct 24, 2017 at 8:44
  • That worked! Thanks. Commented Oct 24, 2017 at 9:08

1 Answer 1

3

For others in future, have a look into RF docs about creating user libraries http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id216

The name of a test library that is used when a library is imported is the same as the name of the module or class implementing it. For example, if you have a Python module MyLibrary (that is, file MyLibrary.py), it will create a library with name MyLibrary. Similarly, a Java class YourLibrary, when it is not in any package, creates a library with exactly that name.

Python classes are always inside a module. If the name of a class implementing a library is the same as the name of the module, Robot Framework allows dropping the class name when importing the library. For example, class MyLib in MyLib.py file can be used as a library with just name MyLib. This also works with submodules so that if, for example, parent.MyLib module has class MyLib, importing it using just parent.MyLib works. If the module name and class name are different, libraries must be taken into use using both module and class names, such as mymodule.MyLibrary or parent.submodule.MyLib.

Sign up to request clarification or add additional context in comments.

Comments

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.