Custom Keyword using Java and importing to RIDE

RIDE may not have the best User Interface, but if you look with attention, you will find the instructions on how to do the XML import.

If not in RIDE app, then I am sure we have info in the project page.

Thank you so much for replying. After importing the XML file in RIDE, the red color display of the Import section was gone and we were able to see the list of keywords in the suggestion at test case level.

But when we try to execute the same. I am getting the below error:
[ ERROR ] Error in file ‘C:\robotframework\TestDir\Implementation\UpointLogin’: Importing test library ‘SwingLibrary’ failed: ImportError: No module named SwingLibrary
Traceback (most recent call last):
None
PYTHONPATH:
C:\Python27\Scripts
C:\WINDOWS\SYSTEM32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
C:\Python27\lib\site-packages\win32
C:\Python27\lib\site-packages\win32\lib
C:\Python27\lib\site-packages\Pythonwin
C:\Python27\lib\site-packages\wx-2.8-msw-unicode
C:\Python27\lib\site-packages\robotide\contrib\testrunner…/…/lib

Can you please let us why why this issue still persists even after all these steps?

Thanks.

You have to use the correct Run Profile, jybot where you have defined the CLASSPATH to the SwingLibrary jar file. (And in the future to add your own jar files).

You can also add in Tools>Preferences>Import tab PYTHONPATH (but not sure if it works).

We have used the Run Profile as jybot and defined the classpath in jybot.bat which is placed inside C:\jython2.7.2\Lib\site-packages as:

@echo off
set CLASSPATH=C:\jython2.7.2\Lib\site-packages\swinglibrary-1.9.9.jar
jython -m robot %*

Added the path in PYTHONPATH as well.

Below is the error which we are facing after executing:
image

Error:
command: jybot.bat --argumentfile c:\users\ah0161759.hewitt-na\appdata\local\temp\RIDE5hl15v.d\argfile.txt --listener C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py:56729:False C:\robotFramework\LibrarayTest\TestLib
TestRunnerAgent: Running under Jython 2.7.2

