我在使用 Cucumber 运行 Selenium 的 JUnit 测试用例时收到“cucumber.runtime.CucumberException: java.lang.NoSuchMethodException
”。
我已经创建了带有功能文件、步骤定义java文件和测试运行器java类的maven项目。
这是我的功能文件:
Feature: Free CRM Login Feature
#without Examples Keyword
#Scenario: Free CRM Login Test Scenario
#
#Given user is already on Login Page
#When title of login page is Free CRM
#Then user enters "naveenk" and "test@123"
#Then user clicks on login button
#Then user is on home page
#with Examples Keyword
Scenario Outline: Free CRM Login Test Scenario
Given user is already on Login Page
When title of login page is Free CRM
Then user enters "<username>" and "<password>"
Then user clicks on login button
Then user is on home page
Then Close the browser
Examples:
| username | password |
| naveenk | test@123 |
| tom | test456 |
我的 TestRunner.java:
/**
*
*/
package com.multiply_automation_testRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
/**
* @author BoMaseko
*
*/
@RunWith(Cucumber.class)
@CucumberOptions(
features="C:\\Users\\bomaseko\\eclipse-workspace\\multiply-website-automation\\src\\main\\java\\com\\multiply_automation_features\\multiply-login.feature"
,glue= {"C:\\Users\\bomaseko\\eclipse-workspace\\multiply-website-automation\\src\\main\\java\\com\\multiply_automation_stepDefinitions\\LoginStepDefinition"},
plugin= {"pretty", "html:test-output"})
public class TestRunner {
}
和我的 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>multiply-website-automation</groupId>
<artifactId>multiply-website-automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>multiply-website-automation</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.8</version>
</dependency>
</dependencies>
</project>
当我尝试执行 JUnit 测试用例时,出现以下错误:
cucumber.runtime.CucumberException:java.lang.NoSuchMethodException:cucumber.runtime.java.JavaBackend.<init>(cucumber.runtime.io.ResourceLoader, io.cucumber.stepexpression.TypeRegistry)
最佳答案
尝试更改仅从 src 开始并以最后一个目录结束的功能的路线:
src\\main\\java\\com\\multiply_automation_features
对于粘合,只需保留测试 java 文件所在的目录即可:
multiply_automation_stepDefinitions
关于java - cucumber .runtime.CucumberException : java. lang.NoSuchMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57095773/