selenium-webdriver - 如何在 Eclipse 中执行 TestNG 项目的 jar 文件
问题描述
我可以通过运行 testng.xml 文件在 Eclipse 中运行 TestNg 项目。构建 Maven 项目后,我尝试使用命令 java -jar jarname 在终端中运行 jar 文件。但它显示错误“没有主要清单属性”。所以我创建了一个运行器类并尝试通过运行为 -> Java 应用程序来运行该类。但它抛出一个错误“在类路径中找不到类”我的代码如下。
pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MockTest</groupId>
<artifactId>MockFrameTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
testng.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener class-name="com.reportListners.testListner"/>
</listeners>
<test name="Test">
<classes>
<class name="com.tests.Login"/>
<class name="com.tests.Home"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
亚军.java
package runner;
import java.util.ArrayList;
import java.util.List;
import org.testng.TestNG;
public class TestNGrunner {
public static void main(String[] args) {
TestNG runner=new TestNG();
// Create a list of String
List<String> suitefiles=new ArrayList<String>();
// Add xml file which you have to execute
suitefiles.add(".//testng.xml");
// now set xml file for execution
runner.setTestSuites(suitefiles);
// finally execute the runner using run method
runner.run();
}
}
那么如何使用 Jar 文件运行这个 TestNG 项目。谁能帮我?
解决方案
推荐阅读
- python - 如何去除背景周围的白框?
- django - 如何将过滤器后端添加到基于功能的视图?
- angular - 带有输出兑现标志的 Angular 构建生成相同的哈希
- python - 用于计算两者之间差异的平方的 Python 代码
- eclipse - 当我从 Eclipse 运行我的 MonkeyC 程序时,为什么我的代码更改没有编译或显示?
- logging - 处理重写规则后的 Haproxy 记录最终路径
- c++ - Qt 如何枚举屏幕?
- kubernetes - 如何更改 OpenShift 控制台 URL 和 API URL
- python - 使用 Python 提取包含给定单词的标签之间的文本
- javascript - 如何使用时刻获取相同日期的数据?