Created
January 11, 2014 19:21
-
-
Save hastebrot/8375513 to your computer and use it in GitHub Desktop.
This file contains 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
// PLUGINS. | |
apply plugin: "groovy" | |
// PROJECT. | |
version = "0.0.1" | |
sourceCompatibility = 1.7 | |
targetCompatibility = 1.7 | |
// DEPENDENCIES. | |
repositories { | |
maven { name = "maven central"; url = "http://repo1.maven.org/maven2/" } | |
} | |
dependencies { | |
compile "org.codehaus.groovy:groovy-all:2.2.1" | |
testCompile "junit:junit:4.11" | |
testCompile "org.spockframework:spock-core:0.7-groovy-2.0" | |
testCompile "org.loadui:testFx:3.0.0" | |
} |
This file contains 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 github.gist.testfx | |
import javafx.scene.Parent | |
import org.loadui.testfx.GuiTest | |
import spock.lang.Specification | |
abstract class GuiSpecification extends Specification { | |
GuiTest fx | |
void setupStage(Closure rootNodeFactory) { | |
fx = new GuiTestMixin() | |
fx.setRootNodeFactory(rootNodeFactory) | |
fx.setupStage() | |
} | |
static class GuiTestMixin extends GuiTest { | |
Closure rootNodeFactory | |
protected Parent getRootNode() { | |
return rootNodeFactory.call() as Parent | |
} | |
} | |
} |
This file contains 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 github.gist.testfx | |
import javafx.event.ActionEvent | |
import javafx.event.EventHandler | |
import javafx.scene.control.Button | |
import javafx.scene.control.Label | |
import javafx.scene.control.TextField | |
import javafx.scene.layout.HBox | |
import org.junit.experimental.categories.Category | |
import org.loadui.testfx.categories.TestFX | |
import static org.loadui.testfx.Assertions.verifyThat | |
import static org.loadui.testfx.controls.Commons.hasText | |
@Category(TestFX.class) | |
class TestFxSampleSpec extends GuiSpecification { | |
def setup() { | |
setupStage { | |
def passwordField = new TextField(id: "password") | |
def submitButton = new Button(id: "submit", text: "submit") | |
def messageLabel = new Label(id: "message") | |
submitButton.onAction = { ActionEvent event -> | |
if (passwordField.text == "fidelio") { | |
messageLabel.text = "please enter!" | |
} | |
else { | |
messageLabel.text = "wrong password!" | |
} | |
} as EventHandler | |
return new HBox(passwordField, submitButton, messageLabel) | |
} | |
} | |
def "enters gate with right password"() { | |
when: | |
fx.click("#password").type("fidelio") | |
fx.click("#submit") | |
then: | |
verifyThat("#message", hasText("please enter!")) | |
} | |
def "enters gate with wrong password"() { | |
when: | |
fx.click("#password").type("shibboleet") | |
fx.click("#submit") | |
then: | |
verifyThat("#message", hasText("wrong password!")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above code adapted for TestFX 4.0.1-alpha: https://gist.github.com/siordache/10fb0a65749c9122edda