Skip to content

Commit

Permalink
Merge pull request #137 from sergei-ivanov/master
Browse files Browse the repository at this point in the history
Respect headless mode instead of enforcing it
  • Loading branch information
hastebrot committed Aug 20, 2014
2 parents 6370432 + 84533e0 commit 0d8eeb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.stage.Window;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.BeforeClass;
import org.loadui.testfx.framework.app.StageSetupCallback;
import org.loadui.testfx.framework.junit.AppRobotTestBase;
import org.loadui.testfx.robots.impl.ScreenRobotImpl;
Expand All @@ -33,13 +34,15 @@
import org.loadui.testfx.service.support.CaptureSupport;
import org.loadui.testfx.service.support.WaitUntilSupport;

import java.awt.GraphicsEnvironment;
import java.io.File;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;

import static org.junit.Assume.assumeFalse;

public abstract class GuiTest extends AppRobotTestBase implements StageSetupCallback {

//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -165,6 +168,13 @@ public static File captureScreenshot() {
// METHODS.
//---------------------------------------------------------------------------------------------

@BeforeClass
public static void checkHeadless() {
assumeFalse(
"Cannot run JavaFX in headless environment",
GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance());
}

@Before
public void setupGuiTest() throws Exception {
setupApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@
*/
package org.loadui.testfx.robots.impl;

import com.google.common.collect.ImmutableMap;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import org.loadui.testfx.robots.ScreenRobot;
import org.loadui.testfx.utils.FXTestUtils;

import java.awt.AWTException;
import java.awt.GraphicsEnvironment;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
Expand All @@ -24,16 +35,6 @@
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.util.Map;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;

import com.google.common.collect.ImmutableMap;
import org.loadui.testfx.robots.ScreenRobot;
import org.loadui.testfx.utils.FXTestUtils;

public class ScreenRobotImpl implements ScreenRobot {

Expand All @@ -58,7 +59,10 @@ public class ScreenRobotImpl implements ScreenRobot {
//---------------------------------------------------------------------------------------------

public ScreenRobotImpl() {
System.setProperty("java.awt.headless", "false");
if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
awtRobot = null;
return;
}
Toolkit.getDefaultToolkit();
awtRobot = createAwtRobot();
}
Expand Down

0 comments on commit 0d8eeb7

Please sign in to comment.