简体   繁体   English

当我在Eclipse中运行Maven项目时,org.apache.maven.surefire.util.SurefireReflectionException

[英]org.apache.maven.surefire.util.SurefireReflectionException when i run a maven project in eclipse

this is first time i use Maven in eclipse with selenium. 这是我第一次在食与硒中使用Maven。 So i use the example of Mkyong : http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/ and i replace the AppTest.java by a simple gmail login test. 因此,我使用Mkyong的示例: http ://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/,并通过简单的gmail登录测试替换了AppTest.java。

So my pom.xml is: 所以我的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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mkyong</groupId>
    <artifactId>NumberGenerator</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>NumberGenerator</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

My AppTest.java is: 我的AppTest.java是:

package com.mkyong;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class AppTest {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    //driver = new FirefoxDriver();
    driver = new ChromeDriver();
    baseUrl = "https://accounts.google.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testGmail() throws Exception {
    driver.get("http://www.gmail.com");
    driver.findElement(By.id("Email")).clear();
    driver.findElement(By.id("Email")).sendKeys("emailaddress");
    driver.findElement(By.id("Passwd")).clear();
    driver.findElement(By.id("Passwd")).sendKeys("password");
    driver.findElement(By.id("signIn")).click();
    /*driver.findElement(By.cssSelector("span.gb_4.gbii")).click();
    driver.findElement(By.id("gb_71")).click();*/
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

When i run by right-clicking the project and click on maven-install, i receive the following error as result: 当我通过右键单击项目运行并单击maven-install时,我收到以下错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building NumberGenerator 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ NumberGenerator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Thimo\Downloads\Maven-NumberGenerator\NumberGenerator\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ NumberGenerator ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ NumberGenerator ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Thimo\Downloads\Maven-NumberGenerator\NumberGenerator\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ NumberGenerator ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ NumberGenerator ---
[INFO] Surefire report directory: C:\Users\Thimo\Downloads\Maven-NumberGenerator\NumberGenerator\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/NoSuchElementException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:57)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:64)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:59)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:54)
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:51)
    at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:97)
    at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:194)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:92)
    ... 9 more
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.NoSuchElementException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 22 more

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.215 s
[INFO] Finished at: 2014-11-02T21:42:38-05:00
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project NumberGenerator: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Can anyone please help how to solve this issue, thank you 谁能帮忙解决这个问题,谢谢

while using maven don't mix the eclipse classpath provider, you need to add 在使用Maven时不要混合eclipse classpath提供程序,您需要添加

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-chrome-driver</artifactId>
  <version>LATEST_COMPATIBLE_VERSION</version>
  <scope>test</scope>
</dependency>

to your pom.xml which defines that your project is dependent on this artifact for tests 到pom.xml,它定义您的项目依赖于此工件进行测试

暂无
暂无

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

相关问题 Maven.surefire.util.SurefireReflectionException测试Junit测试时 - Maven.surefire.util.SurefireReflectionException When testing Junit tests 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test on project XYZ - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test on project XYZ eclipse (pom.xml) 中的 Maven 错误:无法传输 org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 - Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 Eclipse问题,无法导入org.apache.maven.surefire.report.RunListener; - Problems with Eclipse, can't import org.apache.maven.surefire.report.RunListener; 如何修复Maven org.apache.maven.surefire.testset.TestSetFailedException: - How to fix maven org.apache.maven.surefire.testset.TestSetFailedException: 未能在项目上执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project 无法在项目上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project 在Eclipse中运行Maven项目 - Run maven project in Eclipse Maven Surefire中的类加载和派生异常(org.apache.maven.surefire.testset.TestSetFailedException:java.lang.NullPointerException) - Classloading and Forking exception in Maven Surefire (org.apache.maven.surefire.testset.TestSetFailedException: java.lang.NullPointerException) 尝试部署到 AZURE 时出错 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test - Error when trying to deploy to AZURE Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM