RobotFramework Eclipse compile problen - no keywords found

1,732 views
Skip to first unread message

kamirru

unread,
Nov 7, 2013, 2:58:36 AM11/7/13
to robotframe...@googlegroups.com
Hi All, 

I am quite new to RF and have a problem with running my first test. 

I am trying to run the test using Eclipse and java (in my company I am not able to use maven due to some restrictions). 

So I created (eclipse) a new project, package and Java class. I also created a test file Aaa.txt. 

When I am running the test I got an error message "no keyword with name "...." found. 

Here is the project structure and the code: 

Project name: Robot
--

package org.robot.sample.keywords;

public class MyKeywords {

public String sayHi(String name)
{
return "Hello " +name ;
}

public String sayHi()
{
return "Hello World!";
}

public String typeOf(Object param)
{
return param.getClass().getSimpleName();
}
}

----
Aaa.txt 


* Settings*
Library      org.robot.sample.keywords.MyKeywords
 
* Test Cases*
MyTestCase
    ${message}    say hi
    Log    ${message}
 
MyTestCase2
    ${message}    say hi    Valerio
    Log    ${message}
 
MyTestCase3
    ${message}    type of    42
    Log    ${message}



I am trying to run the test from cmd using 
java -jar robotframework-2.8.1.jar Aaa.txt

Here is the message from cmd:

Microsoft Windows [Wersja 6.1.7601] Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzezone. C:\Users\xxx>cd C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\o rg\robot\sample\keywords C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keywor ds>java -jar robotframework-2.8.1.jar Aaa.txt [ ERROR ] Error in file 'C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\sr c\org\robot\sample\keywords\Aaa.txt': Importing test library 'org.robot.sample.k eywords.MyKeywords' failed: ImportError: No module named robot Traceback (most recent call last): None PYTHONPATH: C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keyw ords\robotframework-2.8.1.jar\Lib\robot\libraries C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keyw ords\robotframework-2.8.1.jar\Lib C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keyw ords\Lib __classpath__ __pyclasspath__/ . C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keyw ords CLASSPATH: robotframework-2.8.1.jar ============================================================================== Aaa ============================================================================== MyTestCase | FAIL | No keyword with name 'say hi' found. ------------------------------------------------------------------------------ MyTestCase2 | FAIL | No keyword with name 'say hi' found. ------------------------------------------------------------------------------ MyTestCase3 | FAIL | No keyword with name 'type of' found. ------------------------------------------------------------------------------ Aaa | FAIL | 3 critical tests, 0 passed, 3 failed 3 tests total, 0 passed, 3 failed ============================================================================== Output: C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\samp le\keywords\output.xml Log: C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\samp le\keywords\log.html Report: C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\samp le\keywords\report.html C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keywor ds>

Can anyone help?


Ed Manlove

unread,
Nov 7, 2013, 9:01:59 AM11/7/13
to robotframe...@googlegroups.com
The problem is seen here,


C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\src\org\robot\sample\keywor

ds>java -jar robotframework-2.8.1.jar Aaa.txt

[ ERROR ] Error in file
'C:\Users\xxx\Downloads\eclipse\_Projekty\Robot\sr

c\org\robot\sample\keywords\Aaa.txt': Importing test library
'org.robot.sample.k

eywords.MyKeywords' failed: ImportError: No module named robot


in your traceback; "No module name robot". It could be either you have not properly installed the Robot Framework package or your test library is not within PATH. You should check out your system setup, make sure all the required packages are installed [1], as well as check your PATH.

Ed

[1] https://code.google.com/p/robotframework/wiki/Installation

kamirru

unread,
Nov 7, 2013, 10:12:59 AM11/7/13
to robotframe...@googlegroups.com
Hi, 

thanks for your reply. 
I have not mentioned I am using the stand alone version of RF-I thougt everyrhing will be working without installation:/

Or am I also obligated to insall RF on the system and run it via Jyphon in order to use JAVA?


Markus Bernhardt

unread,
Nov 7, 2013, 11:34:08 AM11/7/13
to cami...@gmail.com, robotframe...@googlegroups.com
No, you do not need to install Jython, to run RF. The RF jar contains Jython already.
From what I saw your Classpath was missing your own library and therefore the Library keyword failed.

