Search code examples
spockgeb

Failed to find spock.lang.Specification


I am trying to use Geb+Spock to do web automation testing, but it keeps telling me :

Caught: java.lang.NoClassDefFoundError: spock/lang/Specification
Caused by: java.lang.ClassNotFoundException: spock.lang.Specification

And I think I have already added the things spock might need ...?

@Grapes([
    @Grab('org.gebish:geb-core:1.1.1'),
    @Grab('org.seleniumhq.selenium:selenium-chrome-driver:2.42.0'),
    @Grab('org.seleniumhq.selenium:selenium-support:2.42.0'),
    @Grab('org.gebish:geb-spock:1.1.1')
])

import geb.spock.GebSpec
import spock.lang.*

class GoogleSpec extends GebSpec{
    def "Google search"() {
        given:
        to GooglePage

        when:
        searchBox.value == "Dogs"

        and:
        searchButton.click()

        then:
        at ResultPage
    }
}

Solution

  • Well, maybe you also want to add dependencies to

    • Spock itself:
      org.spockframework:spock-core:1.0-groovy-2.4
    • Optionally, if you want to mock classes (in addition to interfaces) in Spock:
      cglib:cglib-nodep:3.2.4
    • Optionally, if you feel the urge to mock final classes (please don't, it is evil!) and classes without default constructors (that's fine) in Spock:
      org.objenesis:objenesis:2.2

    I don't know anything about Gradle, but those I use in Maven.

    P.S.: Maybe next time you want to use your favourite web search engine to look for sample projects or documentation first. You should find plenty.