assets are not loaded in functional test mode

余生颓废 提交于 2019-11-29 07:02:17
Jeep87c

Finally, here's the solution to this problem.

I added this line to my build.sbt file :

For SBT 0.x:

unmanagedResourceDirectories in Test <+=  baseDirectory ( _ /"target/web/public/test" )

For SBT 1.x:

unmanagedResourceDirectories in Test +=  baseDirectory ( _ /"target/web/public/test" ).value

Thanks to @MarkVedder and @JarmoPertman for their great comments who put me on this solution!

I recently had a similar problem. I solved it double checking this steps according to Play 2.3 Migration guide:

1.- Check if sbt.version is set to 0.13.5 in your /project/build.properties file.

2.- Add sbt-web plugin in your project/plugins.sbt file: addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.2")

3.- Enable SbtWeb plugin in your /build.sbt file like this lazy val root = (project in file(".")).enablePlugins(PlayJava, SbtWeb)

Let me know if this solved your problem.

For others that come looking for a solution to this, we were having problems getting assets to load properly in our functional test run under Scala 2.12 and Play Framework 2.6. Following the advice on the accepted answer here, we tried adding:

unmanagedResourceDirectories in FunctionalTest += 
  baseDirectory ( _ /"target/web/public/test" ).value

And that appeared to work - at least locally. However, things were still failing on our CI side. Mentioned in another comment here was this old Play Framework issue: https://github.com/playframework/playframework/issues/3234, we tried adding the web-test:assets command prior to running our functional test suite, and that also appeared to fix it as we could see locally that the assets got moved into the target/web/public/test directory. Still having problems though getting it to consistently pass or pass at all on our CI side.

Knowing that sbt-web was involved in this process, going back over the sbt-web docs there was a little hidden item in the readme on https://github.com/sbt/sbt-web:

To automatically add the production-ready assets to classpath, the following might be useful:

(managedClasspath in Runtime) += (packageBin in Assets).value

Modifying that line slighty to work with our FunctionalTest config:

(managedClasspath in FunctionalTest) += (packageBin in Assets).value

and now it is passing ALL THE TIME both locally and on CI. No other SBT lines were needed, and we REMOVED the

unmanagedResourceDirectories in FunctionalTest +=
  baseDirectory ( _ /"target/web/public/test" ).value

line as it was no longer needed.

g00dnatur3

The problem you are having is nothing new, look here:

Static resources not found in (Selenium) JUnit test for Play 2.0 application executed from Eclipse

What i do to overcome this problem is simple (Eclipse example)

public abstract class RunInBrowserTest extends FluentTest {
    private static boolean isTestRunningInEclipse = true;
    static {
        if (System.getenv("PLAY_HOME") != null) {
            isTestRunningInEclipse = false;
        };
    }

    @BeforeClass
    public static void startApp() throws Exception {
        if (!isTestRunningInEclipse) {
            server = play.test.Helpers.testServer(port);
            server.start();
        }
    }
}

The "extends FluentTest" will allow you to have "goTo(url)" and "$(#blah).click" and the entire FluentLenium api available to you directly in your test class.

Also, make sure you have PLAY_HOME set in your environment variables, that's the trick actually.

If you want to enable running functional tests in Eclipse,

You first go to your console and type play run

Now you can just press the play button in Eclipse and your functional tests will run with no problem.

If you would like to get the javascript coverage of your functional tests check out the jscover-sbt-plugin here:

https://github.com/g00dnatur3/jscover-sbt-plugin

Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!