Facing issues while running cucumber with serenity

3.2k views Asked by At

To integrate Cucumber with Serenity, I have created below Gardle file. Serenity is working fine, however I am not able to use it with Cucumber. When I use @RunWith(CucumberWithSerenity.class) in runner class, it gives me unresolved type error.

build.gradle:

apply plugin: "java"
apply plugin: "maven"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'  
apply plugin: 'com.jfrog.bintray'

group = "myorg"
version = 1.0

repositories {
    maven {

            url "http://nexus2.sdmc.ao-srv.com/content/groups/inhouse_dit/"
        }
}

buildscript {
    repositories {
        maven {

            url "http://nexus2.sdmc.ao-srv.com/content/groups/inhouse_dit/"
        }
    }

    dependencies {

        classpath("net.serenity-bdd:serenity-gradle-plugin:1.0.47")
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6' 
    }
}

ext {
bintrayBaseUrl = 'https://api.bintray.com/maven'
bintrayRepository = 'maven'
bintrayPackage = 'serenity-cucumber'
projectDescription = 'Serenity Cucumber integration'
if (!project.hasProperty("bintrayUsername")) {
bintrayUsername = 'wakaleo'
}
if (!project.hasProperty("bintrayApiKey")) {
bintrayApiKey = ''
}
serenityCoreVersion = '1.0.49'
cucumberJVMVersion = '1.2.2'
//versionCounter = new ProjectVersionCounter(isRelease: project.hasProperty("releaseBuild"))
}

sourceSets.all { set ->
    def jarTask = task("${set.name}Jar", type: Jar) {
        baseName = baseName + "-$set.name"
        from set.output
    }

    artifacts {
        archives jarTask
    }
}

sourceSets {
    api
    impl
}

dependencies {
    apiCompile 'commons-codec:commons-codec:1.5'

    implCompile sourceSets.api.output
    implCompile 'commons-lang:commons-lang:2.6'

    compile "info.cukes:cucumber-java:${cucumberJVMVersion}"
    compile "info.cukes:cucumber-junit:${cucumberJVMVersion}"

    testCompile 'net.serenity-bdd:core:1.0.47'                          
    testCompile 'net.serenity-bdd:serenity-junit:1.0.47'                
    testCompile('junit:junit:4.11')
    testCompile('org.assertj:assertj-core:1.7.0')
    testCompile('org.slf4j:slf4j-simple:1.7.7')
    testCompile sourceSets.api.output
    testCompile sourceSets.impl.output
     testCompile 'org.codehaus.groovy:groovy-all:2.3.6'
    testCompile("org.spockframework:spock-core:0.7-groovy-2.0") {
        exclude group: "junit"
        exclude module: "groovy-all"
    }

    testCompile("com.github.goldin:spock-extensions:0.1.4") {
        exclude module: "spock-core"
        exclude module: "slf4j-api" 
    }   
    runtime configurations.apiRuntime
    runtime configurations.implRuntime
}
gradle.startParameter.continueOnFailure = true 

jar {
    from sourceSets.api.output
    from sourceSets.impl.output
    manifest {
             attributes("Implementation-Title": "Serenity Cucumber Plugin",
             "Implementation-Version": project.version.toString())
            }
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar, javadocJar
}


bintray {
user = bintrayUsername //this usually comes form gradle.properties file in ~/.gradle
key = bintrayApiKey //this usually comes form gradle.properties file in ~/.gradle
publications = ['mavenJava'] // see publications closure
pkg {
repo = 'maven'
userOrg = 'serenity'
name = 'serenity-cucumber'
desc = 'Serenity Cucumber integration'
licenses = ['Apache-2.0']
labels = ['serenity','bdd','cucumber']
}
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri("${buildDir}/repo"))

            addFilter("main") { artifact, file -> artifact.name == project.name }
            ["api", "impl"].each { type ->
                addFilter(type) { artifact, file -> artifact.name.endsWith("-$type") }

                // We now have to map our configurations to the correct maven scope for each pom
                ["compile", "runtime"].each { scope ->
                    configuration = configurations[type + scope.capitalize()]
                    ["main", type].each { pomName ->
                        pom(pomName).scopeMappings.addMapping 1, configuration, scope
                    }
                }
            }

        }
    }  

}
task wrapper (type: Wrapper) {

    gradleVersion = '2.3'

    distributionUrl = 'http://nexus2.sdmc.ao-srv.com/content/repositories/inhouse_dit_thirdparty/org/gradle/gradle-bin/2.3/gradle-2.3-bin.zip' 

}

Please suggest what I need to change to run serenity with Cucumber. Thanks in advance.

2

There are 2 answers

0
Sébastien Le Callonnec On BEST ANSWER

You need to add serenity-cucumber to your dependencies:

testCompile 'net.serenity-bdd:serenity-cucumber:1.0.17'
0
Alex Ureche On

Following line fixed the issue for me (gradle 4.10):

testCompile group: 'net.serenity-bdd', name: 'serenity-cucumber', version: '1.9.40'