【发布时间】:2020-05-26 22:50:40
【问题描述】:
我正在尝试创建一个可执行 jar 来启动我的硒化物测试。
TestClass
public class TestClass {
@Test
public void openBrowser(){
System.setProperty("webdriver.chrome.driver", "chrome location");
open("google.com");
}
}
测试执行器
public class TestExecutor {
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { TestClass.class });
testng.addListener((ITestNGListener) tla);
testng.run();
}
}
build.gradle
plugins {
id 'java'
}
repositories {
maven {
url = 'jfrog artifactory url'
}
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task testJar(type: ShadowJar) {
manifest {
attributes 'Implementation-Title': 'Gradle',
'Implementation-Version': project.version,
'Main-Class': 'TestExecutor'
}
from sourceSets.test.output
configurations = [project.configurations.testRuntime]
}
test {
useJUnitPlatform()
}
dependencies {
testCompile 'org.seleniumhq.selenium:selenium-java:3.141.59'
testCompile 'org.apache.poi:poi:4.1.0'
testCompile 'org.apache.poi:poi-ooxml:4.1.0'
testCompile 'org.slf4j:slf4j-simple:1.7.5'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.5.2'
testCompile group: 'com.codeborne', name: 'selenide', version: '5.1.0'
testCompile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.2'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
compile group: 'org.testng', name: 'testng', version: '6.14.3'
}
group 'groupId'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
在构建 jar 时找不到测试依赖项。
我已经尝试像这样将 testRuntimeClasspath 添加到 jar 中
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
configurations.testRuntimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
但随后我收到一条错误消息,提示 无法找到或加载主类
我已经尝试让它运行 2 个多星期了。我不知道我真正需要做什么,因为这一切对我来说都是新的。发送帮助。
【问题讨论】:
标签: java gradle testng selenide