Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: java 11 support #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -260,7 +260,7 @@
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.7.1</version>
<version>2.1.0</version>
<executions>
<execution>
<id>acceptance tests</id>
Expand Down Expand Up @@ -367,6 +367,39 @@
</build>

<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>mac</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
Expand All @@ -391,7 +424,7 @@
<dependency>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>8u76-b04</version>
<version>jdk-12.0.1+2</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jdk-11+26 version did not work. Had some missing methods. Upgrading resolved issues.

</dependency>
<dependency>
<groupId>org.robotframework</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/JavaFXLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public JavaFXLibrary(boolean headless) {
if (headless) {
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("glass.platform", "Monocle");
System.setProperty("monocle.platform", "Headless");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relates to previous comment. Maybe these are not necessary?

System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
TestFxAdapter.isHeadless = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ private Class getMainClass(String appName) {
}

private void addPathToClassPath(String path) {
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

RobotLog.info("Setting following path to classpath: " + path);

try {
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(classLoader, (new File(path)).toURI().toURL());
URL[] urls = new URL[]{new File(path).toURI().toURL()};
URLClassLoader classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());

} catch (Exception e) {
throw new JavaFXLibraryFatalException("Problem setting the classpath: " + path, e);
Expand Down Expand Up @@ -176,11 +174,11 @@ public void setToClasspath(String path, boolean failIfNotFound) {
@RobotKeyword("Logs current classpath content")
public void logApplicationClasspath() {
try {
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
RobotLog.info("Printing out classpaths: \n");
for (URL url : urls) {
RobotLog.info(url.getFile());

String classpathStr = System.getProperty("java.class.path");
for (String classpathItem : classpathStr.split(System.getProperty("path.separator"))) {
RobotLog.info(classpathItem);
}
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Unable to log application classpaths", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package javafxlibrary.keywords.AdditionalKeywords;

import com.sun.javafx.scene.control.skin.TableViewSkin;
import com.sun.javafx.scene.control.skin.VirtualFlow;
import javafx.scene.control.skin.TableViewSkin;
import javafx.scene.control.skin.VirtualFlow;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.geometry.BoundingBox;
Expand Down Expand Up @@ -279,7 +279,7 @@ public String getNodeText(Object locator) {
@RobotKeyword("Returns image name and path of the node. \n\n"
+ "``locator`` is either a _query_ or _Object_ for a node whose getHeight method will be called, see "
+ "`3. Locating JavaFX Nodes`. \n\n"
+ "Returns full image path by subsequently calling impl_getUrl -method. \n\n"
+ "Returns full image path by subsequently calling getUrl -method. \n\n"
+ "Note, impl_getUrl -method is deprecated! Support for this method will be removed from Java in the future.")
@ArgumentNames({"node"})
public String getNodeImageUrl(Object locator) {
Expand All @@ -294,8 +294,7 @@ public String getNodeImageUrl(Object locator) {
try {
Object result = m.invoke(node, (Object) null);
Image image = (Image) result;
RobotLog.trace("Calling deprecated method impl_getUrl() for image: \"" + image + "\"");
return image.impl_getUrl();
return image.getUrl();
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Problem calling method: .getImage(): " + e.getMessage(), e);
}
Expand Down Expand Up @@ -477,15 +476,22 @@ public List<Object> getTableColumnValues(Object locator, int column) {
public List<Object> getTableColumnCells(Object locator, int column) {
checkObjectArgumentNotNull(locator);
try {
List<Object> columnCells = new ArrayList<>();

RobotLog.info("Getting table \"" + locator + "\" cells from column \"" + column + "\".");
TableView table = (TableView) objectToNode(locator);
List<Object> columnCells = new ArrayList<>();
VirtualFlow<?> vf = (VirtualFlow<?>) ((TableViewSkin<?>) table.getSkin()).getChildren().get(1);

for (int i = vf.getFirstVisibleCell().getIndex(); i < vf.getLastVisibleCell().getIndex() + 1; i++) {
RobotLog.info("Index number: " + i);
columnCells.add(mapObject(vf.getCell(i).getChildrenUnmodifiable().get(column)));
}
Optional<VirtualFlow> vf = table.getChildrenUnmodifiable().stream().filter(node -> node instanceof VirtualFlow).map(VirtualFlow.class::cast).findFirst();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed public API in JavaFX.


vf.ifPresentOrElse(virtualFlow -> {
for (int i = virtualFlow.getFirstVisibleCell().getIndex(); i < virtualFlow.getLastVisibleCell().getIndex() + 1; i++) {
RobotLog.info("Index number: " + i);
columnCells.add(mapObject(virtualFlow.getCell(i).getChildrenUnmodifiable().get(column)));
}
}, () -> {
throw new JavaFXLibraryNonFatalException("Could not find VirtualFlow from Tableview!");
});

return mapObjects(columnCells);
} catch (ClassCastException cce) {
throw new JavaFXLibraryNonFatalException("Unable to handle argument as TableView!");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/javafxlibrary/TestFxAdapterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public FxRobotInterface getRobot() {
public static void setupTests() {
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("glass.platform", "Monocle");
System.setProperty("monocle.platform", "Headless");
System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package javafxlibrary.testapps.controllers;

import com.sun.javafx.scene.control.skin.TextAreaSkin;
import javafx.scene.control.skin.TextAreaSkin;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
Expand Down Expand Up @@ -52,15 +52,9 @@ public void initialize(URL location, ResourceBundle resources) {
@Override
public void handle(KeyEvent event) {
if (event.getCode().equals(KeyCode.TAB)) {
if (event.isShiftDown()) {
textArea.setText(textArea.getText() + " ");
textArea.positionCaret(textArea.getText().length());
event.consume();
} else {
TextAreaSkin skin = (TextAreaSkin) textArea.getSkin();
skin.getBehavior().traverseNext();
event.consume();
}
textArea.setText(textArea.getText() + " ");
textArea.positionCaret(textArea.getText().length());
event.consume();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import javafx.scene.input.MouseButton;
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
import javafxlibrary.utils.HelperFunctions;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -50,7 +53,7 @@ public void getMouseButtons_MultipleValues() {
public void getMouseButtons_InvalidValue() {
thrown.expect(JavaFXLibraryNonFatalException.class);
// thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("\"HUGE_RED_ONE\" is not a valid MouseButton. Accepted values are: [NONE, PRIMARY, MIDDLE, SECONDARY]");
thrown.expectMessage("\"HUGE_RED_ONE\" is not a valid MouseButton. Accepted values are: " + Arrays.asList(MouseButton.values()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a mouse with back and forward buttons. Test failed since message had BACK and FORWARD values.

HelperFunctions.getMouseButtons(new String[]{"HUGE_RED_ONE"});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void mapObjects_FromSet() {

@Test
public void mapObjects_FromQueue() {
Queue<Button> queue = new PriorityQueue<>();
Queue<Button> queue = new LinkedList<>();
queue.add(button);
List<Object> keys = HelperFunctions.mapObjects(queue);
Button b = (Button) TestFxAdapter.objectMap.get(keys.get(0));
Expand Down
2 changes: 1 addition & 1 deletion src/test/robotframework/acceptance/MiscTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Get Table Cell Value Using Index That Is Out Of Bounds
Set Test Application javafxlibrary.testapps.TestTableManagement
${TABLE} Find id=table
${MSG} Run Keyword And Expect Error * Get Table Cell Value ${TABLE} 0 40
Should Be Equal ${MSG} Out of table bounds: Index: 40, Size: 5
Should Be Equal ${MSG} Out of table bounds: Index 40 out of bounds for length 5

Get Object Property
[Tags] smoke
Expand Down