RegionChooserGUITest.java 2.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package eu.simstadt.regionchooser;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Paths;
import java.util.concurrent.TimeoutException;
import java.util.prefs.Preferences;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import javafx.application.Platform;
import javafx.stage.Stage;


@ExtendWith(ApplicationExtension.class)
class RegionChooserGUITest
{
	private static final String TEST_REPOSITORY_PATH = Paths.get("../../TestRepository").toAbsolutePath().toString();
	private static String originalRepository;
	private static Preferences userPrefs = Preferences.userRoot().node("/eu/simstadt/desktop");

	private FxRobot robot;

	@BeforeAll
	/**
	 * This method makes sure that the JavaFX/TestFX tests are run in headless mode. They should work on Linux Server,
	 * thanks to https://github.com/TestFX/Monocle
	 *
	 * Alternatively, in order to force headless mode from Maven:
	 *
	 * mvn clean package -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k
	 *
	 * More info:
	 *
	 * https://stackoverflow.com/questions/27403410/headless-testing-with-javafx-and-testfx
	 * https://medium.com/@danielnenkov/run-testfx-tests-on-jenkins-running-on-ec2-d68197e10e2b
	 */
	private static void setupHeadlessTests() {
		//		System.setProperty("testfx.robot", "glass");
		//		System.setProperty("testfx.headless", "true");
		//		System.setProperty("prism.order", "sw");
		//		System.setProperty("prism.text", "t2k");
	}

	@BeforeAll
	private static void setRepositoryToTestRepository() {
		originalRepository = userPrefs.get("RECENT_REPOSITORY", TEST_REPOSITORY_PATH);
		userPrefs.put("RECENT_REPOSITORY", TEST_REPOSITORY_PATH);
	}

	@AfterAll
	private static void resetRepositoryToOriginalRepository() {
		userPrefs.put("RECENT_REPOSITORY", originalRepository);
	}

	/**
	 * Will be called with {@code @Before} semantics, i. e. before each test method.
	 *
	 * @param stage - Will be injected by the test runner.
	 */
	@Start
	private void start(Stage stage) {
		Platform.runLater(() -> new RegionChooserFX().start(stage));
	}

	/**
	 * @param robot - Will be injected by the test runner.
	 * @throws InterruptedException
	 * @throws TimeoutException
	 */
	@Test
	void testClickOnRegionChooser(FxRobot testRobot) throws InterruptedException, TimeoutException {
		this.robot = testRobot;
		System.out.println(robot.window(0).getScene());
		System.out.println(robot.lookup("#RegionChooserBrowser").query());
		//		WaitForAsyncUtils.waitFor(30, TimeUnit.SECONDS, () -> !runButton.isDisabled());
		robot.clickOn("TEST");
		assertTrue(false);
	}
}