0

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?

jcreason
  • 857
  • 5
  • 15
  • Can you include all the code in the question? The difference between where the following lines are called/defined is not clear: FakeApplication app = Helpers.fakeApplication(fakeApplicationConf); and FakeApplication app = FakeApplicationTest.createFakeApp(); – user1886323 Jul 31 '15 at 21:21
  • I've updated the code samples to reflect how I'm trying to use it. My other Unit Tests extend FakeApplicationTest which auto starts the FakeApplication in it's @Before method. Let me know you have any other questions, and thanks for the help. – jcreason Jul 31 '15 at 21:41

0 Answers0