Search code examples
selenium-webdriverplayframeworkspecs2

Play Framework : Run test on multiple drivers


I use PlayFramework 2.3 and specs2 to write functional tests.

In the documentation, there is the following example

"run in a browser" in new WithBrowser(webDriver = WebDriverFactory(HTMLUNIT), app = fakeApplicationWithBrowser) {
…
}

How to run this test against multiple drivers ?

I currently use :

def drivers: Seq[String => WebDriver] = ...

examplesBlock {
  for (driver <- drivers) {
    "run in a browser" in ((s: String) => new WithBrowser(d(s)) {
…
    }
  }
}

Is there a better (simpler) way ?


Solution

  • Finally, I've came up with a cleaner solution, by extracting the logic in a trait

    trait MultiBrowser {
      self : Specification =>
    
      def drivers : Seq[String => WebDriver]
    
      def browsers(u: (String => WebDriver) => Unit) = examplesBlock {
        for (driver <- drivers) {
          u(driver)
        }
      }
    }