簡體   English   中英

org.testng.TestNGException:無法實例化黃瓜測試運行器

[英]org.testng.TestNGException: Cannot instantiate cucumber test runner

嗨,大家好,我試圖用testng運行我的黃瓜框架,我很確定我是一個版本問題,但是如果有人可以在這里指出問題,我就很感謝

特征:

Feature: Application Login

Scenario: Home page default login
Given user is on landing page
When user logins into the application with username "jon" and password 
"1234"
Then Home page is displayed
And Cards displayed "true"

Scenario: Home page default login2
Given user is on landing page
When user logins into the application with username "john" and password 
"4321"
Then Home page is displayed
And Cards displayed "false"

定義:

package StepDefinations;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.And;



public class LoginDefination {

    @Given("^user is on landing page$")
    public void user_is_on_landing_page() throws Throwable {
        //code
        System.out.println("on landing page");
        }


    @When("^user logins into the application with username and password$")
    public void user_logins_into_the_application_with_username_and_password() throws Throwable {
        //code
        System.out.println("logging in");

    }

    @When("^user logins into the application with username \"([^\"]*)\" and password \"([^\"]*)\"$")
    public void user_logins_into_the_application_with_something_and_password_something(String strArg1, String strArg2) throws Throwable {
        System.out.println(strArg1 +" "+ strArg2);
    }

    @Then("^Home page is displayed$")
    public void home_page_is_displayed() throws Throwable {
        //code
        System.out.println("hello homepage");
    }

    @And("^Cards are displayed$")
    public void cards_are_displayed() throws Throwable {
        //code
        System.out.println("hello cards");
    }

    @And("^Cards are not displayed$")
    public void cards_are_not_displayed() throws Throwable {
        //code
        System.out.println("hello not cards");
    }

    @And("^Cards displayed \"([^\"]*)\"$")
    public void cards_displayed(String args) throws Throwable {
        //code
        System.out.println("this will or will not display the cards - " + args);
    }

}

測試運行器文件:

package CucumberOptions;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

//Feature

@CucumberOptions(
        features = "src\\test\\java\\features",
        //if u want tp execute everything then just give the path till the package level
        glue= "StepDefinations"//Package name
        )
public class TestRunner extends AbstractTestNGCucumberTests {

}

testng xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="cucumber testing 101">
  <classes>
  <class name="CucumberOptions.testme"/>
  <class name="CucumberOptions.TestRunner"/>

  </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Maven 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Cucumber</groupId>
  <artifactId>Automation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Automation</name>
  <url>http://maven.apache.org</url>


  <build>
  <resources>

 <resource>
        <directory>src/main/java/resources</directory>
        <filtering>true</filtering>
 </resource>

  </resources>
  <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>

</plugins>
  </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

  <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
</dependency>



  <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>1.1.5</version>
</dependency>


  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.14.0</version>
</dependency>


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




  </dependencies>
</project>

錯誤:

[RemoteTestNG] detected TestNG version 6.10.0
org.testng.TestNGException: 
Cannot instantiate class CucumberOptions.TestRunner
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:363)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:275)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
    at org.testng.TestClass.getInstances(TestClass.java:100)
    at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:86)
    at org.testng.TestClass.init(TestClass.java:78)
    at org.testng.TestClass.<init>(TestClass.java:41)
    at org.testng.TestRunner.initMethods(TestRunner.java:425)
    at org.testng.TestRunner.init(TestRunner.java:252)
    at org.testng.TestRunner.init(TestRunner.java:222)
    at org.testng.TestRunner.<init>(TestRunner.java:171)
    at org.testng.remote.support.RemoteTestNG6_10$1.newTestRunner(RemoteTestNG6_10.java:28)
    at org.testng.remote.support.RemoteTestNG6_10$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_10.java:61)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:623)
    at org.testng.SuiteRunner.init(SuiteRunner.java:189)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:136)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1375)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1355)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
    at org.testng.TestNG.runSuites(TestNG.java:1133)
    at org.testng.TestNG.run(TestNG.java:1104)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
    ... 25 more
Caused by: java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptionsFactory.<init>(Ljava/lang/Class;[Ljava/lang/Class;)V
    at cucumber.api.testng.AbstractTestNGCucumberTests.<init>(AbstractTestNGCucumberTests.java:27)
    at CucumberOptions.TestRunner.<init>(TestRunner.java:14)
    ... 30 more

它是一段簡單的代碼,但是我只是想嘗試使用testng然后使用maven使它工作,如果有人可以幫助我,我將非常感激:)

TestNG和Cucumber庫的版本不兼容。 在依賴關系樹中驗證它們的版本,並檢查適合您的Cucumber庫版本的TestNG版本,例如:

更新:我注意到您實際上已經發布了pom.xml

cucumber-testng的版本更新為1.2.5 (使用與cucumber-java相同的版本)。 使用testng版本6.9.10 (如果您不介意的話)。 這樣,您將對齊所有庫版本。

確認: cucumber-testngcucumber-testng之間存在沖突。 1.1.5和cucumber-java 1.2.5。 將兩個庫都設置為1.1.5版,或者將它們更新為使用1.2.5版。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM