I'm trying to integrate Gebish into Gradle.
I already found this nice tutorial: http://www.gebish.org/manual/0.9.2/build-integrations.html#gradle
The find is that I want to specify the browser with the commandline.
Now I have this code:
def gebVersion = '0.13.1'
def seleniumVersion = '2.51.0'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile("org.spockframework:spock-core:1.0-groovy-2.4")
testRuntime "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
/*
// Drivers
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
*/
}
task firefoxTest(type: Test) {
dependencies {
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
}
}
task chromeTest(type: Test) {
dependencies {
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
}
}
test {
systemProperties "geb.build.reportsDir": "$reportsDir/geb"
}
Also I have this big test that is located at src/test/groovy/test.groovy
import geb.Browser
Browser.drive {
go "http://stackoverflow.com"
}
The problem is that if I run gradle with gradlew firefoxTest or gradlew chromeTest it happens nothing and I get the following message:
14:02:03: Executing external task 'chromeTest'...
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:chromeTest
BUILD SUCCESSFUL
Total time: 2.534 secs
14:02:05: External task execution finished 'chromeTest'.
How can I run my test through the commandline with the specific browser?
Also is it possible to build in Browserstack support?
It looks like you have Gradle set up correctly. However, your big test needs to extend either geb.spock.GebReportingSpec or geb.junit4.GebReportingTest in order to be detected by the test runner as a test. It will then have to contain a test fitting the requirements for either the Spec or the Test. For example, see GebishOrgSpec.groovy and GebishOrgTest.groovy in the Geb Gradle example project.
With regards to running tests using multiple browsers, have a look at the build file of the Geb's example project that uses gradle. Namely at how Geb environment is set here and then used in GebConfig.groovy over here and here.
Related
I have a Gradle project with Kotlin with 3 source folders (main, test, integration). I want to set up different Gradle test tasks for unit and integration tests. That what those test and integration folders are for. I tried several solutions to set up integration test task but nothing worked so far. It's mentioned everywhere that I need to create a different sourceSet for integration, add some configuration to be able to compile the code in that folder properly and set up the task itself. It's all done, but when I run the tests, they fail. The report then says ClassNotFound for everything basically what is inside that(integration) folder.
build.gradle file and the output results are attached below
buildscript {
ext.kotlin_version = '1.3.71'
ext.ktor_version = '1.3.2'
ext.exposed_version = '0.22.1'
ext.kodein_version = '6.5.0'
ext.postgres_version = '42.2.6'
ext.stripe_version = '17.16.0'
ext.junit_version = '5.6.0'
ext.log4j2_version = '2.13.1'
ext.aws_sdk_version = '1.11.734'
ext.html_to_pdf_version = '1.0.0'
ext.kotlintest_version = '4.0.2'
repositories {
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "javax.jms:jms:1.1"
}
}
plugins {
id("java")
id 'org.jetbrains.kotlin.jvm' version '1.3.71'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.71'
id("application")
}
group 'nz.co.redium'
mainClassName = 'nz.co.redium.bookmybusiness.ApplicationKt'
repositories {
mavenCentral()
jcenter()
maven { url "https://dl.bintray.com/kotlin/ktor" }
}
compileKotlin {
kotlinOptions.jvmTarget = "12"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "12"
}
sourceSets {
integration {
java.srcDir "$projectDir/src/integration/kotlin"
kotlin.srcDir "$projectDir/src/integration/kotlin"
resources.srcDir "$projectDir/src/integration/resources"
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations {
integrationImplementation.extendsFrom testImplementation
integrationRuntime.extendsFrom testRuntime
}
test {
useJUnitPlatform()
afterTest { desc, result ->
println "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Multi-Release': true,
'Main-Class': "$mainClassName"
}
project.archivesBaseName = project.name + '-full'
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task integrationTest(type: Test) {
useJUnitPlatform()
description = 'Runs the integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
outputs.upToDateWhen { false }
mustRunAfter test
afterTest { desc, result ->
println "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
check.dependsOn integrationTest
dependencies {
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-server-host-common:$ktor_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "io.ktor:ktor-jackson:$ktor_version"
implementation "io.ktor:ktor-locations:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "io.ktor:ktor-client-jetty:$ktor_version"
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.jetbrains.exposed:exposed-core:$exposed_version"
implementation "org.jetbrains.exposed:exposed-dao:$exposed_version"
implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version"
implementation "org.jetbrains.exposed:exposed-jodatime:$exposed_version"
implementation "org.postgresql:postgresql:$postgres_version"
implementation "org.apache.logging.log4j:log4j-api:$log4j2_version"
implementation "org.apache.logging.log4j:log4j-core:$log4j2_version"
implementation "org.apache.logging.log4j:log4j-slf4j-impl:$log4j2_version"
implementation "org.springframework.security:spring-security-core:5.1.5.RELEASE"
implementation "com.amazonaws:aws-java-sdk-ses:$aws_sdk_version"
implementation "com.amazonaws:aws-java-sdk-s3:$aws_sdk_version"
implementation "com.stripe:stripe-java:$stripe_version"
implementation "org.apache.velocity:velocity-engine-core:2.1"
implementation "com.openhtmltopdf:openhtmltopdf-core:$html_to_pdf_version"
implementation "com.openhtmltopdf:openhtmltopdf-pdfbox:$html_to_pdf_version"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.10.3"
implementation "org.jetbrains.exposed:exposed-jodatime:$exposed_version"
implementation "io.rest-assured:rest-assured:4.3.0"
implementation "org.hamcrest:hamcrest:2.2"
testImplementation "io.kotest:kotest-runner-junit5-jvm:$kotlintest_version" // for kotest framework
testImplementation "io.kotest:kotest-assertions-core-jvm:$kotlintest_version" // for kotest core jvm assertions
testImplementation "org.assertj:assertj-core:3.11.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
testImplementation "io.ktor:ktor-server-core:$ktor_version"
testImplementation "io.ktor:ktor-server-host-common:$ktor_version"
testImplementation "io.ktor:ktor-gson:$ktor_version"
testImplementation "io.mockk:mockk:1.9.3"
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5'
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
> Task :integrationClasses UP-TO-DATE
Skipping task ':integrationClasses' as it has no actions.
:integrationClasses (Thread[Daemon worker Thread 29,5,main]) completed. Took 0.0 secs.
:integrationTest (Thread[Daemon worker Thread 29,5,main]) started.
Gradle Test Executor 19 started executing tests.
Gradle Test Executor 19 finished executing tests.
> Task :integrationTest FAILED
file or directory '/opt/receptioner/bookmybusiness/build/classes/java/integration', not found
Caching disabled for task ':integrationTest' because:
Build cache is disabled
Task ':integrationTest' is not up-to-date because:
Task.upToDateWhen is false.
file or directory '/opt/receptioner/bookmybusiness/build/classes/java/integration', not found
Starting process 'Gradle Test Executor 19'. Working directory: /opt/receptioner/bookmybusiness Command: /usr/lib/jvm/java-13-openjdk-amd64/bin/java -Dorg.gradle.native=false #/tmp/gradle-worker-classpath16424721448345780337txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=NZ -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 19'
Successfully started process 'Gradle Test Executor 19'
Finished generating test XML results (0.0 secs) into: /opt/receptioner/bookmybusiness/build/test-results/integrationTest
Generating HTML test report...
Finished generating test html results (0.0 secs) into: /opt/receptioner/bookmybusiness/build/reports/tests/integrationTest
:integrationTest (Thread[Daemon worker Thread 29,5,main]) completed. Took 0.523 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':integrationTest'.
> There were failing tests. See the report at: file:///opt/receptioner/bookmybusiness/build/reports/tests/integrationTest/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
13 actionable tasks: 1 executed, 12 up-to-date
It's weird though that the failed task refers to classes/java/integration folder (which does't exist) instead of classes/kotlin/integratin folder, which does exist and this is where the compiled code resides in.
It was my bad. After I moved the code from test to integration folder, some resources inside (those which are responsible for initializing the classes) were pointing to the old directory test, not integration. The Gradle build file is correct.
I'm trying to build a Kotlin application but, even with successfully build, I face with the error bellow. What I'm doing wrong?
▶ java -jar build/libs/app-0.1.jar
22:10:02.122 [main] INFO io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application
Here is my build status:
▶ ./gradlew assemble
BUILD SUCCESSFUL in 3s
14 actionable tasks: 1 executed, 13 up-to-date
That is the part of my gradle.build file:
apply from: "dependencies.gradle"
apply from: "protobuf.gradle"
version "0.1"
group "app"
mainClassName = "app.Application"
dependencies {
compile "ch.qos.logback:logback-classic:1.2.3"
}
jar {
manifest {
attributes "Main-Class": mainClassName
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
I had a similar issue:
I was able to run code from IDE, but failed to run Docker container with the app
And had compile 'io.micronaut:micronaut-http-server-netty:1.1.0' in my build.gradle.
Also I was using shadowJar plugin and there was the issue. Adding:
shadowJar {
mergeServiceFiles()
}
solved the problem. It transforms entries in META-INF/services resources into a single resource. My shadowed jar file contained a lot of entries in this folder.
It is difficult to say for sure without seeing the project but one thing that could cause that issue would be not having a dependency on io.micronaut:micronaut-http-server-netty. A newly created app will have something like this in build.gradle...
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
compile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
compile "io.micronaut:micronaut-runtime"
compile "io.micronaut:micronaut-http-client"
// Make Sure You Have This...
compile "io.micronaut:micronaut-http-server-netty"
kapt "io.micronaut:micronaut-inject-java"
kapt "io.micronaut:micronaut-validation"
kaptTest "io.micronaut:micronaut-inject-java"
runtime "ch.qos.logback:logback-classic:1.2.3"
runtime "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.4.1"
testCompile "org.junit.jupiter:junit-jupiter-api:5.1.0"
testCompile "org.jetbrains.spek:spek-api:1.1.5"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:1.1.5"
}
I am very new to gradle and i am so confused in how to invoke my project so i can run my Cucumber test. What do i do after creating a build.gradle file?
my build.gradle looks like this
apply plugin: 'java'
dependencies {
testCompile 'info.cukes:cucumber-java:1.2.4'
testCompile 'info.cukes:cucumber-junit:1.2.4'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
project.ext {
cucumberVersion = '1.2.4'
junitVersion = '4.11'
}
test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
}
You create a JUnit class that uses a Cucumber runner to execute Cucumber.
#RunWith(Cucumber.class)
public class RunCukesTest {
}
in your test directory.
I describe it with more details here: http://www.thinkcode.se/blog/2015/01/30/bdd-with-cucumberjvm-at-geecon-tdd-2015
Another option is to start with the Java skeleton project that is available here: https://github.com/cucumber/cucumber-java-skeleton
And then follow the steps outlined in http://www.thinkcode.se/blog/2015/12/26/gradle-and-cucumberjvm
Just to extend Thomas's great answer I want to mention, that if your have your custom TestRunner class for specific suite of tests (like previously mentioned RunCukesTest or e.g. RegressionTestRunner), it is possible to add custom task for running the exact runner:
task runRegressionTests(type: Test) << {
include "RegressionTestRunner.class"
}
And then it is easy to run regression tests by gradle task:
gradle runRegressionTests
If you have a multiple runner classes for different suites (RegressionTestRunner, SanityTestRunner, etc) - it is useful to write a custom pattern for testing task which will recognize and run defined runner class.
E.g.:
runRegressionTests, runSanityTests.
Added the below in build.gradle file
test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
}
It invoked my cucumber test for gradle clean build
Use Gradle Cucumber JVM Plugin. It works perfectly and has pretty html reports integrated.
https://github.com/commercehub-oss/gradle-cucumber-jvm-plugin
I'm trying to get Gradle (2.1) and IntelliJ (14.0.2) to play nicely. Specifically, I have imported a sample Gradle project containing a separate source set for integration tests into IntelliJ.
The project builds fine using Gradle on the command line, and I'm able to run the integration tests successfully. When running inside IntelliJ on the other hand, I have two problems:
1) Compiling inside IntelliJ fails, due to a dependency in the integration test to a third-party library (commons-collections) which fails to resolve.
2) If I remove the dependency above and compile, I'm not able to run the integration test inside IntelliJ. I get the following error message:
No tests found for given includes: [org.gradle.PersonIntegrationTest.canConstructAPersonWithAName]
The file structure looks like this:
src
integration-test
java
resources
main
java
resources
test
java
resources
build.gradle
And build.gradle:
apply plugin: 'java'
repositories {
mavenCentral()
}
sourceSets {
integrationTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
}
}
dependencies {
testCompile 'junit:junit:4.11'
integrationTestCompile 'commons-collections:commons-collections:3.2'
integrationTestCompile sourceSets.main.output
integrationTestCompile configurations.testCompile
integrationTestCompile sourceSets.test.output
integrationTestRuntime configurations.testRuntime
}
task integrationTest(type: Test, dependsOn: jar) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
systemProperties['jar.path'] = jar.archivePath
}
check.dependsOn integrationTest
Any ideas on how to make this work would be much appreciated.
The full Gradle sample project is available in the Gradle distribution, under samples/java/withIntegrationTests
You need to tell IDEA to map entries from your integrationTest configuration into your project as TEST dependencies. I am not sure whether you need to add source root directories too. The important part is:
idea {
module {
//and some extra test source dirs
testSourceDirs += file('some-extra-test-dir')
generatedSourceDirs += file('some-extra-source-folder')
scopes.TEST.plus += [ configurations.integrationTest ]
}
}
More is described in http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
Edits to reflect Daniel's comments: generatedSourceDirs is is Gradle 2.2+.
To set up the test task you will use task like
task integTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
reports.junitXml.destination = file("${project.testResultsDir}/$name")
reports.html.destination = file("${project.reporting.baseDir}/$name")
shouldRunAfter test
}
check.dependsOn integTest
I am using Sikuli in my project to handle some flash buttons. It's working fine while running scripts locally. The issue is that when I need to run the build.gradle, I need to have the Sikuli dependency in build.gradle. That is how I have written build.gradle. When I run the build, I get this error:
What went wrong: Could not resolve all dependencies for configuration ':compile'.
Could not find com.googlecode.javacpp:javacpp:0.1. Required by:
:new_qa_automation:1.0 > org.sikuli:sikuli-api:1.0.2 > org.sikuli:sikuli-c ore:1.0.1
Could not find com.googlecode.javacv:javacv:0.1. Required by:
:new_qa_automation:1.0 > org.sikuli:sikuli-api:1.0.2 > org.sikuli:sikuli-c ore:1.0.1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED.
Here is my build.gradle file
apply plugin: 'java' version = '1.0' apply plugin: 'project-report'
repositories { mavenCentral() maven { url
"http://repo.springsource.org/release" url
"http://oss.sonatype.org/content/groups/public/" } }
sourceCompatibility = 1.6 targetCompatibility = 1.6
configurations { cucumberRuntime { extendsFrom testRuntime } }
task test(overwrite: true) {
dependsOn assemble, processTestResources, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
//some args
systemProperties System.properties
}
} }
dependencies { compile 'org.seleniumhq.selenium:selenium-java:2.32.+'
compile 'org.apache.commons:commons-lang3:3.1' compile
'org.springframework:spring-context:3.2.3.RELEASE'
compile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+' compile group: 'commons-collections', name: 'commons-collections',
version: '3.+'
testCompile 'info.cukes:cucumber-java:1.1.2'
testCompile 'info.cukes:cucumber-spring:1.1.2'
testCompile 'info.cukes:cucumber-junit:1.1.2'
testCompile 'junit:junit:4.11' testCompile 'org.easytesting:fest-assert-core:2.0+'
}
Edit:
I added the URL for the Maven repositry. Now the error has changed to
ePage.java:9: error: package org.sikuli.script does not exist
import org.sikuli.script.FindFailed;
sikuli-script.jar in Sikuli IDE project not provide in any repository so you must use it like a 3rd party jar
see:
"Mavan's central repository will not answer on any Sikuli stuff" https://answers.launchpad.net/sikuli/+question/185713
"Gradle: Make a 3rd party jar available to local gradle repository" Gradle: Make a 3rd party jar available to local gradle repository
The Sikuli code base appears to be fragmented. It's quite confusing; I know of 3 different sets of Java bindings. (one, two, three)
I think the one you're pulling with Maven is this: http://code.google.com/p/sikuli-api/
If so, org.sikuli.script is not the right import. You don't include your code to show me what you're trying to do with Sikuli, but most of the things you'd want to import are somewhere under org.sikuli.api.
Just download the sikulix jar and mention it in build.gradle
eg: compile files('C:\Users\vedavyasa\Documents\jar\sikulixapi.jar')