简体   繁体   中英

cucumber-scala and Play Framework integration testing

I've managed to get cucumber-scala up and running on a Play/Scala. Now I want to run the entire play application so that I can use something like Selenium to test my application.

My Current attempts have lead me to

 val app = new FakeApplication()
 val port = 3333

  lazy val browser: TestBrowser = TestBrowser.of(webDriverClass, Some("http://localhost:" + port))
  lazy val server = TestServer(port, app)

Of course this FakeApplication() is not configured in any way... Am I approaching this incorrectly? This application is also multi-module and Ideally I would like to have the feature tests run per module (see output from tree below)

├── README.md
├── build.sbt
├── conf
│   ├── application.conf
│   └── routes
├── logs
│   └── application.log
├── modules
│   ├── module1
│   │   ├── app
│   │   ├── conf
│   │   ├── target
│   │   └── test
│   └── module2
│       ├── app
│       ├── conf
│       └── target
└── project
    ├── build.properties
    ├── plugins.sbt
    ├── project
    │   └── target
    └── target
        ├── config-classes
        ├── resolution-cache
        ├── scala-2.10
        └── streams

I am aware that Play has a selenium integration which can be used to drive my tests. However I have a business requirement for feature files, as they are used as a reporting mechanism. I am not absolutely tied to Cucumber so if anyone is aware of a way of driving browser based tests using Feature files that would also be acceptable to me?

Thanks,

Ben

Update:

I was running through IntelliJ, which causes a server to run with no routes or anything provided. I assume this is because it runs with a default blank application.

However When running through sbt test I get the following output:

Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, Configuration error: Configuration error[Router not found: admin.Routes]
  while locating play.api.inject.guice.FakeRouterProvider
  while locating play.api.routing.Router
    for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
  while locating play.api.http.JavaCompatibleHttpRequestHandler
  while locating play.api.http.HttpRequestHandler
    for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
  at play.api.DefaultApplication.class(Application.scala:221)
  while locating play.api.DefaultApplication
  while locating play.api.Application

If you're using the default configuration settings for IntegrationTest in sbt, and ScalaTestPlusPlay , here are the directories to use:

src/it/scala     – scala IT code
src/it/java      – java IT code
src/it/resources – resources, including configuration

Place your application.conf and routes files in the resources directory and FakeApplication will pick it up. You can also set the paths in your sbt script to some other place.

If all of your development/integration testing machines are Unix-like and you use git for VC, you can use a relative symlink 1 to your real routes file.

For Windows or other VCS's, you'll likely have to copy the routes file and do double maintenance.

1 symlink using a relative path to the original, eg, ../../../conf/routes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM