Functional testing using Geb

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Functional testing using Geb

Paul_Fairless
Hi,

I'm looking to set up a functional test suite using Geb and ghostdriver. Are there any recommendations as to how get started? Are there any good examples outside of the Ratpack codebase itself?

Are you supposed to use LocalScriptApplicationUnderTest - how does this get configured?

Any advice most appreciated

Thanks
Paul
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

beckje01
The ratpack site is tested with SauceLabs and Geb, the tests are here.

I don't know of anyone else that has done a Geb setup yet, as for configuring LocalScriptApplicationUnderTest it should be configured the same way as ratpack itself.

Jeff
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Paul_Fairless
I've been trying to match the config used but not having much luck so far. Will the browserTest task run without saucelabs?

LocalScriptApplicationUnderTest throws an exception:

org.ratpackframework.launch.LaunchException: Could not create handler via handler factory: org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory
        at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:61)
        at org.ratpackframework.server.RatpackServerBuilder.buildChannelInitializer(RatpackServerBuilder.java:53)
        at org.ratpackframework.server.RatpackServerBuilder.build(RatpackServerBuilder.java:46)
        at org.ratpackframework.launch.RatpackMain.server(RatpackMain.java:53)
        at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:41)
        at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:25)
        at org.ratpackframework.test.ServerBackedApplicationUnderTest.getAddress(ServerBackedApplicationUnderTest.java:37)
        at HomepageSpec.setup(HomepageSpec.groovy:12)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /Dev/project/ratpack.groovy (No such file or directory)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:57)
        at org.ratpackframework.groovy.internal.ScriptBackedApp.<init>(ScriptBackedApp.java:46)
        at org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory.create(GroovyScriptHandlerFactory.java:42)
        at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:59)
        ... 7 more
Caused by: java.io.FileNotFoundException: /Dev/project/ratpack.groovy (No such file or directory)
        at java.io.FileInputStream.<init>(FileInputStream.java:143)
        at org.ratpackframework.util.internal.IoUtils.readFile(IoUtils.java:39)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.refresh(ReloadableFileBackedFactory.java:105)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:55)


ratpack.groovy is in /Dev/project/src/ratpack/ratpack.groovy I guess I'm missing some configuration but can't seem to see what it is yet
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Marcin Erdmann
can you please show us your build.gradle?


On Mon, Sep 30, 2013 at 4:13 PM, Paul_Fairless [via Ratpack Forum] <[hidden email]> wrote:
I've been trying to match the config used but not having much luck so far. Will the browserTest task run without saucelabs?

LocalScriptApplicationUnderTest throws an exception:

org.ratpackframework.launch.LaunchException: Could not create handler via handler factory: org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory
        at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:61)
        at org.ratpackframework.server.RatpackServerBuilder.buildChannelInitializer(RatpackServerBuilder.java:53)
        at org.ratpackframework.server.RatpackServerBuilder.build(RatpackServerBuilder.java:46)
        at org.ratpackframework.launch.RatpackMain.server(RatpackMain.java:53)
        at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:41)
        at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:25)
        at org.ratpackframework.test.ServerBackedApplicationUnderTest.getAddress(ServerBackedApplicationUnderTest.java:37)
        at HomepageSpec.setup(HomepageSpec.groovy:12)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /Dev/project/ratpack.groovy (No such file or directory)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:57)
        at org.ratpackframework.groovy.internal.ScriptBackedApp.<init>(ScriptBackedApp.java:46)
        at org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory.create(GroovyScriptHandlerFactory.java:42)
        at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:59)
        ... 7 more
Caused by: java.io.FileNotFoundException: /Dev/project/ratpack.groovy (No such file or directory)
        at java.io.FileInputStream.<init>(FileInputStream.java:143)
        at org.ratpackframework.util.internal.IoUtils.readFile(IoUtils.java:39)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.refresh(ReloadableFileBackedFactory.java:105)
        at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:55)


