简体   繁体   English

我在线程“main”org.testng.TestNGException 中收到错误异常:运行测试时无法从文件加载 class

[英]I am getting error Exception in thread "main" org.testng.TestNGException: Cannot load class from file while running a test

This is my testNG file for my project这是我的项目的 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>

my test case file我的测试用例文件

 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");
        }

}

Error logs错误日志

[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)

I installed testNG plugin and testng dependency in my pom file.我在我的 pom 文件中安装了 testNG 插件和 testng 依赖项。 I don't know what is reason behind this error.我不知道这个错误背后的原因是什么。 Please let me know what is possible solution to resolve this issue.请让我知道解决此问题的可能解决方案。 I already reinstall testNG plugin and already done with run, build, clean project我已经重新安装了 testNG 插件并且已经完成了运行、构建、清理项目

pom.xml file 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>

There are a couple of things you need to do.您需要做几件事。

  • Remove the scope parameter from the pom.xml file for all the dependencies从 pom.xml 文件中删除所有依赖项的 scope 参数
  • Try replacing the testng.xml file with the below format and add your classes there,尝试用以下格式替换 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TestNG 异常 - org.testng.TestNGException:在类路径中找不到类: - TestNG Exception - org.testng.TestNGException: Cannot find class in classpath: Getting org.testng.TestNGException: Cannot find class in classpath: error in eclipse during running my program through testng.xml - Getting org.testng.TestNGException: Cannot find class in classpath: error in eclipse during running my program through testng.xml org.testng.TestNGException:无法实例化 class test.AddCustomerTest - org.testng.TestNGException: Cannot instantiate class test.AddCustomerTest org.testng.TestNGException:无法实例化类 - org.testng.TestNGException: Cannot instantiate class org.testng.TestNGException:无法实例化类 - org.testng.TestNGException : Cannot instantiate class 错误:org.testng.TestNGException:在类路径中找不到类:EmpClass - Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass org.testng.TestNGException:实例化类时发生错误 - org.testng.TestNGException: An error occurred while instantiating class org.testng.TestNGException:无法实例化黄瓜测试运行器 - org.testng.TestNGException: Cannot instantiate cucumber test runner org.testng.TestNGException:无法实例化com.Testform类 - org.testng.TestNGException: Cannot instantiate class com.Testform org.testng.TestNGException在类路径中找不到类 - org.testng.TestNGException Cannot find class in classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM