简体   繁体   English

使用 TestNG 时出错

[英]Getting error on using TestNG

When running a java selendroid code with testNG, getting an error message, "A Java Exception has occurred."使用 testNG 运行 java selendroid 代码时,收到错误消息“发生 Java 异常”。 with below exception -除了以下例外 -

Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNGException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.privateGetMethodRecursive(Class.java:3035)
at java.lang.Class.getMethod0(Class.java:3005)
at java.lang.Class.getMethod(Class.java:1771)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.testng.TestNGException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

Below is the selendroid java code -下面是 selendroid java 代码 -

    package com.selendroid.demo;

import org.openqa.selenium.WebDriver;

import io.selendroid.SelendroidDriver;
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.common.device.DeviceTargetPlatform;
import io.selendroid.standalone.SelendroidConfiguration;
import io.selendroid.standalone.SelendroidLauncher;

public class Sele {

    private WebDriver driver;

    public void setUp() throws Exception {

        System.out.println("------------------------Started");

        SelendroidConfiguration config = new SelendroidConfiguration();

        // Add the selendroid-test-app to the standalone server
        config.addSupportedApp("Demo.apk");

        // start the standalone server
        SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
        selendroidServer.launchSelendroid();

        // Create the selendroid capabilities
        SelendroidCapabilities capa = new SelendroidCapabilities(
                "io.selendroid.androiddriver:0.16.0");

        capa.setAut("com.example.demo:1.0");
        capa.setPlatformVersion(DeviceTargetPlatform.ANDROID15);
        // capa.setEmulator(false);
        // capa.setCapability(SelendroidCapabilities.EMULATOR, true);
        // capa.setSerial("emulator-5554");
        SelendroidDriver driver = new SelendroidDriver(capa);

        capa.wait(100);
        driver = new SelendroidDriver(capa);



    }

    }

Not familiar with testng and selendroid so please give the solution in detail.不熟悉testng和selendroid所以请详细给出解决方案。

It seems you don't have the testng jar in your classpath.您的类路径中似乎没有 testng jar。 Just add it.只需添加它。

I had the same problem and I found that the root cause was that in the POM file the scoop was "compile" to the Dependency of TestNG.我遇到了同样的问题,我发现根本原因是在 POM 文件中,勺子被“编译”到了 TestNG 的依赖关系。 All I had to do was erase the scoop setting for the TestNG dependency.我所要做的就是清除 TestNG 依赖项的 scoop 设置。

It is cause to the exception from the Eclipse TestNG plugin because the plugin do not has the TestNG jar in the classpath when it is running (it's running after the compilation phase)这是 Eclipse TestNG 插件异常的原因,因为该插件在运行时的类路径中没有 TestNG jar(它在编译阶段之后运行)

Before:之前:

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.11</version>
  <scope>compile</scope>
</dependency>

After:之后:

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

My testng jar was on classpath and testng plugin was also installed for eclipse.我的 testng jar 在类路径上,并且还为 Eclipse 安装了 testng 插件。 Converting my project to Maven project in eclipse solved the issue.在 Eclipse 中将我的项目转换为 Maven 项目解决了这个问题。

You can also write dependencies like:-您还可以编写依赖项,例如:-

<dependency>
    <groupId> org.testng </groupId>
    <artifactId> testng </artifactId>
    <version> 7.3.0 </version>
    <scope>test</scope>
</dependency>

暂无
暂无

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

相关问题 使用Testng运行硒代码时获取NullPointerException错误消息 - Getting NullPointerException error message while running the selenium code using testng 使用POI和TestNG ..code的Selenium中的数据驱动测试出错 - Data driven testing in Selenium using POI and TestNG ..code getting error 在Azuredevops上使用testNG(使用Maven)套件,在运行管道时,在testNG批注中出现“找不到符号”错误。 在本地运作良好 - testNG(using Maven)suite on azuredevops,getting “can not find symbol” error at testNG annotations when I ran the Pipeline. working well on local 获取 java.lang.ClassNotFoundException: org.testng.TestNG 错误 - Getting a java.lang.ClassNotFoundException: org.testng.TestNG Error TestNG 错误:无法运行 TestNG,获取未定义变量surefireArgLine 的引用? - TestNG Error: Not able to run TestNG ,getting Reference to undefined variable surefireArgLine? 导入Maven项目后出现TestNG错误 - Getting TestNG error after import Maven project 我收到有关在用testng构建时甚至没有使用的软件包的错误消息 - I'm getting an error message about packages that I'm not even using upon building with testng 在 testng 中使用 @DataProvider 进行数据驱动测试时出现错误 java.lang.NullPointerException - getting error java.lang.NullPointerException in data driven testing using @DataProvider in testng 使用 testNG 框架在数据提供程序中获取异常 - Getting exception in dataprovider using testNG framework 获取和使用 TestNG @test 注解参数 - getting and using TestNG @test annotation parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM