0
votes

I am facing a similar issue as : Robot Framework:: Imported library 'class' contains no keywords

Here, the user claims to have solved it by adding FileName.ClassName in the Settings section of .robot file. I tried the same, by adding "Library test.MyLib" but gives me the error "Importing test library 'test.MyLib' failed: Module 'test' does not contain 'MyLib'". However, when I remove and revert back to just "Library test", I get a warning as "[ WARN ] Imported library 'test' contains no keywords" and an error as "No keyword with name 'hello' found." My code is as follows :

test.py

class MyLib(object):
__all__ = ['hello']

def __init__(self):
    name = "Wrath"

def hello(self, *args):
    name = self.args[0]
    print "Hello "+name

test.robot

*** Settings ***
Documentation  Suite description
Library  test

*** Test Cases ***
Test title
    [Tags]  DEBUG
    hello  Sloth

*** Keywords ***

It would be really helpful if I'm advised on the above issue. Have tried out official Robot Framework documentation and the few examples on the web, but seems like I'm doing right. But I have a feeling that I'm probably missing out some minor but crucial thing up there. Precisely, the Keyword section maybe?

2

2 Answers

2
votes

From the symptoms you describe, it sounds like you have another "test.py" file that robot is loading, instead of the keyword file you think it's loading.

A way to determine that is to generate a syslog, which will tell you which file is actually being imported.

The other thing you can try is to rename your library to something other than "test.py", and then modify your import statement accordingly. If it works with another name, that is proof that you have more than one "test.py" in your environment.

2
votes

Okay, my bad. I got a little confused after reading the official documentation of Robot Framework. After many repeated runs of trial and error I found out what I was doing wrong. I got it running finally and here are my observations :

  1. First and foremost thing, I separated the libraries and formed a clean directory structure for each program I was executing.
  2. Secondly, made sure there are exactly 2 whitespaces (i.e, ' ') between the keyword (I'm working on static API) and argument in the .robot file.
  3. Renamed the class in the library file "MyLibrary.py" to anything other than "MyLibrary", say "MyClass". This could help avoid some confusion for a beginner like me. Then, include the class as "Library MyLibrary.MyClass" in "Settings" header of .robot file.

If you make sure of the above, your test suite should execute smoothly, provided you don't have any syntactical or logical errors in your program and the framework environment is proper.