It errors when specifying the user defined java library into RED robot framework eclipse editor - eclipse

My requirement is to make use of user defined java libraries in robot framework using RED eclipse editor. When trying to specify library in the robot framework, the system errors as no such library available(shown underline in red for library name). Please correct my mistakes done. I have followed the below steps,
Updated Eclipse with RED Editor(Eclipse Neon (v 4.6), RED - Robot Editor v0.7.5)
Created a class file just as Project in the same eclipse. (Package name: org.robot.KCCKeywords and Class Name: LogonToKCC)
Converted the class file into the type '.JAR' and stored it in jython folder(C:\jython2.7.0\Lib\site-packages\KCCLibraries)
Integrated RED with Maven plugin using launch4j-3.8-win32(using https://github.com/nokia/RED/blob/9d62dccce18ee7f3051162d05bf3d027e33dccef/red_help/user_guide/maven.html.md)
Integrated RED with Robot framework and Jython. (using https://github.com/nokia/RED/blob/9d62dccce18ee7f3051162d05bf3d027e33dccef/red_help/user_guide/maven.html.md)
CLASS PATH updated for below jars,
a) jython.jar
b) robotframework-3.0.2.jar
c) myOwnJavaLibrary.jar ( The jar that i created in step 3)
d) jdk and jre path
Verified the same class paths in red.xml too.
Created RED Project and started initializing key words as below,
a) Library Selenium2Library
b) Library org.robot.KCCKeywords.LogonToKCC
Here is where the system couldn't read my own library.
I also referred to below blogs and adjusted my steps accordingly. But didn't help me. Referring to multiple blogs and stacks also confusing me. Finally I'm here.
robot framework user java libraries error Test Library "mavenPackage.MyKeyWords.java" does not exist
Robot Framework-RIDE,Import Java Libraries
Stuck with creating Keyword library using Java in Eclipse and using that JAR file in RIDE
Robot Framework - using User Libraries

Using the codecentric blog: Robot Framework Tutorial – Writing Keyword Libraries in Java as a base with some specific steps for RED in stead of RIDE. This walkthrough will allow you to setup Jython, create a simple library in Java and run it from Robot script.
After the installation of Eclipse (NEON) and RED Feature in Eclipse create a new Java project in Eclipse. With that done continue to create a new Java class with the following content.
package org.robot.sample.keywords;
import java.util.Stack;
/**
* This is an example for a Keyword Library for the Robot Framework.
* #author thomas.jaspers
*/
public class SampleKeywordLibrary {
/** This means the same instance of this class is used throughout
* the lifecycle of a Robot Framework test execution.
*/
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
//</editor-fold>
/** The Functionality to be tested */
private Stack<String> testStack;
/**
* Keyword-method to create an empty stack.
*/
public void createAnEmptyStack() {
testStack = new Stack<String>();
}
/**
* Keyword-method to add an element to the stack.
* #param element The element
*/
public void addAnElement(String element) {
testStack.push(element);
}
/**
* Keyword-method to remove the last element from the stack.
*/
public void removeLastElement() {
testStack.pop();
}
/**
* Keyword-method to search for an element position.
* #param element The element
* #param pos The expected position
*/
public void elementShouldBeAtPosition(String element, int pos)
throws Exception {
if (testStack.search(element) != pos) {
throw new Exception("Wrong position: " + testStack.search(element));
}
}
/**
* Keyword-method to check the last element in the stack.
* #param result Expected resulting element
*/
public void theLastElementShouldBe(String result) throws Exception {
String element = testStack.pop();
if (!result.equals(element)) {
throw new Exception("Wrong element: " + element);
}
}
}
Please ensure that you have Jython installed using the Windows Installer. In my example Jython is installed in c:\Jython. As with the regular Python Interpreter Robot Framework still needs to be installed. Assuming that your machine has access to the internet, in the command line go to c:\Jython\bin\ and run the command pip install robotframework. This will install Robot Framework in the Jython environment.
Now create a new Robot Framework project in Eclipse. Please make sure that you have Window > Perspective > Open Perspective > Robot or Other > Robot.
In the project the default Robot Framework is one based on Python and we need to configure the Jython Interpreter. In Eclipse go to Window > Preferences and then select Robot Framework > Installed Frameworks from the tree-menu. Click on Add and point to c:\Jython\bin\. Click on OK.
Open Red.XML from the Robot Project and go to the general tab. This is where the project Interpreter is set. If it is set to Python (like the example below) then click on use local settings for this project and check the Jython interpreter. Save the settings to the file (CTRL-S).
With Robot Framework project setup it is time to export the Java class to a Jar file. Right click the class file and click export. Then choose JAR file and click next. Click on Browse and set the location and file name of the JAR file. In this case I picked ExampleLibrary.jar and the folder of my Robot Project. Press Finish to complete the export.
Go Back to Red.XML and click on Referenced Libraries then proceed to click on Add Java library, pick the exported Jar file (ExampleLibrary.jar) and press OK. This will proceed to load the jar and read the keywords from the Jar file. Save the file (CTRL-S). This should result to the below reference.
Now it's time to create a Robot file and use the library. In the referenced blog the following example script is given that uses the java functions/keywords.
*** Settings ***
Library org.robot.sample.keywords.SampleKeywordLibrary
*** Test Cases ***
ExampleJava
Create An Empty Stack
Add An Element Java
Add An Element C++
Remove Last Element
The Last Element Should Be Java
With the already loaded library no red lines should appear, but otherwise right-click on the library and click quick-fixand autodiscover the library.
Then using the regular Eclipse/RED Run menu run the script. This will then run the script successfully and output the following:
Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Eclipse\Workspace\ExamplJava\ExampleLibrary.jar -m robot.run --listener C:\Users\User\AppData\Local\Temp\RobotTempDir8926065561484828569\TestRunnerAgent.py:57292:False -s ExamplJava.ExampleJava C:\Eclipse\Workspace\ExamplJava
Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_60)
==============================================================================
ExamplJava
==============================================================================
ExamplJava.ExampleJava
==============================================================================
ExampleJava | PASS |
------------------------------------------------------------------------------
ExamplJava.ExampleJava | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
ExamplJava | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Eclipse\Workspace\ExamplJava\output.xml
Log: C:\Eclipse\Workspace\ExamplJava\log.html
Report: C:\Eclipse\Workspace\ExamplJava\report.html

