Trait that uses a shared test approach to enable
you to run the same tests on multiple browsers in a ScalaTest Suite
, where each kind of browser is started and stopped
just once for the whole Suite
.
Trait that uses a shared test approach to enable
you to run the same tests on multiple browsers in a ScalaTest Suite
, where a new browser is started before each test
that needs a browser, and stopped after.
Trait that uses a shared test approach to enable
you to run the same tests on multiple browsers in a ScalaTest Suite
, where a new browser is started before each test
that needs a browser, and stopped after.
Note: the difference between this trait and AllBrowsersPerSuite is that
AllBrowsersPerSuite
will allow you to write tests that rely on maintaining browser state between the tests. Thus, AllBrowsersPerSuite
is a good fit
for integration tests in which each test builds on actions taken by the previous tests. This trait is good if your tests
each need a brand new browser.
This trait overrides Suite
's withFixture
lifecycle method to create a new WebDriver
instance before executing each test that needs a browser, closing it after the test completes, and overrides the tags
lifecycle method to tag the shared tests so you can
filter them by browser type. This trait's self-type, ServerProvider, will ensure
a TestServer
and Application
are available to each test. The self-type will require that you mix in either
GuiceOneServerPerSuite, OneServerPerTest,
ConfiguredServer before you mix in this trait. Your choice among these three
ServerProvider
s will determine the extent to which a TestServer
is shared by multiple tests.
You'll need to place any tests that you want executed by multiple browsers in a sharedTests
method. Because all tests in a ScalaTest Suite
must have unique names, you'll need to append the browser name (available from the BrowserInfo
passed
to sharedTests
) to each test name:
def sharedTests(browser: BrowserInfo) { "The blog app home page" must { "have the correct title " + browser.name in { go to (host + "index.html") pageTitle must be ("Awesome Blog") }
All tests registered via sharedTests
will be registered for each desired WebDriver
, as specified by the browsers
field. When
running, any tests for browser drivers that are unavailable
on the current platform will be canceled.
All tests registered under sharedTests
will be
tagged automatically if they end with a browser name in square brackets. For example, if a test name ends
with [Firefox]
, it will be automatically tagged with "org.scalatest.tags.FirefoxBrowser"
. This will
allow you can include or exclude the shared tests by browser type using ScalaTest's regular tagging feature.
You can use tagging to include or exclude browsers that you sometimes want to test with, but not always. If you
never want to test with a particular browser, you can prevent tests for it from being registered at all
by overriding browsers
and excluding its BrowserInfo
in the returned Seq
. For example, to disable registration of
tests for HtmlUnit
, you'd write:
override lazy val browsers: IndexedSeq[BrowserInfo] = Vector( FirefoxInfo, SafariInfo, InternetExplorerInfo, ChromeInfo )
Note that this trait can only be mixed into traits that register tests as functions, as the shared tests technique
is not possible in style traits that declare tests as methods, such as org.scalatest.Spec
. Attempting to do so
will become a type error once we release ScalaTest 2.2.0.
package org.scalatestplus.play.examples.allbrowserspertest import play.api.test._ import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ import play.api.cache.EhCacheModule class ExampleSpec extends PlaySpec with OneServerPerTest with AllBrowsersPerTest { // Override newAppForTest if you need a Application with other than non-default parameters. override def newAppForTest(testData: TestData): Application = new GuiceApplicationBuilder() .disable[EhCacheModule] .configure("foo" -> "bar") .router(Router.from(TestRoute)) .build() // Place tests you want run in different browsers in the `sharedTests` method: def sharedTests(browser: BrowserInfo) = { "The AllBrowsersPerTest trait" must { "provide a web driver " + browser.name in { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } } // Place tests you want run just once outside the `sharedTests` method // in the constructor, the usual place for tests in a `PlaySpec` "The AllBrowsersPerTest trait" must { "provide a FakeApplication" in { app.configuration.getString("foo") mustBe Some("bar") } "make the FakeApplication available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("foo") mustBe Some("bar") } "start the FakeApplication" in { Play.maybeApplication mustBe Some(app) } "provide the port" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
Here's how the output would look if you ran the above test class in sbt on a platform that did not support Selenium drivers for Internet Explorer or Chrome:
> test-only *allbrowserspersharedtest* [info] ExampleSpec: [info] The AllBrowsersPerTest trait [info] - must provide a web driver [Firefox] [info] The AllBrowsersPerTest trait [info] - must provide a web driver [Safari] [info] The AllBrowsersPerTest trait [info] - must provide a web driver [InternetExplorer] !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (AllBrowsersPerTest.scala:257) [info] The AllBrowsersPerTest trait [info] - must provide a web driver [Chrome] !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (AllBrowsersPerTest.scala:257) [info] The AllBrowsersPerTest trait [info] - must provide a web driver [HtmlUnit] [info] The AllBrowsersPerTest trait [info] - must provide a Application [info] - must make the Application available implicitly [info] - must start the Application [info] - must provide the port [info] - must provide an actual running server
Because the shared tests will be tagged according to browser, you can include or exclude tests based on the browser they use. For example, here's how the output would look if you ran the above test class with sbt and ask to include only Firefox:
> test-only *allbrowserspersharedtest* -- -n org.scalatest.tags.FirefoxBrowser [info] ExampleSpec: [info] The AllBrowsersPerTest trait [info] - must provide a web driver [Firefox] [info] The AllBrowsersPerTest trait [info] The AllBrowsersPerTest trait [info] The AllBrowsersPerTest trait [info] The AllBrowsersPerTest trait [info] The AllBrowsersPerTest trait
Trait that defines an application as app
.
The base abstract trait for one app per suite.
Trait that provides a new Application
instance for each test.
Trait that provides a new Application
instance for each test.
This TestSuiteMixin
trait's overridden withFixture
method creates a new Application
before each test and ensures it is cleaned up after the test has completed. You can
access the Application
from your tests as method app
(which is marked implicit).
By default, this trait creates a new Application
for each test using default parameter values, which
is returned by the newAppForTest
method defined in this trait. If your tests need a Application
with non-default
parameters, override newAppForTest
to return it.
Here's an example that demonstrates some of the services provided by this trait:
package org.scalatestplus.play.examples.oneapppertest import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ class ExampleSpec extends PlaySpec with OneAppPerTest { // Override newAppForTest if you need an Application with other than non-default parameters. implicit override def newAppForTest(testData: TestData): Application = new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build() "The OneAppPerTest trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } } }
Trait that provides a new Application
and running TestServer
instance per ScalaTest Suite
.
Trait that provides a new Application
and running TestServer
instance per ScalaTest Suite
.
By default, this trait creates a new Application
for the Suite
using default parameter values, which
is made available via the app
field defined in this trait and a new TestServer
for the Suite
using the port number provided by
its port
field and the Application
provided by its app
field. If your Suite
needs a
Application
with non-default parameters, override app
. If it needs a different port number,
override port
.
This TestSuiteMixin
trait's overridden run
method calls start
on the TestServer
before executing the Suite
via a call to super.run
.
In addition, it places a reference to the Application
provided by app
into the ConfigMap
under the key org.scalatestplus.play.app
and to the port number provided by port
under the key
org.scalatestplus.play.port
. This allows any nested Suite
s to access the Suite
's
Application
and port number as well, most easily by having the nested Suite
s mix in the
ConfiguredServer trait. On the status returned by super.run
, this
trait's overridden run
method registers a call to stop
on the TestServer
to be executed when the Status
completes, and returns the same Status
. This ensure the TestServer
will continue to execute until
all nested suites have completed, after which the TestServer
will be stopped.
Here's an example that demonstrates some of the services provided by this trait:
package org.scalatestplus.play.examples.oneserverpersuite import play.api.test._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ class ExampleSpec extends PlaySpec with OneServerPerSuite { // Override fakeApplication() if you need a Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder().configure("ehcacheplugin" -> "disabled").build() "The OneServerPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
If you have many tests that can share the same Application
and TestServer
, and you don't want to put them all into one
test class, you can place them into different Suite
classes.
These will be your nested suites. Create a master suite that extends OneServerPerSuite
and declares the nested
Suite
s. Annotate the nested suites with @DoNotDiscover
and have them extend ConfiguredServer
. Here's an example:
package org.scalatestplus.play.examples.oneserverpersuite import play.api.test._ import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ // This is the "master" suite class NestedExampleSpec extends Suites( new OneSpec, new TwoSpec, new RedSpec, new BlueSpec ) with GuiceOneServerPerSuite { // Override app if you need an Application with other than non-default parameters. override def fakeApplication(): Application = new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build() } // These are the nested suites @DoNotDiscover class OneSpec extends PlaySpec with ConfiguredServer @DoNotDiscover class TwoSpec extends PlaySpec with ConfiguredServer @DoNotDiscover class RedSpec extends PlaySpec with ConfiguredServer @DoNotDiscover class BlueSpec extends PlaySpec with ConfiguredServer { "The OneServerPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
Trait that provides a new Application
and running TestServer
instance for each test executed in a ScalaTest Suite
.
Trait that provides a new Application
and running TestServer
instance for each test executed in a ScalaTest Suite
.
This TestSuiteMixin
trait overrides ScalaTest's withFixture
method to create a new Application
and TestServer
before each test, and ensure they are cleaned up after the test has completed. The Application
is available (implicitly) from
method app
. The TestServer
's port number is available as port
(and implicitly available as portNumber
, wrapped
in a PortNumber).
By default, this trait creates a new Application
for each test using default parameter values, which
is returned by the newAppForTest
method defined in this trait. If your tests need an Application
with non-default
parameters, override newAppForTest
to return it.
Here's an example that demonstrates some of the services provided by this trait:
package org.scalatestplus.play.examples.oneserverpertest import play.api.test._ import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ class ExampleSpec extends PlaySpec with OneServerPerTest { // Override newAppForTest or use GuiceOneServerPerTest implicit override def newAppForTest(testData: TestData): Application = new GuiceApplicationBuilder() .configure(Map("ehcacheplugin" -> "disabled")) .router(Router.from(TestRoute)) .build() "The OneServerPerTest trait" must { "provide a FakeApplication" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
Trait that defines an abstract createWebDriver
method for creating a new Selenium WebDriver
and an abstract unableToCreateDriverErrorMessage
method that provides an appropriate error message if the driver
is not available on the current platform.
Trait that defines an abstract createWebDriver
method for creating a new Selenium WebDriver
and an abstract unableToCreateDriverErrorMessage
method that provides an appropriate error message if the driver
is not available on the current platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits.
Abstract class that encapsulates a browser name, tag name, and Selenium WebDriver
factory method.
Abstract class that encapsulates a browser name, tag name, and Selenium WebDriver
factory method.
This class is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
BrowserInfo
is not sealed so that you can extend it if you need other Browser types, for example,
Firefox browsers with different profiles (English, Japanese, etc.).
Factory whose createWebDriver
method will either return a new Selenium ChromeDriver
, or
UnavailableDriver, if Chrome is not available on the host platform.
Factory whose createWebDriver
method will either return a new Selenium ChromeDriver
, or
UnavailableDriver, if Chrome is not available on the host platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits such as
ChromeFactory
.
Trait that provides a configured Application
to the suite into which it is mixed.
Trait that provides a configured Application
to the suite into which it is mixed.
The purpose of this trait is to allow nested suites of an enclosing suite that extends GuiceOneAppPerSuite
to make use of the Application
provided by GuiceOneAppPerSuite
. Trait GuiceOneAppPerSuite
will ensure
the Application
is placed in the ConfigMap
under the key org.scalatestplus.play.app
before
nested suites are invoked. This represents the "configured application" that is passed from the enclosing
suite to the nested suites. Trait ConfiguredApp
extracts the Application
from the ConfigMap
and makes it available via the app
method it provides.
To prevent discovery of nested suites you can annotate them with @DoNotDiscover
. Here's an example,
taken from GuiceOneAppPerSuite
's documentation:
package org.scalatestplus.play.examples.oneapppersuite import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ class ExampleSpec extends PlaySpec with GuiceOneAppPerSuite { // Override app if you need an Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build() "The GuiceOneAppPerSuite trait" must { "provide a FakeApplication" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in { Play.maybeApplication mustBe Some(app) } } }
Trait that provides a configured Application
, server port number, and Selenium WebDriver
to the suite
into which it is mixed.
Trait that provides a configured Application
, server port number, and Selenium WebDriver
to the suite
into which it is mixed.
The purpose of this trait is to allow nested suites of an enclosing suite that extends OneBrowserPerSuite
to make use of the WebDriver
provided by OneBrowserPerSuite
. Trait OneBrowserPerSuite
will ensure
the WebDriver
is placed in the ConfigMap
under the key org.scalatestplus.play.webDriver
before nested suites are invoked. This
information represents the "configured browser" that is passed from the enclosing suite to the nested suites. Trait ConfiguredBrowser
extracts this information from
from the ConfigMap
and makes the WebDriver
available implicitly from the webDriver
method.
This trait's self-type, ServerProvider, will ensure
a TestServer
and Application
are available to each test. The self-type will require that you mix in either
GuiceOneServerPerSuite, OneServerPerTest,
ConfiguredServer before you mix in this trait. Your choice among these three
ServerProvider
s will determine the extent to which one or more TestServer
s are shared by multiple tests.
To prevent discovery of nested suites you can annotate them with @DoNotDiscover
. Here's an example
taken from the documentation for trait OneBrowserPerSuite:
package org.scalatestplus.play.examples.onebrowserpersuite import play.api.test.Helpers import org.scalatest.tags.FirefoxBrowser import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ @FirefoxBrowser class ExampleSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite with FirefoxFactory { // Override fakeApplication() if you need a Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder() .configure("foo" -> "bar", "ehcacheplugin" -> "disabled") .router(Router.from(TestRoute)) .build() "The OneBrowserPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } }
Trait that provides a configured Application
and server port number to the suite into which it is mixed.
Trait that provides a configured Application
and server port number to the suite into which it is mixed.
The purpose of this trait is to allow nested suites of an enclosing suite that extends GuiceOneServerPerSuite
to make use of the Application
and port number provided by OneServerPerSuite
. Trait OneServerPerSuite
will ensure
the Application
is placed in the ConfigMap
under the key org.scalatestplus.play.app
and the port number
under the key org.scalatestplus.play.port
before nested suites are invoked. This information represents the "configured server" that
is passed from the enclosing suite to the nested suites. Trait ConfiguredServer
extracts this information from
from the ConfigMap
and makes the Application
available via the app
method, the port number available as an Int
from
the port
method, and also the port number wrapped in a PortNumber available as implicit method portNumber
(for use
with trait WsScalaTestClient).
To prevent discovery of nested suites you can annotate them with @DoNotDiscover
. Here's an example,
taken from GuiceOneAppPerSuite
's documentation:
package org.scalatestplus.play.examples.oneserverpersuite import play.api.test._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ class ExampleSpec extends PlaySpec with GuiceOneServerPerSuite { // Override fakeApplication() if you need a Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder().configure("ehcacheplugin" -> "disabled").build() "The OneServerPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
Trait that provides method that creates a new instance of Application
to the functional test suite mixins.
Trait that provides method that creates a new instance of Application
to the functional test suite mixins.
The GuiceFakeApplicationFactory
provides a FakeApplicationFactory
that uses GuiceApplicationBuilder
to build an Application for test suites.
Factory whose createWebDriver
method will either return a new Selenium FirefoxDriver
(created
using the profile specified by firefoxProfile
), or
UnavailableDriver, if Firefox is not available on the host platform.
Factory whose createWebDriver
method will either return a new Selenium FirefoxDriver
(created
using the profile specified by firefoxProfile
), or
UnavailableDriver, if Firefox is not available on the host platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits such as
FirefoxFactory
.
Firefox browser info, which encapsulates the browser name, "[Firefox]"
; tag name, org.scalatest.tags.FirefoxBrowser
; and a factory method that produces a Selenium FirefoxDriver
.
Firefox browser info, which encapsulates the browser name, "[Firefox]"
; tag name, org.scalatest.tags.FirefoxBrowser
; and a factory method that produces a Selenium FirefoxDriver
.
This class's superclass, BrowserInfo
, is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
the FirefoxProfile
to use when creating new FirefoxDriver
s in the createWebDriver
factory method.
Factory whose createWebDriver
method will either return a new Selenium HtmlUnitDriver
, or
UnavailableDriver, if HtmlUnit is not available on the host platform.
Factory whose createWebDriver
method will either return a new Selenium HtmlUnitDriver
, or
UnavailableDriver, if HtmlUnit is not available on the host platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits such as
HtmlUnitFactory
.
HtmlUnit
browser info, which encapsulates the browser name, "[HtmlUnit]"
; tag name, org.scalatest.tags.HtmlUnitBrowser
; and a factory method that produces a Selenium HtmlUnitDriver
.
HtmlUnit
browser info, which encapsulates the browser name, "[HtmlUnit]"
; tag name, org.scalatest.tags.HtmlUnitBrowser
; and a factory method that produces a Selenium HtmlUnitDriver
.
This object's superclass, BrowserInfo
, is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
Factory whose createWebDriver
method will either return a new Selenium InternetExplorerDriver
, or
UnavailableDriver, if Internet Explorer is not available on the host platform.
Factory whose createWebDriver
method will either return a new Selenium InternetExplorerDriver
, or
UnavailableDriver, if Internet Explorer is not available on the host platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits such as
InternetExplorerFactory
.
Trait that helps you provide different fixtures to different tests: a Application
, a TestServer
, or one
of the Selenium WebDrivers
s.
Trait that helps you provide different fixtures to different tests: a Application
, a TestServer
, or one
of the Selenium WebDrivers
s.
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 Application
, use the App
function, like this:
"provide an Application" in new App(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") }
If a test needs an Application
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 an Application
, 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.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ class ExampleSpec extends MixedPlaySpec { // Some helper methods def buildApp[A](elems: (String, String)*) = new GuiceApplicationBuilder() .configure(Map(elems:_*)) .router(Router.from(TestRoute)) .build() def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) "The App function" must { "provide an Application" in new App(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new App(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new App(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } } "The Server function" must { "provide an Application" in new Server(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Server(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Server(buildApp("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() } } "The HtmlUnit function" must { "provide an Application" in new HtmlUnit(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new HtmlUnit(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new HtmlUnit(buildApp("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(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Firefox function" must { "provide an Application" in new Firefox(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Firefox(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Firefox(buildApp("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(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Safari function" must { "provide an Application" in new Safari(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Safari(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Safari(buildApp("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(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Chrome function" must { "provide an Application" in new Chrome(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Chrome(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Chrome(buildApp("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(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The InternetExplorer function" must { "provide an Application" in new InternetExplorer(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new InternetExplorer(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new InternetExplorer(buildApp("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(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "Any old thing" must { "be doable without much boilerplate" in { () => 1 + 1 mustEqual 2 } } }
Convenience "super Suite" class for "mixed fixture" Play tests.
Convenience "super Suite" class for "mixed fixture" Play tests.
This class mixes in trait MixedFixtures, and is therefore convenient when different tests in the same test class need different kinds of fixtures. When different tests in the same class need the same fixture, you're probably better of extending PlaySpec instead.
Synonym for GuiceOneAppPerSuite.
Synonym for GuiceOneAppPerSuite.
Synonym for GuiceOneAppPerTest
Synonym for GuiceOneAppPerTest
Trait that provides a new Selenium WebDriver
instance per ScalaTest Suite
.
Trait that provides a new Selenium WebDriver
instance per ScalaTest Suite
.
This TestSuiteMixin
trait's overridden run
method
places a reference to the WebDriver
provided by webDriver
under the key org.scalatestplus.play.webDriver
.
This allows any nested Suite
s to access the Suite
's
WebDriver
as well, most easily by having the nested Suite
s mix in the
ConfiguredBrowser trait. On the status returned by super.run
, this
trait's overridden run
method registers a block of code to close the WebDriver
to be executed when the Status
completes, and returns the same Status
. This ensures the WebDriver
will continue to be available until
all nested suites have completed, after which the WebDriver
will be closed.
This trait also overrides Suite.withFixture
to cancel tests automatically if the related
WebDriver
is not available on the host platform.
This trait's self-type, ServerProvider, will ensure
a TestServer
and Application
are available to each test. The self-type will require that you mix in either
GuiceOneServerPerSuite, OneServerPerTest,
ConfiguredServer before you mix in this trait. Your choice among these three
ServerProvider
s will determine the extent to which one or more TestServer
s are shared by multiple tests.
Here's an example that shows demonstrates of the services provided by this trait. Note that to use this trait, you must mix in one of the driver factories (this example mixes in FirefoxFactory):
package org.scalatestplus.play.examples.onebrowserpersuite import play.api.test.Helpers import org.scalatest.tags.FirefoxBrowser import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ @FirefoxBrowser class ExampleSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite with FirefoxFactory { // Override fakeApplication() if you need a Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder() .configure("foo" -> "bar", "ehcacheplugin" -> "disabled") .router(Router.from(TestRoute)) .build() "The OneBrowserPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } }
If you have many tests that can share the same Application
, TestServer
, and WebDriver
, and you don't want to put them all into one
test class, you can place them into different "nested" Suite
classes.
Create a master suite that extends OneServerPerSuite
and declares the nested
Suite
s. Annotate the nested suites with @DoNotDiscover
and have them extend ConfiguredBrowser
. Here's an example:
package org.scalatestplus.play.examples.onebrowserpersuite import play.api.test._ import org.scalatest._ import tags.FirefoxBrowser import org.scalatestplus.play._ import play.api.{Play, Application} // This is the "master" suite class NestedExampleSpec extends Suites( new OneSpec, new TwoSpec, new RedSpec, new BlueSpec ) with OneServerPerSuite with OneBrowserPerSuite with FirefoxFactory { // Override fakeApplication() if you need a Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder( additionalConfiguration = Map("ehcacheplugin" -> "disabled"), withRoutes = TestRoute ).build() } // These are the nested suites @DoNotDiscover class OneSpec extends PlaySpec with ConfiguredServer with ConfiguredBrowser @DoNotDiscover class TwoSpec extends PlaySpec with ConfiguredServer with ConfiguredBrowser @DoNotDiscover class RedSpec extends PlaySpec with ConfiguredServer with ConfiguredBrowser @DoNotDiscover class BlueSpec extends PlaySpec with ConfiguredServer with ConfiguredBrowser { "The OneBrowserPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }
It is possible to use OneBrowserPerSuite
to run the same tests in more than one browser. Nevertheless,
you should consider the approach taken by AllBrowsersPerSuite
and AllBrowsersPerTest
instead, as it requires a bit less boilerplate code than OneBrowserPerSuite
to test in multiple browsers.
If you prefer to use OneBrowserPerSuite
, however, simply place your tests in an abstract superclass, then define concrete subclasses
for each browser you wish to test against. Here's an example:
package org.scalatestplus.play.examples.onebrowserpersuite import play.api.test._ import org.scalatest._ import tags._ import org.scalatestplus.play._ import play.api.{Play, Application} // Place your tests in an abstract class abstract class MultiBrowserExampleSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite { // Override app if you need an Application with other than non-default parameters. def fakeApplication(): Application = new GuiceApplicationBuilder( additionalConfiguration = Map("ehcacheplugin" -> "disabled"), withRoutes = TestRoute ).build "The OneBrowserPerSuite trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } } // Then make a subclass that mixes in the factory for each // Selenium driver you want to test with. @FirefoxBrowser class FirefoxExampleSpec extends MultiBrowserExampleSpec with FirefoxFactory @SafariBrowser class SafariExampleSpec extends MultiBrowserExampleSpec with SafariFactory @InternetExplorerBrowser class InternetExplorerExampleSpec extends MultiBrowserExampleSpec with InternetExplorerFactory @ChromeBrowser class ChromeExampleSpec extends MultiBrowserExampleSpec with ChromeFactory @HtmlUnitBrowser class HtmlUnitExampleSpec extends MultiBrowserExampleSpec with HtmlUnitFactory
The concrete subclasses include tag annotations describing the browser used to make it easier to include or exclude browsers in specific runs. This is not strictly necessary since if a browser is not supported on the host platform the tests will be automatically canceled. For example, here's how the output would look if you ran the above tests on a platform that did not support Selenium drivers for Chrome or Internet Explorer using sbt:
> test-only *onebrowserpersuite* [info] FirefoxExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application [info] - must make the Application available implicitly [info] - must start the Application [info] - must provide the port number [info] - must provide an actual running server [info] - must provide a web driver [info] SafariExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application [info] - must make the Application available implicitly [info] - must start the Application [info] - must provide the port number [info] - must provide an actual running server [info] - must provide a web driver [info] InternetExplorerExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must make the Application available implicitly !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must start the Application !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide the port number !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide an actual running server !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide a web driver !!! CANCELED !!! [info] Was unable to create a Selenium InternetExplorerDriver on this platform. (OneBrowserPerSuite.scala:201) [info] ChromeExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must make the Application available implicitly !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must start the Application !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide the port number !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide an actual running server !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] - must provide a web driver !!! CANCELED !!! [info] Was unable to create a Selenium ChromeDriver on this platform. (OneBrowserPerSuite.scala:201) [info] HtmlUnitExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application [info] - must make the Application available implicitly [info] - must start the Application [info] - must provide the port number [info] - must provide an actual running server [info] - must provide a web driver
For comparison, here is what the output would look like if you just selected tests tagged with FirefoxBrowser
in sbt:
> test-only *onebrowserpersuite* -- -n org.scalatest.tags.FirefoxBrowser [info] FirefoxExampleSpec: [info] The OneBrowserPerSuite trait [info] - must provide an Application [info] - must make the Application available implicitly [info] - must start the Application [info] - must provide the port number [info] - must provide an actual running server [info] - must provide a web driver [info] SafariExampleSpec: [info] The OneBrowserPerSuite trait [info] InternetExplorerExampleSpec: [info] The OneBrowserPerSuite trait [info] ChromeExampleSpec: [info] The OneBrowserPerSuite trait [info] HtmlUnitExampleSpec: [info] The OneBrowserPerSuite trait
Trait that provides a new Selenium WebDriver
instance for each test executed in a ScalaTest Suite
.
Trait that provides a new Selenium WebDriver
instance for each test executed in a ScalaTest Suite
.
This trait overrides ScalaTest's withFixture
method to create a new WebDriver
instance
before each test, and ensure it is closed after the test has completed.
The WebDriver
is available (implicitly) from method webDriver
.
This trait's self-type, ServerProvider, will ensure
a TestServer
and Application
are available to each test. The self-type will require that you mix in either
GuiceOneServerPerSuite, OneServerPerTest,
ConfiguredServer before you mix in this trait. Your choice among these three
ServerProvider
s will determine the extent to which one or more TestServer
s are shared by multiple tests.
Here's an example that shows demonstrates of the services provided by this trait. Note that to use this trait, you must mix in one of the driver factories (this example mixes in FirefoxFactory):
package org.scalatestplus.play.examples.onebrowserpertest import play.api.test._ import org.scalatest._ import org.scalatest.tags.FirefoxBrowser import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ @FirefoxBrowser class ExampleSpec extends PlaySpec with OneServerPerTest with OneBrowserPerTest with FirefoxFactory { // Override newAppForTest if you need an Application with other than non-default parameters. override def newAppForTest(testData: TestData): Application = new GuiceApplicationBuilder() .configure(Map("ehcacheplugin" -> "disabled")) .router(Router.from(TestRoute)) .build() "The OneBrowserPerTest trait" must { "provide an Application" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } }
Synonym for GuiceOneServerPerSuite.
Synonym for GuiceOneServerPerSuite.
Synonym for GuiceOneServerPerTest
Synonym for GuiceOneServerPerTest
Convenience "super Suite" base class for Play tests.
Convenience "super Suite" base class for Play tests.
Extend this class by default for testing Play apps with the ScalaTest + Play library. You can mix other traits into it to access needed fixtures, such as GuiceOneAppPerSuite, GuiceOneAppPerTest, GuiceOneServerPerSuite, GuiceOneServerPerTest, OneBrowserPerSuite, OneBrowserPerTest, AllBrowsersPerSuite, or AllBrowsersPerTest mix If you want to use trait MixedFixtures, extend MixedPlaySpec instead.
Wraps a port number of a provided TestServer
so that it can be made available as an implicit without making an Int
implicit.
Wraps a port number of a provided TestServer
so that it can be made available as an implicit without making an Int
implicit.
An implicit PortNumber
is made available by traits that provide a play.api.test.TestServer
: MixedFixtures,
OneBrowserPerSuite,
OneBrowserPerTest, GuiceOneServerPerSuite,
and OneServerPerTest.
The implicit PortNumber
is taken by the methods of WsScalaTestClient.
Factory whose createWebDriver
method will either return a new Selenium SafariDriver
, or
UnavailableDriver, if Safari is not available on the host platform.
Factory whose createWebDriver
method will either return a new Selenium SafariDriver
, or
UnavailableDriver, if Safari is not available on the host platform.
Traits OneBrowserPerSuite and
OneBrowserPerTest extend BrowserFactory
and therefore require
you to fill in the createWebDriver
method, usually by mixing in one of the BrowserFactory
subtraits such as
SafariFactory
.
Trait that defines abstract methods that providing a port number and implicit Application
and a concrete
method that provides an implicit PortNumber that wraps the port number.
Trait that defines abstract methods that providing a port number and implicit Application
and a concrete
method that provides an implicit PortNumber that wraps the port number.
This trait is implemented by OneServerPerSuite,
OneServerPerTest, and
ConfiguredServer, each of which use a different strategy to
provide TestServer
s to tests. This trait is included in the self-type of
OneBrowserPerSuite, and
OneBrowserPerTest, and
AllBrowsersPerTest, allowing you to select
the WebDriver
strategy (i.e., the extent to which WebDriver
s are shared between tests) independently from the
TestServer
strategy (the extent to which TestServer
s are shared between tests).
Trait providing convenience methods to create WS requests in tests.
Companion object to trait BrowserFactory
that holds a UnavailableDriver
object that implements
the Selenium WebDriver
interface by throwing UnsupportedOperationException
.
Companion object to trait BrowserFactory
that holds a UnavailableDriver
object that implements
the Selenium WebDriver
interface by throwing UnsupportedOperationException
. This is
used as a placeholder when a driver is not available on the host platform.
Companion object to trait ChromeFactory
that mixes in the trait.
Chrome browser info, which encapsulates the browser name, "[Chrome]"
; tag name, org.scalatest.tags.ChromeBrowser
; and a factory method that produces a Selenium ChromeDriver
.
Chrome browser info, which encapsulates the browser name, "[Chrome]"
; tag name, org.scalatest.tags.ChromeBrowser
; and a factory method that produces a Selenium ChromeDriver
.
This object's superclass, BrowserInfo
, is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
Companion object to trait FirefoxFactory
that mixes in the trait.
Companion object to trait HtmlUnitFactory
that mixes in the trait.
Companion object to trait InternetExplorerFactory
that mixes in the trait.
Internet Explorer browser info, which encapsulates the browser name, "[InternetExplorer]"
; tag name, org.scalatest.tags.InternetExplorerBrowser
; and a factory method that produces a Selenium InternetExplorerDriver
.
Internet Explorer browser info, which encapsulates the browser name, "[InternetExplorer]"
; tag name, org.scalatest.tags.InternetExplorerBrowser
; and a factory method that produces a Selenium InternetExplorerDriver
.
This object's superclass, BrowserInfo
, is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
Companion object to trait SafariFactory
that mixes in the trait.
Safari browser info, which encapsulates the browser name, "[Safari]"
; tag name, org.scalatest.tags.SafariBrowser
; and a factory method that produces a Selenium SafariDriver
.
Safari browser info, which encapsulates the browser name, "[Safari]"
; tag name, org.scalatest.tags.SafariBrowser
; and a factory method that produces a Selenium SafariDriver
.
This object's superclass, BrowserInfo
, is used by AllBrowsersPerSuite and
AllBrowsersPerTest: an IndexedSeq[BrowserInfo]
is returned
from the browsers
field of these traits to specify the browsers to share between tests.
When tests are registered, AllBrowsersPerSuite
and AllBrowsersPerTest
use the browser name to ensure the tests shared by multiple browsers
have unique names (the name of each shared test is appended with a browser name). When the tests run, these traits
use the BrowserInfo
's factory method to create WebDriver
s as needed.
The AllBrowsersPerSuite
and AllBrowsersPerTest
traits use the tag name to automatically tag any tests that use
a particular WebDriver
with the appropriate tag so that tests can be dynamically filtered by the browser the use.
Trait that uses a shared test approach to enable you to run the same tests on multiple browsers in a ScalaTest
Suite
, where each kind of browser is started and stopped just once for the wholeSuite
.Note: the difference between this trait and AllBrowsersPerTest is that this trait will allow you to write tests that rely on maintaining browser state between the tests. This is a good fit for integration tests in which each test builds on actions taken by the previous tests.
This trait overrides
Suite
'swithFixture
lifecycle method to create a newWebDriver
instance the first time it is needed by each test, and close it the first time it is not needed (thus allowing multiple tests to share the same browser), and overrides thetags
lifecycle method to tag the shared tests so you can filter them by browser type. This trait's self-type, ServerProvider, will ensure aTestServer
andApplication
are available to each test. The self-type will require that you mix in either GuiceOneServerPerSuite, GuiceOneServerPerTest, ConfiguredServer before you mix in this trait. Your choice among these threeServerProvider
s will determine the extent to which aTestServer
is shared by multiple tests.You'll need to place any tests that you want executed by multiple browsers in a
sharedTests
method. Because all tests in a ScalaTestSuite
must have unique names, you'll need to append the browser name (available from theBrowserInfo
passed tosharedTests
) to each test name:All tests registered via
sharedTests
will be registered for each desiredWebDriver
, as specified by thebrowsers
field. When running, any tests for browser drivers that are unavailable on the current platform will be canceled. All tests registered undersharedTests
will be tagged automatically if they end with a browser name in square brackets. For example, if a test name ends with[Firefox]
, it will be automatically tagged with"org.scalatest.tags.FirefoxBrowser"
. This will allow you can include or exclude the shared tests by browser type using ScalaTest's regular tagging feature.You can use tagging to include or exclude browsers that you sometimes want to test with, but not always. If you never want to test with a particular browser, you can prevent tests for it from being registered at all by overriding
browsers
and excluding itsBrowserInfo
in the returnedSeq
. For example, to disable registration of tests forHtmlUnit
, you'd write:Note that this trait can only be mixed into traits that register tests as functions, as the shared tests technique is not possible in style traits that declare tests as methods, such as
org.scalatest.Spec
. Attempting to do so will become a type error once we release ScalaTest 2.2.0.Here's how the output would look if you ran the above test class in sbt on a platform that did not support Selenium drivers for Internet Explorer or Chrome:
Because the shared tests will be tagged according to browser, you can include or exclude tests based on the browser they use. For example, here's how the output would look if you ran the above test class with sbt and ask to include only Firefox: