org.testng.TestNGException: Невозможно создать экземпляр теста на огурец - PullRequest
0 голосов
/ 13 октября 2018

Привет, ребята, я пытаюсь запустить мой фреймворк для огурцов с помощью 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 {

}

файл xml testng:

<?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, если кто-то может мне помочь, я буду очень благодарен:)

1 Ответ

0 голосов
/ 13 октября 2018

Несовместимые версии библиотек TestNG и Cucumber.Проверьте их версии в дереве зависимостей и проверьте, какая версия TestNG соответствует версии вашей библиотеки Cucumber, например, здесь:

ОБНОВЛЕНИЕ: я заметил, что вы на самом деле опубликовали pom.xml

Обновите версию cucumber-testng до 1.2.5 (используйте ту же версию, что и для cucumber-java).Используйте testng версию 6.9.10 (если не возражаете).Таким образом вы выровняете все версии библиотек.

ПОДТВЕРЖДЕНО: У вас конфликт между cucumber-testng ver.1.1.5 и cucumber-java вер.1.2.5.Установите для обеих библиотек либо версию 1.1.5, либо обновите их для использования версии 1.2.5.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...