You were using:
ds>java -jar robotframework-2.8.1.jar Aaa.txt

Try using:
ds>java -cp robotframework-2.8.1.jar:<path to your library> org.robotframework.RobotFramework Aaa.txt

Cheers,
Markus

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/groups/opt_out.

kamirru

unread,
Nov 7, 2013, 12:24:26 PM11/7/13
to robotframe...@googlegroups.com
Thanks, I also think the library with the keywords is missing. 
But still, I think I,ve mixed something up in setting the cp.... Could you give me a whole example? 
Let's assume alle files are in the same directory: D:\RobotFramework

So running up the script will be (? - does not work): 
java -cp robotframework-2.8.1.jar:.MyKeywords java -jar robotframework-2.8.1.jar A.txt

Or should I name the path to MyKeywords even if it is the same directoy? I also do not understand the "org.robotframework.RobotFramework Aaa.txt" you mentioned. 


Using D:\RobotFramework>java -cp robotframework-2.8.1.jar: D:\RobotFramework\MyKeywords.jar (it should be jar, right?) couses "could not find or load main class...

Markus Bernhardt

unread,
Nov 7, 2013, 2:20:14 PM11/7/13
to cami...@gmail.com, robotframe...@googlegroups.com
Hi,

first you have to compile your *.java files into *.class files. You said you are using Eclipse. There should be a directory created automatically by Eclipse containing this files. You need the to add this directory to the classpath. I think it is called "bin" as standard, but I'm not sure. Something like:

java -cp robotframework-2.8.1.jar;C:\Workspace\Project\bin org.robotframework.RobotFramework A.txt

BTW. You cannot mix the -jar and -cp parameter of java. This has nothing to do with RF.

BTW 2: "org.robotframework.RobotFramework" is the name of the program you are about to start. When not using the -jar parameter you have to specify that.
---

One more thing. You said you are using Eclipse. That means you already have maven available. You could simply go to Help -> Eclipse Marketplace ..., search for "maven" and install the "Maven Integration for Eclipse (Juno or newer)".

After that make a new "Maven Project" and select the archetype I wrote last time.

---

Cheers,
Markus

kamirru

unread,
Nov 7, 2013, 3:30:45 PM11/7/13
to robotframe...@googlegroups.com
I suppose with maven it would be much easier;) Unfortunately I am not allowed use maven at work (it should change someday, but...), so I have to do it via cmd, or maybe write a simple gui or something as a workaround...
But still:

java -cp robotframework-2.8.1.jar;D:\RobotFramework\MyKeywords\bin\example org.robotframework.RobotFramework A.txt 
couses an error ( same as java -jar robotframework-2.8.1.jar A.txt running from bin directory)

The error is:
[ ERROR ] Error in file 'D:\RobotFramework\MyKeywords\bin\example\A.txt': Import ing test library 'MyKeywords' failed: NoClassDefFoundError: MyKeywords (wrong na me: example/MyKeywords) java.lang.NoClassDefFoundError: at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)

I tried to google it, but there is not very much about RF and java...

Markus Bernhardt

unread,
Nov 7, 2013, 4:42:25 PM11/7/13
to cami...@gmail.com, robotframe...@googlegroups.com
You problem is 100% related to the classpath.
could you please open a DOS box and type:

d:
cd \RobotFramework\MyKeywords
dir /b /s

Please send the output of the dir command.

Cheers,
Markus

kamirru

unread,
Nov 8, 2013, 9:55:04 AM11/8/13
to robotframe...@googlegroups.com


D:\>cd D:\RobotFramework\MyKeywords

D:\RobotFramework\MyKeywords>dir /p /s


 Katalog: D:\RobotFramework\MyKeywords

2013-11-07  20:25    <DIR>          .
2013-11-07  20:25    <DIR>          ..
2013-11-07  15:56               301 .classpath
2013-11-07  15:56               386 .project
2013-11-07  20:25    <DIR>          .settings
2013-11-07  20:25    <DIR>          bin
2013-11-07  20:25    <DIR>          src
           

 Katalog: D:\RobotFramework\MyKeywords\.settings

2013-11-07  20:25    <DIR>          .
2013-11-07  20:25    <DIR>          ..
2013-11-07  15:56               598 org.eclipse.jdt.core.prefs
               1 plik(ów)                598 bajtów

 Katalog: D:\RobotFramework\MyKeywords\bin

