Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Started with Playframework 2.0 and Selenium

I am using Play framework 2.0. I would like to write some browser-based acceptance test using Selenium, but I have never used Selenium before must less integrated it with Play or Scala.

What is a basic setup that I can copy and work from?

like image 796
Jacob Groundwater Avatar asked Nov 13 '22 07:11

Jacob Groundwater


1 Answers

Here is an example on how to do it with HTMLUnit, if that helps you.

Inspired from: https://github.com/joscha/Play20/blob/master/samples/scala/computer-database/test/IntegrationSpec.scala

import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
import org.fluentlenium.core.filter.FilterConstructor._
class IntegrationSpec extends Specification {
  "Application" should {
    "work from within a browser" in {
      running(TestServer(3333), HTMLUNIT) { browser =>
        browser.goTo("http://www.myRockstartDomain.com:3333/")
          browser.$("header h1").first.getText must contain("Play 2.0 sample application — Computer database")
          browser.$("#pagination li.current").first.getText must equalTo("Displaying 1 to 10 of 574")
          browser.$("#pagination li.next a").click()
          browser.$("#pagination li.current").first.getText must equalTo("Displaying 11 to 20 of 574")
          browser.$("#searchbox").text("Apple")
          browser.$("#searchsubmit").click()
      }
    }
  }
}
like image 102
bjartek Avatar answered Dec 20 '22 00:12

bjartek