From 05178b75bc867ba06528aeb8ef44ea1911ab9422 Mon Sep 17 00:00:00 2001 From: Hallvard Traetteberg <hal@ntnu.no> Date: Wed, 24 Jan 2018 09:53:08 +0100 Subject: [PATCH] Experimental support for headless JavaFX tests using Monocle --- .gitlab-ci.yml | 5 ++-- tdt4140-gr1800/app.ui/pom.xml | 29 ++++++++++++++++--- .../java/tdt4140/gr1800/app/ui/FxAppTest.java | 8 +++++ .../gr1800/app/ui/GitlabCISupport.java | 16 ++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/GitlabCISupport.java diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c83acd3..0c2a715 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ -image: kaiwinter/docker-java8-maven +image: krissrex/docker-java8-maven-testfxmonocle:1.0 +# image: kaiwinter/docker-java8-maven # image: maven:3.3.9-jdk-8 # most of this taken from https://stackoverflow.com/questions/37785154/how-to-enable-maven-artifact-caching-for-gitlab-ci-runner @@ -11,7 +12,7 @@ cache: variables: MAVEN_OPTS: "-Djava.awt.headless=true -Dmaven.repo.local=.m2/repository" - MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -Dskip-ui-tests=true" + MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -Dgitlab-ci=true build-job: stage: build diff --git a/tdt4140-gr1800/app.ui/pom.xml b/tdt4140-gr1800/app.ui/pom.xml index 0511740..579df81 100644 --- a/tdt4140-gr1800/app.ui/pom.xml +++ b/tdt4140-gr1800/app.ui/pom.xml @@ -9,6 +9,31 @@ <version>0.0.1-SNAPSHOT</version> </parent> + <profiles> + <profile> + <id>gitlab-ci</id> + <activation> + <property> + <name>gitlab-ci</name> + <value>true</value> + </property> + </activation> + <!-- + <properties> + <skip-ui-tests>true</skip-ui-tests> + </properties> + --> + <dependencies> + <dependency> + <groupId>org.testfx</groupId> + <artifactId>openjfx-monocle</artifactId> + <version>8u76-b04</version> <!-- jdk-9+181 for Java 9 --> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> + <dependencies> <dependency> <groupId>tdt4140-gr1800</groupId> @@ -49,10 +74,6 @@ </dependency> </dependencies> - <properties> - <skip-ui-tests>false</skip-ui-tests> - </properties> - <build> <plugins> <plugin> diff --git a/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/FxAppTest.java b/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/FxAppTest.java index 254f782..5bded2b 100644 --- a/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/FxAppTest.java +++ b/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/FxAppTest.java @@ -1,6 +1,7 @@ package tdt4140.gr1800.app.ui; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; @@ -13,6 +14,13 @@ import javafx.stage.Stage; public class FxAppTest extends ApplicationTest { + @BeforeClass + public static void headless() { + if (Boolean.valueOf(System.getProperty("gitlab-ci", "false"))) { + GitlabCISupport.headless(); + } + } + @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("FxApp.fxml")); diff --git a/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/GitlabCISupport.java b/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/GitlabCISupport.java new file mode 100644 index 0000000..2a1c9d7 --- /dev/null +++ b/tdt4140-gr1800/app.ui/src/test/java/tdt4140/gr1800/app/ui/GitlabCISupport.java @@ -0,0 +1,16 @@ +package tdt4140.gr1800.app.ui; + +public class GitlabCISupport { + + public static void headless() { + System.setProperty("prism.verbose", "true"); // optional + System.setProperty("java.awt.headless", "true"); + 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"); + System.setProperty("testfx.setup.timeout", "2500"); + } +} -- GitLab