2013-11-07  20:25    <DIR>          .
2013-11-07  20:25    <DIR>          ..
2013-11-07  20:26    <DIR>          example


 Katalog: D:\RobotFramework\MyKeywords\bin\example

2013-11-07  20:26    <DIR>          .
2013-11-07  20:26    <DIR>          ..
2013-11-07  16:03               278 A.txt
2013-11-07  20:40           195 657 log.html
2013-11-07  15:57               937 MyKeywords.class
2013-11-07  20:40             5 951 output.xml
2013-11-07  20:40           199 481 report.html
2013-11-07  16:01        19 972 193 robotframework-2.8.1.jar
               6 plik(ów)         20 374 497 bajtów

 Katalog: D:\RobotFramework\MyKeywords\src

2013-11-07  20:25    <DIR>          .
2013-11-07  20:25    <DIR>          ..
2013-11-07  20:25    <DIR>          example
               0 plik(ów)                  0 bajtów

 Katalog: D:\RobotFramework\MyKeywords\src\example

2013-11-07  20:25    <DIR>          .
2013-11-07  20:25    <DIR>          ..
2013-11-07  16:03               278 A.txt
2013-11-07  16:03           195 196 log.html
2013-11-07  15:57               271 MyKeywords.java
2013-11-07  16:03             3 016 output.xml
2013-11-07  16:03           199 520 report.html
2013-11-07  16:01        19 972 193 robotframework-2.8.1.jar
               6 plik(ów)         20 370 474 bajtów


D:\RobotFramework\MyKeywords>
----

Is there anything wrong?

Btw.: Is there a possibility to run it directly from eclpise not having maven installed?

Markus Bernhardt

unread,
Nov 8, 2013, 10:29:28 AM11/8/13
to cami...@gmail.com, robotframe...@googlegroups.com
Well, I'm sorry, but there are several things you should fix.
Am I right that you never worked with Eclipse before? No pun intended.

The example directory is a Java Package directory inside the source directory.
Please do the following on a CMD shell:

D:
mkdir \RobotFramework\MyKeywords\lib
mkdir \RobotFramework\MyKeywords\testsuites
move \RobotFramework\MyKeywords\src\example\robotframework-2.8.1.jar \RobotFramework\MyKeywords\lib
move \RobotFramework\MyKeywords\src\example\A.txt \RobotFramework\MyKeywords\testsuites
del \RobotFramework\MyKeywords\src\example\*.html

Change in A.txt "Library MyKeywords" to "Library example.MyKeywords"

Then do a "Clean all" in Eclipse. After that there should be exactly one file in D:\RobotFramework\MyKeywords\bin\example: MyKeywords.class.

Then execute your test in a CMD shell:

D:
cd \RobotFramework\MyKeywords
java -cp lib\robotframework-2.8.1.jar;bin org.robotframework.RobotFramework testsuites 


Cheers,
Markus

kamirru

unread,
Nov 8, 2013, 12:30:44 PM11/8/13
to robotframe...@googlegroups.com
True - I am not very familiar with eclipse

I made steps you gave me, it looks better, but still some errors:


D:\RobotFramework\MyKeywords>java -cp lib\robotframework-2.8.1.jar;bin org.robotframework.RobotFramework testsuites
[ ERROR ] Error in file 'D:\RobotFramework\MyKeywords\testsuites\A.txt': Non-existing setting 'Library example.MyKeywords'.

==============================================================================
Testsuites
==============================================================================
Testsuites.A
==============================================================================
MyTestCase                                                            | FAIL |
No keyword with name 'say hi' found.
------------------------------------------------------------------------------
MyTestCase2                                                           | FAIL |
No keyword with name 'say hi' found.
------------------------------------------------------------------------------
MyTestCase3                                                           | FAIL |
No keyword with name 'type of' found.
------------------------------------------------------------------------------
Testsuites.A                                                          | FAIL |
3 critical tests, 0 passed, 3 failed
3 tests total, 0 passed, 3 failed
==============================================================================
Testsuites                                                            | FAIL |
3 critical tests, 0 passed, 3 failed
3 tests total, 0 passed, 3 failed
==============================================================================
Output:  D:\RobotFramework\MyKeywords\output.xml
Log:     D:\RobotFramework\MyKeywords\log.html
Report:  D:\RobotFramework\MyKeywords\report.html


