org.scalatestplus.play

MixedFixtures

trait MixedFixtures extends SuiteMixin with UnitFixture

Trait that helps you provide different fixtures to different tests: a FakeApplication, a TestServer, or one of the Selenium WebDriverss.

Trait MixedFixtures can be mixed into any fixture.Suite. For convenience it is mixed into MixedPlaySpec. In a fixture.Suite, tests can take a no-arg function. MixedFixtures provides several no-arg function classes (classes extending Function0) that can be used to provide different fixtures for different tests.

If a test needs a FakeApplication, use the App function, like this:

"provide a FakeApplication" in new App(fakeApp("ehcacheplugin" -> "disabled")) {
  app.configuration.getString("ehcacheplugin") mustBe Some("disabled")
}

If a test needs a FakeApplication and running TestServer, use the Server function, like this:

"send 404 on a bad request" in new Server {
  import java.net._
  val url = new URL("http://localhost:" + port + "/boom")
  val con = url.openConnection().asInstanceOf[HttpURLConnection]
  try con.getResponseCode mustBe 404
  finally con.disconnect()
}

If a test needs a FakeApplication, running TestServer, and Selenium driver, use one of functions Chrome, Firefox, HtmlUnit, InternetExplorer, or Safari. If the chosen Selenium driver is unavailable on the host platform, the test will be automatically canceled. Here's an example that uses the Safari function:

"provide a web driver" in new Safari(fakeApp()) {
  go to ("http://localhost:" + port + "/testing")
  pageTitle mustBe "Test Page"
  click on find(name("b")).value
  eventually { pageTitle mustBe "scalatest" }
}

Here's a complete example:

package org.scalatestplus.play.examples.mixedfixtures

import play.api.test._ import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application}
class ExampleSpec extends MixedPlaySpec {
// Some helper methods def fakeApp[A](elems: (String, String)*) = FakeApplication(additionalConfiguration = Map(elems:_*), withRoutes = TestRoute) def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key)
// If a test just needs a FakeApplication, use "new App": "The App function" must { "provide a FakeApplication" in new App(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new App(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new App(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } }
// If a test needs a FakeApplication and running TestServer, use "new Server": "The Server function" must { "provide a FakeApplication" in new Server(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new Server(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new Server(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Server { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } }
// If a test needs a FakeApplication, running TestServer, and Selenium // HtmlUnit driver use "new HtmlUnit": "The HtmlUnit function" must { "provide a FakeApplication" in new HtmlUnit(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new HtmlUnit(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new HtmlUnit(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new HtmlUnit { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new HtmlUnit(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } }
// If a test needs a FakeApplication, running TestServer, and Selenium // Firefox driver use "new Firefox": "The Firefox function" must { "provide a FakeApplication" in new Firefox(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new Firefox(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new Firefox(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Firefox { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Firefox(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } }
// If a test needs a FakeApplication, running TestServer, and Selenium // Safari driver use "new Safari": "The Safari function" must { "provide a FakeApplication" in new Safari(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new Safari(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new Safari(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Safari { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Safari(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } }
// If a test needs a FakeApplication, running TestServer, and Selenium // Chrome driver use "new Chrome": "The Chrome function" must { "provide a FakeApplication" in new Chrome(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new Chrome(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new Chrome(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Chrome { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Chrome(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } }
// If a test needs a FakeApplication, running TestServer, and Selenium // InternetExplorer driver use "new InternetExplorer": "The InternetExplorer function" must { "provide a FakeApplication" in new InternetExplorer(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in new InternetExplorer(fakeApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in new InternetExplorer(fakeApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new InternetExplorer { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new InternetExplorer(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } }
// If a test does not need any special fixtures, just // write "in { () => ..." "Any old thing" must { "be doable without much boilerplate" in { () => 1 + 1 mustEqual 2 } } }

Self Type
MixedFixtures with Suite
Linear Supertypes
UnitFixture, SuiteMixin, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. MixedFixtures
  2. UnitFixture
  3. SuiteMixin
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. abstract class App extends NoArg

    NoArg subclass that provides a FakeApplication fixture.

  2. abstract class Chrome extends WebBrowser with NoArg with ChromeFactory

    NoArg subclass that provides a fixture composed of a FakeApplication, running TestServer, and Selenium ChromeDriver.

  3. abstract class Firefox extends WebBrowser with NoArg with FirefoxFactory

    NoArg subclass that provides a fixture composed of a FakeApplication, running TestServer, and Selenium FirefoxDriver.

  4. type FixtureParam = Unit

    Definition Classes
    UnitFixture
  5. abstract class HtmlUnit extends WebBrowser with NoArg with HtmlUnitFactory

    NoArg subclass that provides a fixture composed of a FakeApplication, running TestServer, and Selenium HtmlUnitDriver.

  6. abstract class InternetExplorer extends WebBrowser with NoArg with InternetExplorerFactory

    NoArg subclass that provides a fixture composed of a FakeApplication, running TestServer, and Selenium InternetExplorerDriver.

  7. abstract class Safari extends WebBrowser with NoArg with SafariFactory

    NoArg subclass that provides a fixture composed of a FakeApplication, running TestServer, and Selenium SafariDriver.

  8. abstract class Server extends NoArg

    NoArg subclass that provides a fixture composed of a FakeApplication and running TestServer.

Abstract Value Members

  1. abstract def expectedTestCount(filter: Filter): Int

    Definition Classes
    SuiteMixin
  2. abstract def nestedSuites: IndexedSeq[Suite]

    Definition Classes
    SuiteMixin
  3. abstract def rerunner: Option[String]

    Definition Classes
    SuiteMixin
  4. abstract def run(testName: Option[String], args: Args): Status

    Definition Classes
    SuiteMixin
  5. abstract def runNestedSuites(args: Args): Status

    Attributes
    protected
    Definition Classes
    SuiteMixin
  6. abstract def runTest(testName: String, args: Args): Status

    Attributes
    protected
    Definition Classes
    SuiteMixin
  7. abstract def runTests(testName: Option[String], args: Args): Status

    Attributes
    protected
    Definition Classes
    SuiteMixin
  8. abstract val styleName: String

    Definition Classes
    SuiteMixin
  9. abstract def suiteId: String

    Definition Classes
    SuiteMixin
  10. abstract def suiteName: String

    Definition Classes
    SuiteMixin
  11. abstract def tags: Map[String, Set[String]]

    Definition Classes
    SuiteMixin
  12. abstract def testDataFor(testName: String, theConfigMap: ConfigMap): TestData

    Definition Classes
    SuiteMixin
  13. abstract def testNames: Set[String]

    Definition Classes
    SuiteMixin
  14. abstract def withFixture(test: (MixedFixtures.this)#NoArgTest): Outcome

    Attributes
    protected
    Definition Classes
    SuiteMixin

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. def withFixture(test: (MixedFixtures.this)#OneArgTest): Outcome

    Definition Classes
    UnitFixture

Inherited from UnitFixture

Inherited from SuiteMixin

Inherited from AnyRef

Inherited from Any

Ungrouped