Last active
November 8, 2016 02:15
-
-
Save sebnozzi/8288876 to your computer and use it in GitHub Desktop.
How to integrate ScalaTest (FlatSpec) with Play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Stupid name (
ZExampleSpec
) - I just want it to be belowPlayBrowserSpec