Search code examples
grailsfunctional-testinggeb

Drive two different browsers in one GebReportingSpec?


I'm using geb and spock for functional tests in my Grails 2.3.7 app. The app allows real-time interaction between users, which I'd like to test automatically.

Does anyone know how, or if it's possible, to run two different browsers in one Spec? For example, see the pseudo code below for how I imagine this working in a perfect world.

@Stepwise
class ChatPageSpec extends GebReportingSpec {

    def "login with chrome"() {
    }

    def "login with firefox"() {
    }

    def "send chat request with chrome"() {
    }

    def "accept chat request with firefox"() {
    }

    def "send hello with chrome"() {
    }

    def "receive hello with firefox"() {
    }
}

Running the tests in parallel as Craig describes (http://www.objectpartners.com/2013/11/14/parallel-grails-functional-tests-with-geb-and-gradle/) looked promising, but if I understand it correctly, the parallel tests would use different app instances, which won't work. Plus, @Stepwise or something similar would have to keep the browsers in sync.

I also checked out the poly driver plugin (http://grails.org/plugin/poly-driver), but it looks like it's designed for one browser per Spec.

Ken


Solution

  • I'm afraid that you will need to handcraft something for this.

    There is an example of achieving this which was once posted to Geb mailing list. I have never used it myself but the code looks reasonable. It feels like you'll want to use MultiBrowserGebSpec and override createBrowserMap().

    You can create driver instances by hand and then set it on browsers instances using setDriver(). Another way would be to have different config files for different browsers which you would load using getConf() and pass to Browser constructor. Yet another one would be to have different environments for different browsers in one GebConfig.groovy and use different ConfifgurationLoaders created using the constructor that accepts environment name.