selenium - 无法使用gradle build命令运行testng xml

标签 selenium gradle testng build.gradle

我已经创建了gradle项目并在eClipse中配置了testng。我创建了一个示例testng脚本,当我通过eClipse运行testng.xml时,该脚本已成功执行。
但是,当我从命令提示符处执行gradle build / test etc命令时,我的testng.xml没有得到执行。

我没有遇到任何错误,但是无法使用gradle命令运行testng.xml。

你能帮我这个忙吗?下面是我正在使用的build.gradle。

apply plugin: "java"
apply plugin: "maven"

group = "myorg"
version = 1.0
def poiVersion = "3.10.1"

repositories {
   maven {
            url "rep_url"
        }
}

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'

    testCompile 'junit:junit:4.9'
    testCompile sourceSets.api.output
    testCompile sourceSets.impl.output
    testCompile group: 'org.testng', name: 'testng', version: '6.9.5'
    runtime configurations.apiRuntime
    runtime configurations.implRuntime
    compile('org.seleniumhq.selenium:selenium-java:2.47.1') {
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-htmlunit-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-android-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-iphone-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-safari-driver'
        exclude group: 'org.webbitserver', module: 'webbit'
        exclude group: 'commons-codec', module: 'commons-codec'
        exclude group: 'cglib', module: 'cglib-nodep'
        }
    compile "org.apache.poi:poi:${poiVersion}"
    compile "org.apache.poi:poi-ooxml:${poiVersion}"
    compile "org.apache.poi:ooxml-schemas:1.1"  
}

tasks.withType(Test) {
    scanForTestClasses = false
    include "**/*.xml" // whatever Ant pattern matches your test class files
}

jar {
    from sourceSets.api.output
    from sourceSets.impl.output
}

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
                    }
                }
            }

        }
    }
}

在此先感谢您的帮助。

最佳答案

我可以通过在build.gradle中添加以下代码来实现。

test {
    useTestNG() {
        // runlist to executed. path is relative to current folder
        suites 'src/test/resources/runlist/Sanity.xml'
    }
 } 

谢谢!

关于selenium - 无法使用gradle build命令运行testng xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32432876/

相关文章:

java - 如何使用命令行更改属性文件中的浏览器值来运行 selenium 测试用例

python - 使用 Selenium 登录

java - Log4j2 + MongoDb不起作用

gradle - 使用 Gradle Shadow 插件时如何仅包含项目和重定位类?

xml - 如何为 Maven 项目批量运行 testng .xml 文件

java - 添加模拟会破坏数据库测试

android - 范围报告问题并行测试

html - 使用 text() 的 XPath 定位元素不起作用

java - 子项目取决于Gradle中的根项目

java - 组织.testng.TestNGException : while trying to execute the tests