I pick up the question, if it is possible to run it directly from eclipse without using maven?

Kevin O.

unread,
Nov 8, 2013, 3:04:47 PM11/8/13
to robotframe...@googlegroups.com
If you have your Build Path configured correctly, you should be able to run it directly from Eclipse. Letting Eclipse handle the classpath will make your life easier. Run your project as a Java application, using the main class of org.robotframework.RobotFramework. Use Program arguments in the run configuration UI to pass arguments into RF, e.g. D:\RobotFramework\MyKeywords\testsuites

It is unfortunate your company will not let you use Maven. Do they know that you can run your own repository like Artifactory and use access control to restrict what is allowed to be stored in it? If you can't use software capable of downloading other software to build software, then maybe should do the build on a Commodore 64 because it lacks a TCP/IP stack. LOL

Markus Bernhardt

unread,
Nov 9, 2013, 1:37:03 AM11/9/13
to cami...@gmail.com, robotframe...@googlegroups.com
Could you please post the complete content of A.txt

Von meinem iPhone gesendet
--

kamirru

unread,
Nov 9, 2013, 5:33:33 AM11/9/13
to robotframe...@googlegroups.com
Here is the A.txt testsuite:

*** Settings ***
Library example.MyKeywords
 
*** Test Cases ***
MyTestCase
    ${message}    say hi
    Log    ${message}
 
MyTestCase2
    ${message}    say hi    Kamirru

Markus Bernhardt

unread,
Nov 10, 2013, 2:12:05 PM11/10/13
to cami...@gmail.com, robotframe...@googlegroups.com
Please change:
Library example.MyKeywords

to:
Library    example.MyKeywords

kamirru

unread,
Nov 11, 2013, 6:03:00 AM11/11/13
to robotframe...@googlegroups.com
:)
It worked.

But... I wonder why? Does it depend on the number of spaces? 

I also have one question regarding what Kevin said: 
I am trying to run the test case directly from eclispe. I included org.robotframework.RobotFramework as main class, the path to MyKeywords\testsuites as arguments and I included the RF.jar to the classpath - but I am getting:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

Another issue that I have: 
let's assuem I have a public class (java) :

package example;

public class Run {
public static void main(String args[]) {
//how should I run the test from this point - is it possible?
}

}

Is it possible to run the TC from main?

Ahh - I do not know if it is necessarcy to open a new topic, if yes - just let me know:)

I also very appreciate your help. 
Thank you!

Markus Bernhardt

unread,
Nov 11, 2013, 6:20:20 AM11/11/13
to cami...@gmail.com, robotframe...@googlegroups.com

> :)
> It worked.
>
> But... I wonder why? Does it depend on the number of spaces?

In Robot a single space does not seperate statements. You need at least 2 space to seperate keywords and their parameter.

>
> I also have one question regarding what Kevin said:
> I am trying to run the test case directly from eclispe. I included org.robotframework.RobotFramework as main class, the path to MyKeywords\testsuites as arguments and I included the RF.jar to the classpath - but I am getting:
>
> Error occurred during initialization of VM
> java/lang/NoClassDefFoundError: java/lang/Object
>
> Another issue that I have:
> let's assuem I have a public class (java) :
>
> package example;
>
> public class Run {
>
> public static void main(String args[]) {
>
> //how should I run the test from this point - is it possible?
// That should work
org.robotframework.RobotFramework.main(args);
>
> }
>
> }
>
> Is it possible to run the TC from main?
>
> Ahh - I do not know if it is necessarcy to open a new topic, if yes - just let me know:)

Not for me.

Cheers,
Markus

chaudha...@gmail.com

unread,
Dec 18, 2014, 2:08:29 AM12/18/14
to robotframe...@googlegroups.com
Hi,

I'm trying to get the browser instance handle from my selenium webdriver script to the robot framework test cases using a custom keyword. However, everytime there is an error "ImportError: cannot import name Selenium2Library, "from Selenium2Library import Selenium2Library". This line has problem. Can anybody pls help?

-Geeta
Reply all
Reply to author
Forward
0 new messages