简体   繁体   中英

Selecting the right dependencies for Selenium on Gradle

I am very very new to programming andI have created some short test cases in Selenium and need to commit them to the repository for someone else to pull and test. Im looking for a way to be able to push this project and its jars, so that the person who opens it will already have the jars imported and my code wont throw a bunch of errors.

在此处输入图片说明

These are the jars i have to manually import in order or my tests to run.

I also tried creating a gradle project (Would that solve my problem?). Is "compile group: 'org.seleniumhq.selenium', name: 'selenium-java',version: '3.141.59'" all i need to mention?

This is where i have listed my dependencies on the build.gradle file

plugins {
    id 'java'
}

group 'org.Programming'

version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {

    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
    compile group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0'
    testCompile group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0'
    testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
}

But then the problem is that i cant run my tests for some reason. 在此处输入图片说明

I am really interested to learn more about how to organise my project dependencies better for git. Please help!

You have not use Java JRE location as I can see Java package is not appearing under external library. For Other jars which you import manually Create an Aritifactory in https://jfrog.com/artifactory/start-free/ .

Use below code in build.gradle

buildscript {
    repositories {
        maven {
            url 'YourArtifactoryURL'
            credentials {
                username = "YourUserName"
                password = 'YourPassword'
            }
        }

    }
    dependencies {
        //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
    }
}

allprojects {
    apply plugin: "com.jfrog.artifactory"
}

group = 'FolderStrucinArtifactoryeg. com.test.in'
def ver = System.getProperty("jar.version")
version = "$ver"

apply plugin: 'java-library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'



def artifactory_password = 'YourArtifactoryPassword'
def artifactory_user = "yourArtifactoryusername"
def artifactory_contextUrl = "YourArtifactoryURL"

configurations.all {
    // Check for snapshot updates every build
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
jar {from sourceSets.test.output}

task testJar(type: Jar) {
//    classifier = 'tests'
    from sourceSets.test.output

    from('src/test/java') {
        include '/**/*.json'
    }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from tasks.javadoc.destinationDir
}

task sourcesJar(type: Jar) {
    from sourceSets.test.allSource
    classifier = 'sources'
}


artifacts {
    archives testJar
    archives javadocJar
    //archives sourcesJar
}


repositories {

    repositories {
        maven {
            url "ArtifactoryUrLwith1stRepokey"
        }
        maven {
            url "ArtifactoryUrLwith2ndRepokey"
        }

    }
}



dependencies {
    #enter your dependencies here
}





    artifactory {
        contextUrl = "${artifactory_contextUrl}"
        //The base Artifactory URL if not overridden by the publisher/resolver
        publish {
            repository {
                repoKey = 'YourRepokeyinArtifactory'
                username = "${artifactory_user}"
                password = "${artifactory_password}"
                mavenCompatible = true

            }
            defaults {
                publications('mavenJava')
                publishBuildInfo = true
                publishArtifacts = true
                publishPom = true
            }


        }
        resolve {
            repository {
                repoKey = 'yourrepositoryfolderinartifactory'
                username = "${artifactory_user}"
                password = "${artifactory_password}"
                maven = true

            }
        }
    }
    publishing {
        publications {
            mavenJava(MavenPublication) {
                groupId = "$group"
                artifactId = "$rootProject.name"
                version = "${ver}"
                from components.java
                artifact jar
                artifact javadocJar
                artifact sourcesJar
            }
        }
    }

Enter below command to publish your build in artifactory
gradlew clean build -Djar.version=1.0.0

gradlew artifactoryPublish -Djar.version =1.0.0

it will publish your jars in artifactory and other person just have to do gradle refresh to get the jars .

You may create a pipeline to deploy the jar whenever you push to github.

Then in your Code like as usual you can use the import statement to use the jars and your Test should run fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM