从命令提示符执行mavenized selenium项目时的TestNGException

时间:2014-10-27 17:08:09

标签: maven selenium-webdriver webdriver classpath testng

我正在使用&#m; mvn clean install test'从命令提示符运行mavenized TestNG Webdriver项目。但是我在cmd提示符中得到以下异常

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
17:test (default-test) on project WebdriverWithTestNG: Execution default-test of
goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was
an error in the forked process
[ERROR] org.testng.TestNGException:
[ERROR] An error occurred while instantiating class com.generic.validateorders.W
ebAppTest: null
[ERROR] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:398)

另一方面,每当我从日食中运行它时,它执行完全没有任何问题。我的项目类路径有什么问题吗?如果是,那么我该如何解决呢。

3 个答案:

答案 0 :(得分:1)

确保在pom.xml中将fork模式设置为never for surefire插件配置

<configuration>
<forkMode>never</forkMode>
</Configuration>

答案 1 :(得分:1)

我遇到了类似的问题。

<强>根本原因: 我错误地删除了Maven创建的目标文件夹,我试图运行pom.xml

执行失败,错误如下:

[错误]无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.19:test(default-test)项目MoneyFlow:目标org.apache.maven.plugins的执行默认测试: maven-surefire-plugin:2.19:测试失败:分叉过程中出现错误

解决方案

在eclipse中,右键单击Project Explorer中的项目名称&gt; Maven &gt; 更新项目。它使用类文件更新目标文件夹。现在尝试重新运行pom.xml

希望它有所帮助。

答案 2 :(得分:0)

Public Class Main
  Public oList As New List(Of TestObject)
  Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    Dim NewObject As New TestObject(Me)
    oList.Add(NewObject)
    Dim NewObject2 As New TestObject(Me)
    oList.Add(NewObject2)

    MsgBox(NewObject2.Index)
  End Sub

  Public Function Index(ByVal TestObject As TestObject) As Integer
    Return oList.IndexOf(TestObject)
  End Function
End Class

Public Class TestObject

  Private _main As Main
  Public ReadOnly Property Index() As Integer
    Get
        Return _main.Index(Me)
    End Get
  End Property

  Public Sub New(RootClass As Main)
    _main = RootClass
  End Sub

End Class