ratpack.groovy is in /Dev/project/src/ratpack/ratpack.groovy I guess I'm missing some configuration but can't seem to see what it is yet



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack-framework.org/Functional-testing-using-Geb-tp176p178.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Paul_Fairless
buildscript {
  repositories {
    maven { url "http://oss.jfrog.org/repo" }
    mavenCentral()
    maven { url "http://dl.bintray.com/robfletcher/gradle-plugins" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
  dependencies {
    classpath ('org.ratpack-framework:ratpack-gradle:0.9.0-SNAPSHOT')
    classpath 'org.gebish:geb-gradle:0.9.2-SNAPSHOT'
    classpath "org.gradle.plugins:gradle-compass:1.0.9"
  }
}
repositories {
  maven { url "http://oss.jfrog.org/repo" }
  mavenCentral()
  maven { url "http://repo.springsource.org/repo" } // for springloaded
  maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

// The “ratpack” plugin applies the “application” plugin, making it easy to create a standalone application.
// See: http://gradle.org/docs/current/userguide/application_plugin.html
apply plugin: "ratpack-groovy"
apply plugin: "compass"
compass {
    cssDir = file("src/ratpack/public/css")
    sassDir = file("src/main/sass")
    imagesDir = file("src/ratpack/public/images")
    relativeAssets = true
    debugInfo = false
    environment = "production"
}

processResources.inputs.files compileSass
run.dependsOn watchSass
clean.dependsOn cleanCompileSass


applicationDistribution.from('src/ratpack/templates') {
    into "templates"
}
applicationDistribution.from('src/ratpack/public') {
    into "public"
}
applicationDistribution.from('src/ratpack/handlebars') {
    into "handlebars"
}
applicationDistribution.from('src/ratpack/ratpack.groovy') {
    into "."
}
// The “ratpack” plugin is IDEA aware.
// It will create a run configuration in IDEA to launch your app in your IDE, with hot reloading.
apply plugin: "idea"
idea {
    project {
        jdkName "1.7"
        languageLevel "1.7"
    }
}

configurations {
    browserTestCompile.extendsFrom testCompile
    browserTestRuntime.extendsFrom testRuntime
}

sourceSets {
    browserTest {
        resources.srcDir(file('src/ratpack'))
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}
dependencies {
    // SpringLoaded enables runtime hot reloading.
    // It is not part of the app runtime and is not shipped in the distribution.
    springloaded "org.springsource.springloaded:springloaded-core:1.1.1"
    compile "com.codahale.metrics:metrics-core:3.0.0"
    compile "com.codahale.metrics:metrics-jvm:3.0.0"
    compile "joda-time:joda-time:2.2"
    compile "org.ratpack-framework:ratpack-handlebars:0.9.0-SNAPSHOT"


    testCompile "org.spockframework:spock-core:0.7-groovy-2.0"

    browserTestCompile "org.gebish:geb-spock:0.9.2-SNAPSHOT"
    browserTestCompile "com.github.detro.ghostdriver:phantomjsdriver:1.0.4"
    browserTestCompile "org.seleniumhq.selenium:selenium-chrome-driver:2.34.0", {
        exclude module: 'guava'
    }
}

task browserTest(type: Test) {
    testClassesDir = sourceSets.browserTest.output.classesDir
    classpath = sourceSets.browserTest.runtimeClasspath
    systemProperty 'geb.build.reportsDir', project.reporting.file("$name-geb")
}

run {
    systemProperty "ratpack.reloadable", "true"
}

task wrapper(type: Wrapper) {
  gradleVersion = '1.6'
}
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Marcin Erdmann
This looks right to me assuming that your Geb tests are in browserTest source set. If I comment out this line in ratpack-site.gradle:

sourceSets {
  browserTest {
    //resources.srcDir(file('src/ratpack'))
    compileClasspath += main.output
    runtimeClasspath += main.output
  }
}

then I get the exact same error as you do:
org.ratpackframework.launch.LaunchException: Could not create handler via handler factory: org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory
at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:60)
at org.ratpackframework.server.RatpackServerBuilder.buildChannelInitializer(RatpackServerBuilder.java:52)
at org.ratpackframework.server.RatpackServerBuilder.build(RatpackServerBuilder.java:45)
at org.ratpackframework.launch.RatpackMain.server(RatpackMain.java:53)
at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:41)
at org.ratpackframework.test.RatpackMainServerFactory.create(RatpackMainServerFactory.java:25)
at org.ratpackframework.test.ServerBackedApplicationUnderTest.getAddress(ServerBackedApplicationUnderTest.java:37)
at org.ratpackframework.site.SiteManualSpec.setup(SiteManualSpec.groovy:31)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /Users/erdi/workspace/ratpack/ratpack-site/ratpack.groovy (No such file or directory)
at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:57)
at org.ratpackframework.groovy.internal.ScriptBackedApp.<init>(ScriptBackedApp.java:46)
at org.ratpackframework.groovy.launch.GroovyScriptHandlerFactory.create(GroovyScriptHandlerFactory.java:42)
at org.ratpackframework.server.RatpackServerBuilder.createHandler(RatpackServerBuilder.java:58)
... 7 more
Caused by: java.io.FileNotFoundException: /Users/erdi/workspace/ratpack/ratpack-site/ratpack.groovy (No such file or directory)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.ratpackframework.util.internal.IoUtils.readFile(IoUtils.java:39)
at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.refresh(ReloadableFileBackedFactory.java:105)
at org.ratpackframework.reload.internal.ReloadableFileBackedFactory.<init>(ReloadableFileBackedFactory.java:55)
... 10 more

And yes, the way you configured it should work with local driver and not SauceLabs.


On Mon, Sep 30, 2013 at 4:52 PM, Paul_Fairless [via Ratpack Forum] <[hidden email]> wrote:
buildscript {
  repositories {
    maven { url "http://oss.jfrog.org/repo" }
    mavenCentral()
    maven { url "http://dl.bintray.com/robfletcher/gradle-plugins" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
  dependencies {
    classpath ('org.ratpack-framework:ratpack-gradle:0.9.0-SNAPSHOT')
    classpath 'org.gebish:geb-gradle:0.9.2-SNAPSHOT'
    classpath "org.gradle.plugins:gradle-compass:1.0.9"
  }
}
repositories {
  maven { url "http://oss.jfrog.org/repo" }
  mavenCentral()
  maven { url "http://repo.springsource.org/repo" } // for springloaded
  maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

// The “ratpack” plugin applies the “application” plugin, making it easy to create a standalone application.
// See: http://gradle.org/docs/current/userguide/application_plugin.html
apply plugin: "ratpack-groovy"
apply plugin: "compass"
compass {
    cssDir = file("src/ratpack/public/css")
    sassDir = file("src/main/sass")
    imagesDir = file("src/ratpack/public/images")
    relativeAssets = true
    debugInfo = false
    environment = "production"
}

processResources.inputs.files compileSass
run.dependsOn watchSass
clean.dependsOn cleanCompileSass


applicationDistribution.from('src/ratpack/templates') {
    into "templates"
}
applicationDistribution.from('src/ratpack/public') {
    into "public"
}
applicationDistribution.from('src/ratpack/handlebars') {
    into "handlebars"
}
applicationDistribution.from('src/ratpack/ratpack.groovy') {
    into "."
}
// The “ratpack” plugin is IDEA aware.
// It will create a run configuration in IDEA to launch your app in your IDE, with hot reloading.
apply plugin: "idea"
idea {
    project {
        jdkName "1.7"
        languageLevel "1.7"
    }
}

configurations {
    browserTestCompile.extendsFrom testCompile
    browserTestRuntime.extendsFrom testRuntime
}

sourceSets {
    browserTest {
        resources.srcDir(file('src/ratpack'))
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}
dependencies {
    // SpringLoaded enables runtime hot reloading.
    // It is not part of the app runtime and is not shipped in the distribution.
    springloaded "org.springsource.springloaded:springloaded-core:1.1.1"
    compile "com.codahale.metrics:metrics-core:3.0.0"
    compile "com.codahale.metrics:metrics-jvm:3.0.0"
    compile "joda-time:joda-time:2.2"
    compile "org.ratpack-framework:ratpack-handlebars:0.9.0-SNAPSHOT"


    testCompile "org.spockframework:spock-core:0.7-groovy-2.0"

    browserTestCompile "org.gebish:geb-spock:0.9.2-SNAPSHOT"
    browserTestCompile "com.github.detro.ghostdriver:phantomjsdriver:1.0.4"
    browserTestCompile "org.seleniumhq.selenium:selenium-chrome-driver:2.34.0", {
        exclude module: 'guava'
    }
}

task browserTest(type: Test) {
    testClassesDir = sourceSets.browserTest.output.classesDir
    classpath = sourceSets.browserTest.runtimeClasspath
    systemProperty 'geb.build.reportsDir', project.reporting.file("$name-geb")
}

run {
    systemProperty "ratpack.reloadable", "true"
}

task wrapper(type: Wrapper) {
  gradleVersion = '1.6'
}



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack-framework.org/Functional-testing-using-Geb-tp176p180.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Paul_Fairless
current Gradle documentation (1.8) suggests the resources property is read-only (http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html#org.gradle.api.tasks.SourceSet:resources)

what version of Gradle is being used to run the tests on ratpack-site?
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Paul_Fairless
After a closer look at the docs I see the srcDir method is fine to call on resources

Not really sure how best to progress this - is it possible there is a setting from a parent build that I need to add?
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Marcin Erdmann
I think I know what the problem might be. Do you have ratpack.properties file next to ratpack.groovy?


On Tue, Oct 1, 2013 at 11:38 AM, Paul_Fairless [via Ratpack Forum] <[hidden email]> wrote:
After a closer look at the docs I see the srcDir method is fine to call on resources

Not really sure how best to progress this - is it possible there is a setting from a parent build that I need to add?


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack-framework.org/Functional-testing-using-Geb-tp176p183.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Functional testing using Geb

Paul_Fairless
Adding an empty ratpack.properties solved this for me. Thank you for your help - much appreciated

Paul