I finally followed the below for a great journey with robot framework.
1 Installed Java, Eclipse, RED Eclipse plugin.
a) Java(JDK 1.8.0/JRE 1.8.0)
b) Eclipse Neon (v 4.6)
c) RED - Robot Eclipse Editor v0.7.5.2(Eclipse Plugin)
2 Downloaded and Installed Python 2.7.12 using windows. A folder created automatically after installation in C:\python27
3 "Installed Robot Framework using pip command in Command Prompt.
Command: C:\python27\scripts>pip install robotframework"
4 Downloaded and installed Jython 2.7.0 using windows. A folder created automatically after installation in C:\jython2.7.0
5 "Installed Robot Framework using pip command in Command Prompt.
Command: C:\jython2.7.0\bin>pip install robotframework"
6 "Installed Selenium2Library using pip command in Command Prompt.
Command: C:\jython2.7.0\bin>pip install robotframework-selenium2library"
7 "Set the below,
a) Goto Window-Preferences-Robot Framework-Installed Framework
b) Map Robot framework with Jython Interpreter
I used c:\jython2.7.0\bin"
8 Created JavaProject and export it into a jar file. Right click on the class name, click on export-Java-Jarfile. Select the path name where the new jar file to be put including the new file name.jar. Click Ok.
9 Open RED.xml Click Add Java Library and select the newly created jar file.
10 "Set up this before proceeding with robot framework
goto Windows - Perspective - Open Perspective-Other-Robot"
11 Create a robot suite, import library selenium2library & user defined library, Write Test cases.

Related

Unable to run/debug robot tests in vscode - robocorp extensions installed

