如何使用gradle配置selenium测试?

如何使用gradle配置selenium测试?,selenium,gradle,Selenium,Gradle,我想在jboss上使用gradle运行selenium测试,我能够进行所需的配置,我想与社区共享它。解决方案如下: gradle.build: apply plugin: 'java' apply plugin: 'eclipse-wtp' apply plugin: 'war' apply plugin: 'findbugs' //apply from:'http://github.com/breskeby/gradleplugins/raw/master/emmaPlugin/emma.gr

我想在jboss上使用gradle运行selenium测试,我能够进行所需的配置,我想与社区共享它。

解决方案如下:

gradle.build:

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
apply plugin: 'findbugs'
//apply from:'http://github.com/breskeby/gradleplugins/raw/master/emmaPlugin/emma.gradle'
apply from: 'emma.gradle'
buildDir = 'build'

sourceCompatibility = 1.7
version = ''

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6'
    }
}

repositories {
    mavenCentral()
    mavenRepo url: 'http://repository.primefaces.org'
    mavenRepo url: 'http://repository.jboss.org/nexus/content/groups/public'
    mavenRepo url: 'http://repository.jboss.org/maven2'
    mavenRepo url: 'http://maven.springframework.org/release'
    mavenRepo url: 'http://repo1.maven.org/maven2'
    mavenRepo url: 'http://git.solutionstream.com/nexus/content/repositories/thirdparty'
}


configurations {
   compileOnly
   weldEmbeddedTestRuntime { extendsFrom testRuntime }
   jbossasRemoteTestRuntime { extendsFrom testRuntime, compileOnly }
}

sourceSets {

   main {
      compileClasspath = configurations.compile + configurations.compileOnly
   }

   test {
      compileClasspath = compileClasspath + configurations.compileOnly
   }

   selenium {
      compileClasspath = compileClasspath + configurations.compileOnly
   }
}

dependencies {
    //JSF
    compile group: 'com.sun.faces', name: 'jsf-api', version: '2.1.22'
    compile group: 'com.sun.faces', name: 'jsf-impl', version: '2.1.22'
    compile 'org.ocpsoft.rewrite:rewrite-servlet:2.0.3.Final'
    compile 'org.ocpsoft.rewrite:rewrite-config-prettyfaces:2.0.3.Final'


    //Servlet
    compile group: 'javax.servlet', name: 'jstl', version: '1.2'
    providedCompile group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: '1.0.0.Final'
    compile 'taglibs:standard:1.1.2'
    compile group: 'org.springframework', name: 'spring-web', version: '3.2.2.RELEASE'

    //Omnifaces
    compile 'org.omnifaces:omnifaces:1.5'

    //Prime Faces
    compile group: 'org.primefaces', name: 'primefaces', version: '4.0-SNAPSHOT'
    compile 'org.primefaces.themes:bootstrap:1.0.10'

    // DB
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.3.1.RELEASE'
    compile group: 'org.springframework', name: 'spring-aspects', version: '3.2.2.RELEASE'
    compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.9'

    compile group: 'javax.inject', name: 'javax.inject', version: '1'
    compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-SP4'
    compile 'cglib:cglib-nodep:2.2.2'

    //Hibernate / JPA   
    compile 'org.hibernate:hibernate-core:4.1.0.Final'
    compile 'org.hibernate:hibernate-entitymanager:4.1.0.Final'
    compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
    //JSR-303
    compile 'org.hibernate:hibernate-validator:4.3.1.Final'

    // Spring Security
    compile 'org.springframework.security:spring-security-core:3.1.4.RELEASE'
    compile 'org.springframework.security:spring-security-web:3.1.4.RELEASE'
    compile 'org.springframework.security:spring-security-config:3.1.4.RELEASE'

    //Utility
    compile 'com.google.guava:guava:14.0.1'
    compile 'commons-lang:commons-lang:2.6'
    compile 'org.apache.commons:commons-email:1.3.1'
    compile 'com.typesafe:config:1.0.0'
    compile 'joda-time:joda-time:2.2'
    compile 'org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.3'
    compile 'org.slf4j:slf4j-api:1.7.2'
    compile 'org.slf4j:jcl-over-slf4j:1.7.2'
    compile 'org.slf4j:slf4j-log4j12:1.7.2'


    //Mustache Templates
    compile 'com.github.jknack:handlebars:1.0.0'

    //Projects
    //compile project(":ExtraValidators")

    ////TESTING DEPENDENCIES
    testCompile 'com.googlecode.jmockit:jmockit:1.2'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile 'com.h2database:h2:1.3.172'

    //Spring Testing
    testCompile 'org.springframework:spring-test:3.2.3.RELEASE'

    /* Selenium */
    seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.33.0'
    seleniumCompile 'junit:junit:4.11'
    seleniumCompile 'org.slf4j:slf4j-api:1.7.2'
    seleniumCompile 'org.slf4j:slf4j-log4j12:1.7.2'
    seleniumCompile 'org.slf4j:jcl-over-slf4j:1.7.2'

    /* Remote Jboss */
    testCompile group: 'org.jboss.arquillian', name: 'arquillian-junit', version: '1.0.0-SNAPSHOT'   
    jbossasRemoteTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-jbossas-remote-6', version: '1.0.0-SNAPSHOT'
    jbossasRemoteTestRuntime group: 'org.jboss.jbossas', name: 'jboss-as-server', classifier: 'client', version: '6.1.0.Final', transitive: false
    jbossasRemoteTestRuntime group: 'org.jboss.jbossas', name: 'jboss-as-profileservice', classifier: 'client', version: '6.1.0.Final'
}


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

eclipse {
    classpath {
       downloadSources=true
       plusConfigurations += configurations.seleniumCompile
    }
}


task selenium(type: Test) {
   testClassesDir = sourceSets.selenium.output.classesDir
   classpath = sourceSets.selenium.runtimeClasspath  + files('src/selenium/resources-jbossas') + configurations.jbossasRemoteTestRuntime
}
您需要手动启动jboss服务器,然后使用命令gradlew clean selenium

I make t

我的依赖项(仅使用mavenCentral repo)是:

dependencies {
    compile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
    compile group: 'commons-io', name: 'commons-io', version: '1.3.+'
    compile group: 'junit', name: 'junit', version: '4.+'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
    compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.+'
}

我会将JBoss7作为服务(在windows上)运行,而不是直接从Gradle执行它。如果你想用的话我就写了。然后,您只需执行一个gradle任务来执行带有“start”参数的脚本来启动服务。

将此列表复制到gradle.build,以便使用appium、testng和selenium进行移动测试

// https://mvnrepository.com/artifact/cglib/cglib-nodep
compile 'cglib:cglib-nodep:3.2.6'

// https://mvnrepository.com/artifact/commons-codec/commons-codec
compile 'commons-codec:commons-codec:1.10'

// https://mvnrepository.com/artifact/org.apache.commons/commons-exec
compile 'org.apache.commons:commons-exec:1.3'

// https://mvnrepository.com/artifact/commons-io/commons-io
compile 'commons-io:commons-io:2.6'

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile 'org.apache.commons:commons-lang3:3.7'

// https://mvnrepository.com/artifact/commons-logging/commons-logging
compile 'commons-logging:commons-logging:1.2'

// https://mvnrepository.com/artifact/net.sourceforge.cssparser/cssparser
compile 'net.sourceforge.cssparser:cssparser:0.9.24'

// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile 'com.google.code.gson:gson:2.8.2'

// https://mvnrepository.com/artifact/com.google.guava/guava
compile 'com.google.guava:guava:23.0'

// https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all
compile 'org.hamcrest:hamcrest-all:1.3'

// https://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit
compile 'net.sourceforge.htmlunit:htmlunit:2.29'

// https://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit-core-js
compile 'net.sourceforge.htmlunit:htmlunit-core-js:2.28'

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/htmlunit-driver
compile 'org.seleniumhq.selenium:htmlunit-driver:2.29.2'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compile 'org.apache.httpcomponents:httpclient:4.5.4'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
compile 'org.apache.httpcomponents:httpcore:4.4.7'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime
compile 'org.apache.httpcomponents:httpmime:4.5.4'

// https://mvnrepository.com/artifact/io.appium/java-client
compile 'io.appium:java-client:5.0.3'

// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile 'javax.servlet:javax.servlet-api:3.1.0'

// https://mvnrepository.com/artifact/com.beust/jcommander
compile 'com.beust:jcommander:1.72'

// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-client
compile 'org.eclipse.jetty:jetty-client:9.4.8.v20171121'

// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-http
compile 'org.eclipse.jetty:jetty-http:9.4.8.v20171121'

// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-io
compile 'org.eclipse.jetty:jetty-io:9.4.8.v20171121'

// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util
compile 'org.eclipse.jetty:jetty-util:9.4.8.v20171121'

// https://mvnrepository.com/artifact/net.java.dev.jna/jna
compile 'net.java.dev.jna:jna:4.1.0'

// https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform
compile 'net.java.dev.jna:jna-platform:4.1.0'

// https://mvnrepository.com/artifact/junit/junit
compile 'junit:junit:4.12'

// https://mvnrepository.com/artifact/net.sourceforge.htmlunit/neko-htmlunit
compile 'net.sourceforge.htmlunit:neko-htmlunit:2.28'

// https://mvnrepository.com/artifact/com.codeborne/phantomjsdriver
compile 'com.codeborne:phantomjsdriver:1.4.0'

// https://mvnrepository.com/artifact/org.w3c.css/sac
compile 'org.w3c.css:sac:1.3'

// https://mvnrepository.com/artifact/xalan/serializer
compile 'xalan:serializer:2.7.2'

// https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-api
compile 'org.eclipse.jetty.websocket:websocket-api:9.4.8.v20171121'

// https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-client
compile 'org.eclipse.jetty.websocket:websocket-client:9.4.8.v20171121'

// https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-common
compile 'org.eclipse.jetty.websocket:websocket-common:9.4.8.v20171121'

// https://mvnrepository.com/artifact/xalan/xalan
compile 'xalan:xalan:2.7.2'

// https://mvnrepository.com/artifact/xerces/xercesImpl
compile 'xerces:xercesImpl:2.11.0'

// https://mvnrepository.com/artifact/xml-apis/xml-apis
compile 'xml-apis:xml-apis:2.0.2'

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile 'org.seleniumhq.selenium:selenium-java:3.10.0'

// https://mvnrepository.com/artifact/commons-validator/commons-validator
compile 'commons-validator:commons-validator:1.6'

// https://mvnrepository.com/artifact/org.testng/testng
compile 'org.testng:testng:6.11'

// https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'

当JaCoCo内置于gradle时,为什么要使用emma?