[ ERROR ] Error in file ‘C:\robotFramework\LibrarayTest\TestLib’: Importing test library ‘SwingLibrary’ failed: NoClassDefFoundError: org/robotframework/javalib/library/KeywordDocumentationRepository
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.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)**
** at robot.utils.importer$py.import$14(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:167)**
** at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)**
** at robot.utils.importer$py.import
$29(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:257)**
** at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)**
** at robot.utils.importer$py._import_class_or_module$5(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:77)**
** at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)**
** at robot.utils.importer$py.import_class_or_module$4(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:74)**
** at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)**
** at robot.model.visitor$py.visit_suite$2(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py:88)**
** at robot.model.visitor$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py)**
** at robot.model.testsuite$py.visit$19(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py:168)**
** at robot.model.testsuite$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py)**
** at robot.run$py.main$3(C:/jython2.7.2/Lib/site-packages/robot/run.py:448)**
** at robot.run$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/run.py)**
** at robot.utils.application$py._execute$10(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py:94)**
** at robot.utils.application$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py)**
** at robot.utils.application$py.execute_cli$5(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py:49)**
** at robot.utils.application$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py)**
** at robot.run$py.run_cli$7(C:/jython2.7.2/Lib/site-packages/robot/run.py:488)**
** at robot.run$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/run.py)**
** at runpy$py._run_code$9(C:/jython2.7.2/Lib/runpy.py:73)**
** at runpy$py.call_function(C:/jython2.7.2/Lib/runpy.py)**
** at runpy$py._run_module_as_main$14(C:/jython2.7.2/Lib/runpy.py:161)**
** at runpy$py.call_function(C:/jython2.7.2/Lib/runpy.py)**
Caused by: java.lang.ClassNotFoundException: org.robotframework.javalib.library.KeywordDocumentationRepository
** 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)**
** … 194 more**
PYTHONPATH:
** \jython2.7.2\Lib\site-packages**
** C:\jython2.7.2\Lib**
** classpath**
** pyclasspath/**
** C:\jython2.7.2\Lib\site-packages**
** C:\Python27\lib\site-packages\robotide\contrib\testrunner…/…/lib**
CLASSPATH:
** C:\jython2.7.2\jython.jar**
** C:\jython2.7.2\Lib\site-packages\swinglibrary-1.9.9.jar**
==================================================================================================================================================================
**TestLib **
==================================================================================================================================================================

[ ERROR ] Error in file ‘C:\robotFramework\LibrarayTest\TestLib’: Importing test library ‘Selenium Library’ failed: ImportError: No module named Selenium Library
Traceback (most recent call last):
** None**
PYTHONPATH:
** \jython2.7.2\Lib\site-packages**
** C:\jython2.7.2\Lib**
** classpath**
** pyclasspath/**
** C:\jython2.7.2\Lib\site-packages**
** C:\Python27\lib\site-packages\robotide\contrib\testrunner…/…/lib**
CLASSPATH:
** C:\jython2.7.2\jython.jar**
** C:\jython2.7.2\Lib\site-packages\swinglibrary-1.9.9.jar**
**TestLib.UpointTest **
==================================================================================================================================================================

[ ERROR ] Error in file ‘C:\robotFramework\LibrarayTest\TestLib\UpointTest.robot’: Importing test library ‘SwingLibrary’ failed: NoClassDefFoundError: org/robotframework/javalib/library/KeywordDocumentationRepository
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.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)
at robot.utils.importer$py.import$14(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:167)
at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py.import
$29(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:257)
at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py._import_class_or_module$5(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:77)
at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py.import_class_or_module$4(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py:74)
at robot.utils.importer$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/importer.py)
at robot.model.visitor$py.visit_suite$2(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py:88)
at robot.model.visitor$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py)
at robot.model.testsuite$py.visit$19(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py:168)
at robot.model.testsuite$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py)
at robot.model.itemlist$py.visit$11(C:/jython2.7.2/Lib/site-packages/robot/model/itemlist.py:71)
at robot.model.itemlist$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/itemlist.py)
at robot.model.visitor$py.visit_suite$2(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py:88)
at robot.model.visitor$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/visitor.py)
at robot.model.testsuite$py.visit$19(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py:168)
at robot.model.testsuite$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/model/testsuite.py)
at robot.run$py.main$3(C:/jython2.7.2/Lib/site-packages/robot/run.py:448)
at robot.run$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/run.py)
at robot.utils.application$py._execute$10(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py:94)
at robot.utils.application$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py)
at robot.utils.application$py.execute_cli$5(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py:49)
at robot.utils.application$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/utils/application.py)
at robot.run$py.run_cli$7(C:/jython2.7.2/Lib/site-packages/robot/run.py:488)
at robot.run$py.call_function(C:/jython2.7.2/Lib/site-packages/robot/run.py)
at runpy$py._run_code$9(C:/jython2.7.2/Lib/runpy.py:73)
at runpy$py.call_function(C:/jython2.7.2/Lib/runpy.py)
at runpy$py._run_module_as_main$14(C:/jython2.7.2/Lib/runpy.py:161)
at runpy$py.call_function(C:/jython2.7.2/Lib/runpy.py)
Caused by: java.lang.ClassNotFoundException: org.robotframework.javalib.library.KeywordDocumentationRepository
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)
… 212 more
PYTHONPATH:
\jython2.7.2\Lib\site-packages
C:\jython2.7.2\Lib
classpath
pyclasspath/
C:\jython2.7.2\Lib\site-packages
C:\Python27\lib\site-packages\robotide\contrib\testrunner…/…/lib
CLASSPATH:
C:\jython2.7.2\jython.jar
C:\jython2.7.2\Lib\site-packages\swinglibrary-1.9.9.jar
Utest | FAIL |
No keyword with name ‘SwingLibrary.Add Table Cell Selection’ found.

Can you please help us why this issue occurs?

Thanks.

I was trying to help you getting the Jython environment working and RIDE too, having the keywords help for SwingLibrary. I believe this is already done.
On the previous message, you shown PYTHONPATH missing the path to jar files.
I was assuming that you were testing running the SwingLibrary demo test cases.
Did that worked?

What you show now seems that is referring to your initial goal of having a own library in Java. Now that you have a working environment, you have to know how to use your library. If just want to call it from command window with robot, then you have to add the path to the jar file in the CLASSPATH variable (seems that is missing).
If you want to have keywords documentation in RIDE, you have to create the XML file with libdoc, and import into RIDE.

I see missing SeleniumLibrary errors. You must install SeleniumLibrary in Jython.

If your are learning how to do this, then create a simple Java library and test it, before doing with more complex libraries.

Good luck. I think I helped enough.