After creating new java gradle project added following dependencies in build file.
enter image description here
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.3.0'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.3.0'
// https://mvnrepository.com/artifact/org.testng/testng
testImplementation group: 'org.testng', name: 'testng', version: '7.6.1'
// https://mvnrepository.com/artifact/org.apache.poi/poi
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2'
// https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api
implementation("javax.annotation:javax.annotation-api:1.3.2")
}
Then following popup appeared on vs code.
"Do you want to synchronize the Java classpath/configuration" once and for all? with yes/always/never option
I tried selecting each option in new project. Still after doing gradle build none of dependency downloaded
So if I am writing WebDriver or WebDriverManager I am not getting import option in quick fix
Related
I have well configure and designed framework using webdrivermanager = '5.0.3'( Selenium 3.141.5,) + Junit 5 + junit-platform.properties file to run the test scripts in parallel, which running seamlessly without any issues. I am able to run scripts based on tags and based on package.
Now I upgraded the selenium version to 4.1.2, when I run individual script it is perfectly fine but when run the scripts in parallel infinite browsers are launching even though thread count is restricted to 5 in junit-platform.properties file.
junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=same_thread
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=5
I am using below mentioned dependencies in build gradle file.
repositories {
jcenter()
mavenCentral()
}
ext {
// selenium = '3.141.59'
webdrivermanager = '5.0.3'
// junitJupiterVersion = '5.8.2'
selenium = '4.1.2'
seleniumJupiterVersion = '4.0.1'
junitJupiterVersion = '5.7.0'
}
dependencies {
compile("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}")
compile("org.seleniumhq.selenium:selenium-java:${selenium}")
// compile("io.github.bonigarcia:selenium-jupiter:${seleniumJupiterVersion}")
// compile("org.seleniumhq.selenium:selenium-java:${selenium}")
// compile("io.github.bonigarcia:webdrivermanager:${webdrivermanager}")
// testImplementation "org.seleniumhq.selenium:selenium-chrome-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-firefox-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-ie-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-edge-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-safari-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-remote-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-support:${selenium}"
// testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
// testImplementation 'org.hamcrest:hamcrest:2.1'
// testImplementation 'org.hamcrest:hamcrest-library:2.1'
// testCompile("org.junit.jupiter:junit-jupiter-api:5.6.2")
// testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// testRuntime("org.junit.platform:junit-platform-launcher:1.4.2")
// testCompile('io.github.bonigarcia:selenium-jupiter:4.0.1')
compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.11.0'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.16'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
// implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
compile group: 'io.qameta.allure', name: 'allure-gradle', version: '2.7.0'
compile 'org.apache.maven.plugins:maven-surefire-plugin:2.21.0'
// compile('com.assertthat:selenium-shutterbug:1.5')
compile 'org.slf4j:slf4j-nop:1.7.25'
implementation group: 'javax.mail', name: 'mail', version: '1.4.7'
// implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
// runtimeClasspath group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
// compile group: 'net.lightbody.bmp', name: 'browsermob-core', version: '2.1.4'
// compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.4'
compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'
// implementation group: 'org.json', name: 'json', version: '20201115'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.2'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-surefire-provider', version: '1.3.2'
}
Project component : Selenium 4 +Junit5 +junit-platform properties file
Any help to resolve this issue is highly appreciated.
Sorry, if the question is still relevant, of course.
First, you may just marked all your test classes with #ResourceLock("SYSTEM_OUT") annotation. see details here and below about Syncronization.
However this may not help. Then you may additionally implement ParrallelExecutionConfiguration and ParallelExecutionConfigurationStrategy and write this implementation in a junit-platform.properties file e.g.
junit.juipiter.execution.parallel.config.custom.class=base.ParallelStrategy
where "base" - package and "ParallelStrategy" - the implementation of the above interfaces (I just return numbers of thread values).
Also you have to state custom strategy explicitly:
junit.juipiter.execution.parallel.config.strategy=custom
Why it worked with Selenium3+, but stopped with the fourth - I don’t know. But these steps solved the same problem for me as yours.
There's a few components which might be causing this.
JUnit issue 'Parallelism value ignored for the fixed strategy' #2273 describes how the ForkJoinPool used will actually grow if threads are blocked
Selenium issue 'Can no longer limit the number of parallel sessions from JUnit 5 #9359' describes how the above issue impacts Selenium versions 4.0.0-alpha-4 and up.
Both issues suggest defining a custom strategy which limits the MaxPoolSize. This works, but only on JDK9 and up. The ForkJoinPool created in ForkJoinPoolHierarchicalTestExecutorService is different between JDK8 and JDK9+, with only the latter using the strategy MaxPoolSize.
So if you're on JDK8, I think the only option is to use ResourceLocks. Otherwise, define a custom strategy.
See my SO post maven-failsafe-plugin not honoring fixed parallelism in JUnit5 for pretty much the same issue.
I try to build a working jar from my project by IntellIJ.
(I add the artifact and build it from the build menu)
I literally can build it as a clean helloworld but as I keep adding the dependencies it breaks.
The built artifact those not find my main class:
Error: Could not find or load main class hu.qlmdc.drp.HelloWorldKt
After a lot of tests I found the exact dependency causing the problem:
"com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8"
Without it the project works but I need the dependency.
What causes this?
How can I repair the artifact?
My gradle file:
plugins {
id "application"
id "java"
id "war"
id "org.jetbrains.kotlin.jvm" version "1.5.0"
}
group 'hu.qlmdc.drp'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
maven { url 'http://repo.jenkins-ci.org/releases/' }
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.5.0'
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.5.0', ext: 'pom'
implementation "io.ktor:ktor-server-core:1.5.4"
implementation "io.ktor:ktor-server-netty:1.5.4"
implementation "io.ktor:ktor-metrics:1.5.4"
implementation "io.ktor:ktor-locations:1.5.4"
implementation "io.ktor:ktor-gson:1.5.4"
implementation "io.ktor:ktor-client-core:1.5.4"
implementation "io.ktor:ktor-client-apache:1.5.4"
implementation "ch.qos.logback:logback-classic:1.2.3"
//implementation 'mysql:mysql-connector-java:8.0.23'
implementation "com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8"
implementation "org.hibernate:hibernate-core:5.4.31.Final"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "org.apache.httpcomponents:fluent-hc:4.5.13"
// Jenkins plugins
implementation group: 'org.jenkins-ci.plugins', name: 'credentials', version: '2.3.15', ext: 'jar'
implementation group: 'org.jenkins-ci.plugins', name: 'matrix-auth', version: '2.6.6', ext: 'jar'
implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.90', ext: 'jar'
implementation fileTree(dir: 'lib', include: ['*.jar'])
}
Non bundled plugins are stored in the repository and can be referenced by groupId:artifactId:versionId but the documentation only says this ambiguous thing about declaring dependencies on bundled plugins:
locate the plugin’s main JAR file containing META-INF/plugin.xml
descriptor with tag (or if not specified).
Okay. Locate it and do what exactly?
My solution was to copy the template for a gradle IntelliJ plugin and copy this example which led me to declare the dependency by plugin name with no version, groupId. In my case I wanted to use classes from the built-in maven plugin so I added this to the plugins = [....]. The plugin will automatically grab the version of that plugin that is in your IntelliJ.
build.gradle
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.26'
}
group 'com.whatever'
version '1.0-SNAPSHOT'
id 'MyPlugin'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime files('maven.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.2'
plugins = ['maven']
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
After I added copyBootstrap to build.gradle I am getting the next error when try to run the build task:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project '.
Cannot change dependencies of configuration ':providedCompile' after it has been included in dependency resolution.
How could this issue be solved? I have searched on Internet but no solutions were found. I got the copyBootstrap task from this link. Their goal is to extract all content from org.webjars group jars to a specific path.
I am using Gradle 3.2 and Intellij IDEA 2016.2.5
//group 'org'
//version '1.0-SNAPSHOT'
task wrapper(type: Wrapper) {
gradleVersion = '3.2'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.4.0'
}
}
repositories {
mavenCentral()
jcenter()
}
//apply plugin: 'java'
//apply plugin: 'eclipse-wtp'
//apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
//compile group: 'org.akhikhl.gretty', name: 'gretty', version: '1.4.0'
// ********************************************************************************************************
// SPRING FRAMEWORK, ORM Y H2DB
// ********************************************************************************************************
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.4.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.3.Final'
// ********************************************************************************************************
// JACKSON DATABIND
// ********************************************************************************************************
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.4'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4'
// ********************************************************************************************************
// THYMELEAF
// ********************************************************************************************************
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.2.RELEASE'
// ********************************************************************************************************
// SERVLET
// ********************************************************************************************************
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
// ********************************************************************************************************
// MYSQL CONNECTOR
// ********************************************************************************************************
//compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5' issues with time zone
compile 'mysql:mysql-connector-java:5.1.6'
// ********************************************************************************************************
// WEB RESOURCES
// ********************************************************************************************************
compile group: 'org.webjars', name: 'angularjs', version: '1.5.8'
compile group: 'org.webjars', name: 'jquery', version: '2.1.4'
compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
compile group: 'org.webjars', name: 'jquery-ui', version: '1.12.1'
compile group: 'org.webjars', name: 'modernizr', version: '2.8.3'
// ********************************************************************************************************
// JUNIT AND SPRING TEST
// ********************************************************************************************************
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.4.RELEASE'
// ********************************************************************************************************
// GOOGLE DRIVE API
// ********************************************************************************************************
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v2-rev245-1.22.0'
compile group: 'com.google.api-client', name: 'google-api-client-java6', version: '1.22.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'
// ********************************************************************************************************
// DROPBOX API
// ********************************************************************************************************
compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '1.8.2'
// ********************************************************************************************************
// TWITTER API
// ********************************************************************************************************
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.5'
// compile group: 'org.slf4j', name: 'slf4j-mylearn.api', version: '1.7.21'
// compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
// compile files("twitter/main/webapp/") // add this path as a classpath
}
task copyBootstrap(type: Copy) {
into "$buildDir/static_resources"
configurations.compile
.files({ it.group.equals("org.webjars")})
.each {
from zipTree(it)
}
}
//build.dependsOn(copyBootstrap)
task copyToLib2(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}
war {
archiveName = 'ROOT.war'
destinationDir = file('webapps')
}
// ********************************************************************************************************
// GRETTY SETTINGS
// ********************************************************************************************************
/* Change context path (base url). otherwise defaults to name of project */
gretty {
port = 8081
contextPath = ''
}
This problem seems to be related to the org.akhikhl.gretty plugin you are trying to use. If I try to build a project using the above gradle file I get the following output:
C:\ws\PLAYGROUND\test123>gradle wrapper --stacktrace
Changed dependencies of configuration ':providedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is cheduled to be removed in Gradle 3.0.
Changed dependencies of parent of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of configuration ':grettyProvidedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0.
⋮
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'test123'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:74)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
⋮
Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of configuration ':compile' after it has been resolved.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:578)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$2.run(DefaultConfiguration.java:137)
⋮
at org.akhikhl.gretty.GrettyPlugin$_addDependencies_closure11.doCall(GrettyPlugin.groovy:130)
⋮
That is the gretty plugin seems to use functionality that has been removed with gradle 3.0
There is issue #306 that has been reported a short time ago which describes pretty much your problem.
Given the number of open issues for such a small project and the lack of activity on the issues, I don't think this plugin is much of a help and you will probably be better off using something different.
I got a gradle script that should run the testng xml files from command line. But whenever I try to run is with grald test I get the following output. With no test run even no browser opened
C:\Users\Steve\Documents\Projects\automation>gradle test
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
BUILD SUCCESSFUL
My gradle script is the following
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
group = 'automation'
version = '1.1-SNAPSHOT'
description = ""
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:'2.52.0'
compile group: 'org.uncommons', name: 'reportng', version:'1.1.4'
compile group: 'org.apache.velocity', name: 'velocity', version:'1.7'
compile group: 'com.google.inject', name: 'guice', version:'4.0'
testCompile group: 'junit', name: 'junit', version:'3.8.1'
testCompile group: 'org.testng', name: 'testng', version:'6.9.4'
}
test{
useTestNG{
include '/src/test/resources/BasicTestXML/**'}
}
include is used to include (or not) test classes:
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
What you are looking for is
suites.
See an example from the TestNG build file.
Found the solution how to run them and choose which to run
test{
useTestNG() {
suites "src/test/resources/BasicTestXML/LoginTest.xml"
}
}
In this way you can choose which xml file it will run. If you want an extra to run just add an extra suites line.