ScalaTest 2.0 の Selenium DSL がいいかんじ
ScalaTest 2.0-M4 に Selenium 用の DSL が入っていました。
ScalaTest Selenium DSL
go to "...." でページを開けたり、
click on "foo" でクリックできたり、
delete all cookies でクッキー消せたりと、かなり自然な DSL になっています。
build.sbt には scalatest のほか、selenium の dependency も必要でした。
// build.sbt libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "2.0.M4" % "test", "org.seleniumhq.selenium" % "selenium-java" % "2.25.0" % "test" )
DSL は org.scalatest.selenium.WebBrowser という trait を mix-in し
使いたい WebDriver を implicit 定義することで使えるようになります。
あとは
http://www.artima.com/docs-scalatest-2.0.M4/#org.scalatest.selenium.WebBrowser
を見ればわかるでしょう。
package example import org.scalatest.FlatSpec import org.scalatest.matchers.ShouldMatchers import org.scalatest.selenium._ import org.openqa.selenium.WebDriver import org.openqa.selenium.htmlunit.HtmlUnitDriver class SeleniumExampleSpec extends FlatSpec with ShouldMatchers with WebBrowser { implicit val webDriver: WebDriver = new HtmlUnitDriver "scala-lang.org" should "have the correct title" in { go to ("http://www.scala-lang.org") title should be ("The Scala Programming Language") } "scala-lang.org" should "have a downlod link" in { go to ("http://www.scala-lang.org") click on linkText("Download iScala") title should be ("Scala Distribution | The Scala Programming Language") } }
Play2.0 には FluentLenium (Seleniumのラッパー) が標準で入っていて、それもまあまあ使いやすいのですが、
DSL としては ScalaTest のほうがきれいですね。