I have installed Robocorp Code as well as Robot Framework Language Server and have configured them. However, I am still having errors when trying to run the tests via the code lens options.
Repo - A webapi repo with a specific folder containing all tests. Lets call it regression.
RF - 4.1.3
Python - 3.8
This is what happens when I click on Run on the code lens for any of the tests -
`PS C:\git\xxxx\regression> C:; cd 'C:\git\xxxx\regression'; &
'C:\Users\xxxx\AppData\Local\Temp\rf-ls-run\run_env_00_smh5defr.bat'
'-u'
'c:\Users\xxxx.vscode\extensions\robocorp.robotframework-lsp-0.47.2\src\robotframework_debug_adapter\run_robot__main__.py'
'--port' '54331' '--no-debug' '--argumentfile'
'C:\git\xxxx\regression\args-local.txt' '--pythonpath'
'c:\git\xxxx\regression\common\lib' '--variable'
'EXECDIR:C:/git/xxxx/regression'
'--prerunmodifier=robotframework_debug_adapter.prerun_modifiers.FilteringTestsSuiteVisitor'
'c:\git\xxxx\regression\api\api_Test.robot'
[ ERROR ] Parsing'--pythonpath' failed: File or directory to execute does not exist.
However, the test starts if I remove the argumentfile parameter but it, of course, fails because its missing arguments from the file.
Do note that the folder specified in pythopath exists and has some python libraries needed for the tests.

Eclipse/Java9: how to access internal javafx packages?

My context:
Eclipse IDE for Java Developers, Version: Oxygen.1a Release (4.7.1a), Build id: 20171005-1200oxygen
jdk9.0.1
win10
Something simple like:
import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;
import javafx.application.Application;
import javafx.stage.Stage;
public class ImportCom extends Application {
#Override
public void start(Stage arg0) throws Exception {
new LambdaMultiplePropertyChangeListenerHandler();
}
}
won't compile due to
The type com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler is not accessible
What to do?
looks similar but now for internal classes ;) Had been compiling until patch 530 of the beta9 support but not after - so keeping that oldish oxygen as a gold treasure ...
Note: cross-posted to eclipse forum
Edit:
Just checked that the behavior of javac on the commandline:
C:\Users\kleopatra\ox-1a-64\dummy\src>\java\jdk\190-64\bin\javac first\ImportCom.java
first\ImportCom.java:3: error: package com.sun.javafx.scene.control is not visible
import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;
^
(package com.sun.javafx.scene.control is declared in module javafx.controls, which does not export it to the unnamed module)
1 error
The error is similar to the one in Eclipse. Works fine with --add-exports:
C:\Users\kleopatra\ox-1a-64\dummy\src>\java\jdk\190-64\bin\javac --add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED first\ImportCom.java
So the question boils down to: where/how to configure Eclipse such that it compiles access to internal classes just the same way as javac?
In Project > Properties: Java Build Path, Libraries tab, select the node Modulepath/JRE System Library[JavaSE-9]/Is modular and click Edit...
In the Module Properties dialog, in the Details tab, in the Added exports section click Add... and enter the following:
Source module: javafx.controls
Package: com.sun.javafx.scene.control
Click OK twice to close the Add-exports configuration and the Module Properties dialogs and Apply and Close to close the Properties dialog
Well, it's a bit hidden:
open Java Build Path dialog of the project
select Libraries tab
select isModular entry
use the Edit... button to open the module properties dialog
select Details tab
create all required entries with the Add.. button
If you have installed the Beta plugin for Java 9 support - uninstall. Make sure the latest Java 9 support plugin is installed.
In order to solve this issue you have to add the compiler argument
--add-exports=javafx.controls/com.sun.javafx.scene.control=A‌​LL-UNNAMED.
This can be done in Eclipse too but I have to admit at a very hidden place.
Go to the properties of your project and then to the Java Build Path.
Select Modulepath and then the JRE System library (should be java 9).
Inside that you find an item "is modular". Select that. Then open "Edit"
on the right and a menu will open. At the top select "Details". There you will see a table where you can add your exports. Believe it or not but it works :-) I had to clean and re-build the project though in order to really get this compiled.

Eclipse Indigo CDT: Function could not be resolved

This feels silly, but its been 2 days...somewhere after upgrading from Ubuntu 10.04 to 10.11 and from Eclipse Helios to Eclipse Indigo, I got stuck with the following problem:
Problem Description:
I'm trying to use a function in math.h called isinf(), but the problem also occurs with things like isnan(). The program compiles fine on the command line using make and fine in eclipse using build. But if I open the program file in eclipse it reports that it cannot reolve the isinf() function call. If I just insert the program contents into a new project and new source file, the error appears immediately. This problem did not occur under 11.04 with Eclipse Helios CDT
Questions:
Why are these errors only reported when the program file is opened and not on when the program is compiled; why are the errors not detected make is run from the command line? Is there a solution/workaround available?
Version Info
Linux Ubuntu 10.11 64-bit
Eclipse CDT Indigo, Service Release 1, Build id: 20110916-0149
(Also using Eclipse EE Indigo – if that makes a difference)
GNU Make 3.81
gcc 4.6.1-9Ubuntu3
To Duplicate:
Please find the two files you'll need to replicate below:
Step 0. Verify that everything is fine outside of Eclipse
Copy the attached source file and make file
create a directory e.g. Mkdir FunTest
Save the source file a 'Test.cpp' and the makefile as 'makefile'
Open a command prompt and navigate to the directory e.g. FunTest
Enter 'make'
Enter ./TestOut
Program responds “is not infinite”
Step 1. Create the project in Eclipse
Open Eclipse
Select File|New|MakeFile Project with Existing Code
Click Browse – navigate to the directory (FunTest) and click ok
Select 'Linux GCC' from the Toolchain selector
Click Finish
Step 2. Find the Error
Click Build All (Ctrl-B) – project builds without errors
Open the project in the project explorer to display the file in the directory
Double click on the file “Test.cpp”
Note the error icon next to line testing for infinity
Note the 2 error messages:
Semantic error: Function _isinff could not be resolved
Semantic error: Function _isinfl could not be resolved
Test.cpp:
include <math.h>
int main(int argc, char **argv)
{
int TestNum = 10;
if (isinf(TestNum) == 0)
printf("Not infinite\n");
return 0;
}
makefile:
# Specify the compiler
CC = g++
# Specify the compiler flags
CFLAGS += -c
# Specify the files making up the application
SOURCES = Test.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = TestOut
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $#
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $#
install:
#echo "Build complete!"
I have experienced similar problems of the CDT reporting errors even though the code compiled fine within Eclipse Indigo.
Project > Properties > Settings > Binary Parsers > "GNU Elf Parser"
helped in my case. I had the "Elf Parser" checked.
That looks like a problem that many others have had with eclipse CDT before. Sometimes shutting eclipse down and then starting it back up again is enough to help. If that isn't the case, take a look at what I have below:
Compilation ok, but eclipse content assist having problems
Check your includes: if you're using include<math.h> change it to include<cmath>. The same for stdio.h and stdlib.h, you should replace by cstdio and cstdlib. Another option may be change you project to a C project instead of a C++.
You are missing -lm option in your build preferences.
Project->Properties->Settings->Miscleanous->Other (linker) flags[]
For me, it was solved by adding a specific ‘Source Location’ folder, and removing the default. In Luna, it is under:
Project > Properties > C/C++ General > Paths and Symbols > Source
Location

Why would Eclipse not be able to include a file when running a PHPUnit test?

I have the following class and unit test in a PHP project in Eclipse:
I know my unit test works as I can run it at the command line:
Now I want to run this test from Eclipse. I set up PHP Unit in Eclipse like this:
However, when I run the PHPUnit tests:
It tells me that it can't include the class file:
/usr/bin/php -c /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/zend_debug/session4910937990995915704.tmp -d asp_tags=off /Applications/eclipse/plugins/org.phpsrc.eclipse.pti.tools.phpunit_0.5.0.R20101103000000/php/tools/phpunit.php --log-junit /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/pti_phpunit/phpunit.xml /Volumes/data/domains/et/extjslayout/phpunittest/tests
PHP Warning: include_once(../Product.php): failed to open stream: No such file or directory in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Warning: include_once(): Failed opening '../Product.php' for inclusion (include_path='/usr/local/PEAR') in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Fatal error: Class 'Product' not found in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 9
Why would PHPUnit be able to find the class when run from the command line but not when run from Eclipse?
When you start something from the command line, the "current directory" has a well-defined meaning: It's the directory where you started the command.
In Eclipse, what is the "current directory"? It's probably the directory from which you started Eclipse or maybe the folder in which Eclipse is installed.
I haven't used PHP in Eclipse before but for other languages, I can set the current directory in the launch config somewhere. If that doesn't work, define a variable which points to your project and then use absolute paths (using that variable as a starting point).
Have same problem. Found only solution by creating tests with internal PHPUnit wizard like at this screenshot:
Source: HowTo create a Test Case Class from a PHP Class
But following investigate show that your test case file should contain reference to tested code for example like this: require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';
Other experiments with plugin config not bringing luck. So in my opinion PHPUnit from PHP Tools not well developed plugin. Consider using MakeGood plugin as better alternative.

Error Using MathFP class in Eclipse

I am tryin to develop a game in j2m using eclipse. To handle floating point I have downloaded the MathFp class. I did the following steps
i placed the mathFP.class file in net/jscience/math/kvm/ directory
1> Ziped the folder containig the downloaded class.
2> java build path->libraries->ADD jar->selected my zipped folder.
3> in the source code of my project i wrote import net.jscience.math.kvm.MathFP;
But when i compile it it shows NoClassDefFoundError
Ensure the relevant jar is checked in the "Java Build Path" -> "Order and Export" window.