Skip to content

Instantly share code, notes, and snippets.

@sebnozzi
Last active November 8, 2016 02:15
Show Gist options
  • Save sebnozzi/8288876 to your computer and use it in GitHub Desktop.
Save sebnozzi/8288876 to your computer and use it in GitHub Desktop.
How to integrate ScalaTest (FlatSpec) with Play
import org.scalatest.BeforeAndAfterAll
import org.openqa.selenium.WebDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.FlatSpec
import play.api.test.TestServer
import org.scalatest.Matchers
import play.api.test.Helpers
import org.scalatest.selenium.WebBrowser
import play.api.test.FakeApplication
trait PlayBrowserSpec extends FlatSpec with BeforeAndAfterAll with Matchers with WebBrowser{
implicit val webDriver: WebDriver = new HtmlUnitDriver
val host = s"http://localhost:${Helpers.testServerPort}"
var app: FakeApplication = _
var server: TestServer = _
override def beforeAll() {
app = FakeApplication()
server = TestServer(port = Helpers.testServerPort)
server.start
}
override def afterAll() {
server.stop
quit
}
}
class ZExampleSpec extends PlayBrowserSpec {
"The home page" should "have the correct title" in {
go to (host + "/")
pageTitle should be("Welcome to Play")
}
it should "say 'ready' somewhere" in {
go to (host + "/")
pageSource should include("ready")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment