在类路径文件

时间:2016-02-02 17:41:11

标签: java eclipse maven selenium automation

首先,我要说的是,我已经在尝试解决此问题时进行了相当多的研究。我已经在SO上查看过一堆答案并尝试了很多,但遗憾的是,无济于事。

我当前的堆栈是带有Maven和Selenium的Eclipse(Mars)。在尝试运行自动化测试时,我得到以下内容:

  
    

[INFO]扫描项目... [INFO] [INFO]     -------------------------------------------------- ---------------------- [INFO]楼宇自动化0.0.1-SNAPSHOT [INFO]     -------------------------------------------------- ---------------------- [警告] org.testng:testng:jar:5.14.3的POM无效,     传递依赖(如果有)将不可用,启用调试     记录更多详细信息[警告] POM for     org.testng:testng:jar:5.14.4无效,传递依赖(如果     any)将不可用,启用调试日志记录以获取更多详细信息     [警告] org.testng:testng:jar:5.14.5的POM无效,     传递依赖(如果有)将不可用,启用调试     记录更多细节[信息] [信息] ---     maven-clean-plugin:2.5:clean(default-clean)@ automation --- [INFO]     删除C:\ Users \ bmoore \ workspace \ automation \ target [INFO] [INFO]     --- maven-resources-plugin:2.6:资源(默认资源)@ automation --- [INFO]使用' UTF-8'编码复制过滤     资源。 [INFO]复制7个资源[INFO] [INFO] ---     maven-compiler-plugin:3.3:compile(default-compile)@ automation ---     [INFO]检测到更改 - 重新编译模块! [INFO]编译253     源文件到C:\ Users \ bmoore \ workspace \ automation \ target \ classes     [INFO] [INFO] --- maven-resources-plugin:2.6:testResources     (default-testResources)@ automation --- [INFO]使用' UTF-8'编码     复制过滤后的资源。 [INFO]复制3个资源[INFO] [INFO]     --- maven-compiler-plugin:3.3:testCompile(default-testCompile)@ automation --- [INFO]检测到更改 - 重新编译模块!     [INFO]编译17个源文件     C:\ Users \ bmoore \ workspace \ automation \ target \ test-classes [INFO]

         

[INFO] --- maven-surefire-plugin:2.19:test(default-test)@ automation

  
     

----------------------------------------------- --------测试   -------------------------------------------------- -----运行TestSuite

     

结果:

     

测试运行:0,失败:0,错误:0,跳过:0

     

[INFO]   -------------------------------------------------- ---------------------- [INFO] BUILD FAILURE [INFO]   -------------------------------------------------- ---------------------- [INFO]总时间:9.679 s [INFO]完成于:   2016-02-02T10:26:53-07:00 [信息]最终记忆:23M / 277M [INFO]   -------------------------------------------------- ---------------------- [错误]无法执行目标   org.apache.maven.plugins:Maven的万无一失,插件:2.19:测试   项目自动化的(默认测试):目标的执行默认测试   org.apache.maven.plugins:maven-surefire-plugin:2.19:测试失败:那里   是分叉进程中的错误[错误] org.testng.TestNGException:   [ERROR] [ERROR]在类路径中找不到类:   com..qa.automation.roles.SuperAdminCreateCouponTest [ERROR]   at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)[ERROR] at   org.testng.xml.XmlClass.init(XmlClass.java:73)[ERROR] at   org.testng.xml.XmlClass。(XmlClass.java:59)[ERROR] at   org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:546)   [错误]在   com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)   [错误]在   com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)   [错误]在   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1344)   [错误]在   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)   [错误]在   com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)   [错误]在   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)   [错误]在   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)   [错误]在   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)   [错误]在   com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)   [错误]在   com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)   [错误]在   com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl $ JAXPSAXParser.parse(SAXParserImpl.java:643)   [错误]在   com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)   [错误]在javax.xml.parsers.SAXParser.parse(SAXParser.java:195)   org.testng.xml.XMLParser.parse的[错误](XMLParser.java:38)[错误]   at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)[错误]   at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)[ERROR]   在org.testng.xml.Parser.parse(Parser.java:172)[错误] at   org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:300)[错误]   在org.testng.TestNG.run(TestNG.java:1021)[ERROR] at   org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:282)   [错误]在   org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:83)   [错误]在   org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:114)   [错误]在   org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:286)   [错误]在   org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:240)   [错误]在   org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)   [错误] - > [帮助1] [错误] [错误]查看完整的堆栈跟踪   错误,用-e开关重新运行Maven。 [错误]重新运行Maven   使用-X开关启用完整的调试日志记录。 [ERROR] [ERROR] For   有关错误和可能的解决方案的更多信息,请阅读   以下文章:[错误] [帮助1]   http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

这是发生的事情的完整痕迹。问题(我认为)是以下几行:

  

[错误]无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.19:test(default-test)项目自动化:目标org.apache.maven.plugins的执行默认测试: maven-surefire-plugin:2.19:测试失败:分叉进程出错   [错误] org.testng.TestNGException:   [错误]   [错误]在类路径中找不到类:com..qa.automation.roles.SuperAdminCreateCouponTest

我已经尝试验证类路径条目,并且存在surefire插件。在这两种情况下,它们都应该是它们应有的位置。我曾尝试一次提交文件,这是有效的。只有在我构建时才会遇到问题,并且它阻止我完全运行自动化。

我猜这个问题可能很容易解决,但是,Java / Eclipse堆栈对我来说不是第二天性,就像.NET / C#那样。

注意:如果问题可用,我会用新信息更新问题。

更新:我已将POM包括在内:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.kryterion.qa</groupId>
    <artifactId>automation</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>automation</name>
    <url>http://maven.apache.org</url>
       <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <skipTests>false</skipTests>
       </properties>
 <dependencies>
    <dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
       <version>6.9.9</version>
    </dependency>
    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.17</version>
    </dependency>
    <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-java</artifactId>
       <version>2.48.2</version>
    </dependency>
    <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-firefox-driver</artifactId>
       <version>2.48.2</version>
    </dependency>
    <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-chrome-driver</artifactId>
       <version>2.48.2</version>
    </dependency>
    <dependency>
       <groupId>org.seleniumhq.selenium</groupId>
       <artifactId>selenium-server</artifactId>
       <version>2.48.2</version>
    </dependency>
    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>5.1.37</version>
    </dependency>
    <dependency>
       <groupId>com.google.inject</groupId>
       <artifactId>guice</artifactId>
       <version>3.0</version>
    </dependency>
    <dependency>
       <groupId>net.sourceforge.jexcelapi</groupId>
       <artifactId>jxl</artifactId>
       <version>2.6.12</version>
    </dependency>
    <dependency>
       <groupId>org.apache.poi</groupId>
       <artifactId>poi</artifactId>
       <version>3.10-FINAL</version>
    </dependency>
    <dependency>
       <groupId>org.uncommons</groupId>
       <artifactId>reportng</artifactId>
       <version>1.1.4</version>
    </dependency>
    <dependency>
       <groupId>org.apache.velocity</groupId>
       <artifactId>velocity</artifactId>
       <version>1.7</version>
    </dependency>
    <dependency>
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
       <version>10.11.1.1</version>
    </dependency>
    <dependency>
       <groupId>org.mybatis</groupId>
       <artifactId>mybatis</artifactId>
       <version>3.2.8</version>
    </dependency>
    </dependencies>
    <build>
       <finalName>automation</finalName>
    <plugins>
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.3</version>
          <configuration>
             <source>1.8</source>
             <target>1.8</target>
             <showDeprecation>true</showDeprecation>
          </configuration>
       </plugin>
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19</version>
          <configuration>
             <skipTests>${skipTests}</skipTests>
             <systemPropertyVariables>
                <environment>${envName}</environment>
             </systemPropertyVariables>
             <suiteXmlFiles>
                <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
             </suiteXmlFiles>
         </configuration>
       </plugin>
    </plugins>
 </build>
<reporting>
   <plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-report-plugin</artifactId>
      <version>2.16</version>
   </plugin>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.7</version>
   </plugin>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-changelog-plugin</artifactId>
      <version>2.2</version>
         <configuration>
            <issueLinkUrl>http://prodjira01:8080/browse/%ISSUE%</issueLinkUrl>
         </configuration>
   </plugin>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>2.9.1</version>
   <configuration>
      <show>private</show>
      <additionalparam>${javadoc.doclint.none}</additionalparam>
   </configuration>
   </plugin>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jxr-plugin</artifactId>
      <version>2.3</version>
   </plugin>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pmd-plugin</artifactId>
      <version>3.4</version>
   <configuration>
      <linkXRef>true</linkXRef>
      <source>1.8</source>
      <targetJdk>1.8</targetJdk>
   <rulesets>
      <ruleset>/rulesets/java/basic.xml</ruleset>
      <ruleset>/rulesets/java/braces.xml</ruleset>
      <ruleset>/rulesets/java/design.xml</ruleset>
   </rulesets>
</configuration>
   </plugin>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>taglist-maven-plugin</artifactId>
      <version>2.4</version>
<configuration>
   <tagListOptions>
   <tagClasses>
   <tagClass>
      <displayName>Todo</displayName>
   <tags>
   <tag>
      <matchString>todo</matchString>
      <matchType>ignoreCase</matchType>
   </tag>
   <tag>
      <matchString>FIXME</matchString>
      <matchType>ignoreCase</matchType>
   </tag>
   <tag>
      <matchString>NB</matchString>
      <matchType>exact</matchType>
   </tag>
   </tags>
</tagClass>
<tagClass>
   <displayName>Deprecated</displayName>
   <tags>
   <tag>
      <matchString>@deprecated</matchString>
      <matchType>ignoreCase</matchType>
   </tag>
</tags>
</tagClass>
</tagClasses>
</tagListOptions>
</configuration>
</plugin>
<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>findbugs-maven-plugin</artifactId>
   <version>3.0.0</version>
<configuration>
   <xmlOutput>true</xmlOutput>
   <!-- Optional directory to put findbugs xdoc xml report -->
   <xmlOutputDirectory>target/site</xmlOutputDirectory>
</configuration>
</plugin>
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>config/sun_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

@sircapsalot - 我做了下面你建议的改变,发生的事情就是所有的:

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

突然开始在具有这些导入的所有类中发出警告。想法?

2 个答案:

答案 0 :(得分:1)

根据Maven Central,您要求的版本不存在。 (您正在申请org.testng:testng:jar: 5.14.3

尝试更新到pom.xml中的最新版本6.9.10

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

maven central search

答案 1 :(得分:0)

所以,我找出了问题......事实证明,这是PEBKAC的一个问题。

我将昨天更改的文件重命名为原始状态,现在一切都很顺利。感谢那些帮助解决这个问题的人!