Created
October 24, 2018 21:24
-
-
Save timmolderez/5af5adfa60e62989846750ccc01cb7a7 to your computer and use it in GitHub Desktop.
Software engineering - TestFX example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.thm.move | |
import java.awt.{MouseInfo, Robot} | |
import javafx.scene.input.{KeyCode, MouseButton} | |
import org.junit.Test | |
import org.junit.Assert._ | |
class DrawRectangleTest extends GuiTest { | |
/** | |
* Creates a new file, and draws a rectangle | |
*/ | |
@Test def drawRectangle(): Unit = { | |
clickOn("File") | |
clickOn("New file") | |
clickOn("OK") | |
clickOn("#rectangle_btn") | |
moveBy(200, 0) | |
press(MouseButton.PRIMARY).moveBy(200, 200).release(MouseButton.PRIMARY) | |
moveBy(-100, -100) | |
val loc = MouseInfo.getPointerInfo.getLocation | |
val pixelColor = new Robot().getPixelColor(loc.x, loc.y) | |
assertEquals(pixelColor.getRed, 251) | |
assertEquals(pixelColor.getGreen, 0) | |
assertEquals(pixelColor.getBlue, 7) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.thm.move | |
import de.thm.move.controllers.MoveCtrl | |
import javafx.event.EventHandler | |
import javafx.fxml.FXMLLoader | |
import javafx.scene.{Parent, Scene} | |
import javafx.stage.{Stage, WindowEvent} | |
import org.testfx.framework.junit.ApplicationTest | |
/** | |
* Base class for writing TestFX tests | |
*/ | |
abstract class GuiTest extends ApplicationTest { | |
override def start(stage: Stage): Unit = { | |
val windowWidth = Global.config.getDouble("window.width").getOrElse(600.0) | |
val windowHeight = Global.config.getDouble("window.height").getOrElse(600.0) | |
val fxmlLoader = new FXMLLoader(MoveApp.getClass.getResource("/fxml/move.fxml")) | |
fxmlLoader.setResources(Global.fontBundle) | |
val mainViewRoot: Parent = fxmlLoader.load() | |
val scene = new Scene(mainViewRoot) | |
scene.getStylesheets.add(Global.styleSheetUrl) | |
stage.setTitle(Global.config.getString("window.title").getOrElse("")) | |
stage.setScene(scene) | |
stage.setWidth(windowWidth) | |
stage.setHeight(windowHeight) | |
stage.show() | |
val ctrl = fxmlLoader.getController[MoveCtrl] | |
ctrl.setupMove(stage, None) | |
stage.setOnCloseRequest(new EventHandler[WindowEvent] { | |
override def handle(event: WindowEvent): Unit = { | |
ctrl.shutdownMove() | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment