bunduru
bunduru

Reputation: 121

Robot Framework doesn't see Groovy Keywords

I'm using Robot Framework to test a large number of Java files, and I'm wanting to add several Groovy files. I've read that this is possible because a compiled Groovy file is a .class file just like a compiled Java file.

Here's my Groovy file;

import java.io.IOException;

class GroovyTest 
{   
    public String t1(){
        return 'PASS'   
    }
} 

Here's my Robot file;

|  *** Settings ***  |

|  Library  |  GroovyTest  |


|  *** Test Cases ***  |

|  Groovy Sanity   |  [Documentation]  |  set pass string  |
|  \  |  GroovyTest.t1       |
|  \  |  Return GROOVY state  |


|  *** Keywords ***  |

|  Return GROOVY state  |
|  \  |  ${value}=        |  GroovyTest.t1    |
|  \  |  [return]         |  ${value}              |
|  \  |  Should Be Equal  |  ${value}              |  PASS    |

This is identical to how I've set up all of my Java test cases and keywords. With Groovy, I'm getting this error;

[ WARN ] Imported library 'GroovyTest' contains no keywords

Upvotes: 1

Views: 492

Answers (1)

ombre42
ombre42

Reputation: 2384

EDIT: this answer was only appropriate for the original posting which used the class name 'test'.

The problem is that there is already a module named test containing unit tests for Jython itself that being loaded by Robot Framework instead of your test library. Try a more descriptive class name like TestGroovyLibrary.


    >>> import test
    >>> help(test)
    Help on package test:

    NAME
        test - # Dummy file to make this directory a package.

    FILE
        c:\apps\jython2.5.3\lib\test\__init__.py

    PACKAGE CONTENTS
        Graph
        access_protected_class
        access_protected_field
        anygui
        autotest
        bad_coding
        ...

To see what was loaded you can do this:

${library}=    Get Library Instance    test
Log    ${library.__file__}

Output in RIDE:

20130711 10:12:54.117 :  INFO : ${library} = <module 'test' from C:\apps\jython2.5.3\Lib\test\__init__$py.class'\>  
20130711 10:12:54.130 :  INFO : C:\apps\jython2.5.3\Lib\test\__init__$py.class

Upvotes: 1

Related Questions