Использование TestFX с огурцом - PullRequest
0 голосов
/ 17 октября 2018

Я пытаюсь использовать Cucumber с TestFX, но не могу получить какие-либо узлы из приложения.

У меня есть другой класс TestFX, который отлично работает, и другой класс Cucumber, который также работает нормально.Но я получаю

org.loadui.testfx.exceptions.NoNodesFoundException: не найдено ни одного узла 'TextInputControl имеет текст "Вы можете найти этот ярлык"'.

TestFXBase:

import javafx.scene.Node;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.testfx.api.FxToolkit;
import org.testfx.framework.junit.ApplicationTest;

import java.util.concurrent.TimeoutException;


public class TestFXBase extends ApplicationTest {

    private static boolean isHeadless = false;

    @BeforeClass
    public static void setupHeadlessMode() {
       if(isHeadless){
            System.setProperty("testfx.robot", "glass");
            System.setProperty("testfx.headless", "true");
            System.setProperty("prism.order", "sw");
            System.setProperty("prism.text", "t2k");
            System.setProperty("java.awt.headless", "true");
        }


    }

    @Before
    public void setUpClass() throws Exception {
        ApplicationTest.launch(Main.class);
    }

    @Override
    public void start(Stage stage) throws Exception {
        stage.show();
    }

    @After
    public void afterEachTest() throws TimeoutException {

        FxToolkit.hideStage();
        release(new KeyCode[]{});
        release(new MouseButton[]{});
    }

    /* Helper method to retrieve Java FX GUI Components */
    public <T extends Node> T find (final  String query){
        return (T) lookup(query).queryAll().iterator().next();
    }

}

Это мой базовый класс testfx, а мой бегун и огурец расширяет его.

StepDefs:

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import org.junit.Test;


public class MyStepdefs extends TestFXBase  {
    @Test
    @Given("^That \"([^\"]*)\" Exists$")
    public void thatExists(String arg0) throws Throwable {
        rightClickOn("#rect");
    }
    @Test
    @Then("^Which is \"([^\"]*)\"$")
    public void whichIs(String arg0) throws Throwable {
        System.out.println(arg0);
    }
}

Бегунок:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;


@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty" })
public class MyRunner extends TestFXBase{}

Функция:

Функция: Существуют ли тексты меток?

Сценарий: Можете ли вы найти этот текст метки

Учитывая, что «Можете ли вы найти этот ярлык» Существует

Тогда что «здорово»

Итак, параметрПрошло, но TestFX не запускает приложение в моем бегунке с огурцами, просто пытается найти узлы.Есть класс, который расширяет TestFXBase и работает отлично.Как я могу решить эту проблему?

Редактировать: Мои зависимости

  <dependency>
            <groupId>org.loadui</groupId>
            <artifactId>testFx</artifactId>
            <version>3.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.jfxtras</groupId>
            <artifactId>openjfx-monocle</artifactId>
            <version>1.8.0_20</version>
        </dependency>

        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <version>4.0.6-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit</artifactId>
            <version>4.0.6-alpha</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>

1 Ответ

0 голосов
/ 21 ноября 2018

Решением здесь является перемещение содержимого методов setupHeadlessMode и setUpClass в инициализатор класса TestFXBase:

static {
    if (isHeadless) {
        System.setProperty("testfx.robot", "glass");
        System.setProperty("testfx.headless", "true");
        System.setProperty("prism.order", "sw");
        System.setProperty("prism.text", "t2k");
        System.setProperty("java.awt.headless", "true");
    }

    try {
        ApplicationTest.launch(Main.class);
    } catch (Exception e) {
        // oh no
    }
}
...