gpt4 book ai didi

java - 我在线程 "main"org.testng.TestNGException : Cannot load class from file while running a test 中收到错误 Exception

转载 作者:行者123 更新时间:2023-12-01 16:30:30 34 4
gpt4 key购买 nike

这是我的项目的 testNG 文件

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mobile-automation-framework">
<parameter name="os" value="android" />

<listeners>
<listener class-name="UITestFramework.retryLogic.RetryListener" />
<listener class-name="UITestFramework.retryLogic.TestListener" />
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>

<test name="LoginTest">
<classes>
<class name="tests.testngTests.e2e_Tests"/>
</classes>
</test>
</suite>

我的测试用例文件

 package tests.testngTests;

import org.testng.annotations.*;
import IntegrationTests.coreLogic.base.*;
import IntegrationTests.coreLogic.android.*;
import UITestFramework.CreateSession;

/**
* automated test to verify login to android/iOS app.
*/
public class e2e_Tests extends CreateSession {

LoginCoreLogic loginCoreLogic;
/**
* this method instantiate required helpers depending on the platform(android or iOS)
*
* @param invokeDriver android or iOS
*/
@Parameters({"os"})
@BeforeClass
public void instantiateHelpers(@Optional("android") String invokeDriver) {
//Load Test Data


if (invokeDriver.equalsIgnoreCase("android")) {
loginCoreLogic = new AndroidLoginHelper(driver);

} else if (invokeDriver.equalsIgnoreCase("iOS")) {
//loginCoreLogic = new IOSLoginCoreLogic(driver);
}
}

/**
* method to verify login to android and iOS app
*
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either
before
* or during the activity.
*/
@Test(priority = 0)
public void VerifyForgotPassword() throws InterruptedException {
System.out.println("inside test 1");
}

}

错误日志

[RemoteTestNG] detected TestNG version 7.0.1
Exception in thread "main" org.testng.TestNGException:
Cannot load class from file:
at org.testng.internal.ClassHelper.fileToClass(ClassHelper.java:340)
at org.testng.TestNG.configure(TestNG.java:1422)
at org.testng.remote.AbstractRemoteTestNG.configure(AbstractRemoteTestNG.java:75)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:235)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

我在我的 pom 文件中安装了 testNG 插件和 testng 依赖项。我不知道这个错误背后的原因是什么。请让我知道解决此问题的可能解决方案。我已经重新安装了 testNG 插件,并且已经完成了运行、构建、清理项目

pom.xml 文件

    <?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github</groupId>
<artifactId>mobile-automation-framework</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MobileAutomationFramework</name>
<url>http://maven.apache.org</url>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
<suiteXmlFiles>
<suiteXmlFile>"testng.xml"</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<suiteXmlFiles>-->
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!--<systemPropertyVariables>
<property>
<invokeDriver>${invokeDriver}</invokeDriver>
</property>
</systemPropertyVariables>-->
</configuration>
</plugin>

</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
<type>maven-plugin</type>
</dependency>

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-configuration2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.1.1</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.saucelabs/sauce_java_common -->
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_java_common</artifactId>
<version>2.1.23</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.saucelabs/sauce_testng -->
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_testng</artifactId>
<version>2.1.23</version>
</dependency>


<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>


<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>


<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

最佳答案

您需要做几件事。

  • 从所有依赖项的 pom.xml 文件中删除范围参数
  • 尝试使用以下格式替换 testng.xml 文件并在其中添加您的类,

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Test Automation" parallel="tests">
<listeners>
<listener class-name=""/>
</listeners>
<test thread-count="5" name="Test Cases">
<classes>
<class name="com.package.yourclassname"/>
</classes>
</test>
</suite>

关于java - 我在线程 "main"org.testng.TestNGException : Cannot load class from file while running a test 中收到错误 Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62051370/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com