Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
Created October 16, 2014 22:34
Show Gist options
  • Save RobertFischer/134f97c5de9c6248a889 to your computer and use it in GitHub Desktop.
Save RobertFischer/134f97c5de9c6248a889 to your computer and use it in GitHub Desktop.
Why does one work but the other doesn't?
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._
import play.api.test._
import play.api.test.Helpers._
import org.openqa.selenium.WebDriver
// This compiles
@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {
"Application" should {
"work from within a browser" in new WithBrowser {
browser.goTo("http://localhost:" + port)
browser.pageSource must contain("KreateLabs")
}
}
}
// This doesn't -- complains that AppBrowser needs a type variable
@RunWith(classOf[JUnitRunner])
class IntegrationSpec2 extends Specification {
trait AppBrowser[WEBDRIVER <: WebDriver] extends WithBrowser[WEBDRIVER] {}
"Application" should {
"work from within a browser" in new AppBrowser {
browser.goTo("http://localhost:" + port)
browser.pageSource must contain("KreateLabs")
}
}
}
@jroper
Copy link

jroper commented Oct 28, 2014

A number of problems:

  • WithBrowser is an abstract class. A trait can't extend an abstract class, it can only extend other traits
  • AppBrowser is parameterised, when you use it, you're not declaring that parameter type (the reason WithBrowser works is that the default arguments for the constructor parameters declare what the type of WEBDRIVER is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment