Create a TestServer with an already started FakeApplication

时间:2015-07-31 20:56:01

标签: java playframework playframework-2.3 fluentlenium

I've started integrating in some Selenium tests into the testing framework in Play. I have a class in which I define a lot of special config settings for a FakeApplication, then create that FakeApplication using:

public abstract class FakeApplicationTest {
    public static FakeApplication createFakeApp() {
        // grab the main application.conf file that is used to start up the Play application
        Config config = ConfigFactory.parseFile(new File("conf/application.conf"));

        // resolve all variables within this config file with other variables within itself
        config = ConfigFactory.load(config);

        // create a Configuration object out of this and then turn it into a Map to be modified
        Configuration configuration = new Configuration(config);
        Map<String, Object> fakeApplicationConf = Maps.newHashMap(configuration.asMap());

        ...
        // CUSTOM CONFIG THINGS HERE
        ...

        return Helpers.fakeApplication(fakeApplicationConf);
    }
}

What I would like to be able to do, is use this FakeApplication, start it in a @Before method (using JUnit 4), and then pass that already running FakeApplication to the TestServer which is needed to run the Selenium tests.

public class Checkout extends FluentTest {
    public WebDriver webDriver = new FirefoxDriver();
    ...
    public FakeApplication app;

    @Before
    public void beforeTest() {
        app = FakeApplicationTest.createFakeApp();
        Helpers.start(app);
        FakeApplicationTest.createCleanDb();
        ...
    }

    @Test
    public void testReviewPage()
        running(testServer(3333, app), webDriver, browser -> {
            ...
        }
    }
}

What seems to happen when I do this though, is that the existing, running FakeApplication gets ignored/tossed and a new FakeApplication is created and started which is not setup with my custom fakeApplicationConf Map... or, it's stopping the app and restarting it but goes back to only use my default application.conf.

Any ideas on why this is? or if I can somehow accomplish this in a different way?

0 个答案:

没有答案
相关问题