psad
psad

Reputation: 23

Add Class in Library of Robot Framework

I want to add a class in the library of robot framework but it does not work. I create a simple test to describe my issue.


Robot script: helloworld.robot  
*** Settings ***    
Library         Library.py

*** Test Cases ***    
Hello World     
      ${x} =     Print Hello World      
         log to console          ${x}

Library scirpt: Library.py

class Hello_World(object):    
      def print_Hello_World():         
            return "Hello World"


Output of terminal: enter image description here


I dont understand why I get an error that no keyword found.

The script works without the class, but I need to add classes for further tests.

I would be happy if someone could take a look at my problem.

Best psad

Upvotes: 0

Views: 1529

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20067

From the user guide:

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.

And:

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. ... 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.

So rename the class to be the same as the file it's in, or provide the class name when importing.

Upvotes: 1

Related Questions