当我有匹配的胶水代码时,eclipse抛出以下错误 - 步骤"用户已经在登录页面上"没有匹配的胶水代码



我无法在 eclipse 中运行我的运行器文件,因为 eclipse 说步骤 -'用户已经在登录页面上' 在我的功能文件上没有匹配的胶水代码。

同样,当我关闭并打开功能文件日食时说- 期间发生内部错误:"扫描步骤定义"。 java.lang.NullPointerException

当我运行运行器文件时,Ecipse 显示以下错误

您可以使用以下代码片段实现缺失的步骤:

@Given("^User is already on loginpage$")
public void user_is_already_on_loginpage() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
} .....

我尝试以许多不同的方式指定功能文件和步骤定义文件的路径,但没有任何效果。

功能文件

功能

:免费的CRM登录功能

场景:CRM 登录

给定用户已在登录页面上

当登录页面的标题是免费的CRM时

然后用户输入用户名和d密码

然后用户点击登录按钮

然后用户在主页上

步骤定义文件

package stepDefinitions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
import cucumber.api.java.en.*;
import org.junit.Assert;

public class LogInStepDefinition {
WebDriver driver;
@Given("^User is already on loginpage$")
public void User_is_already_on_loginpage() {
driver=new ChromeDriver();
System.setProperty("webdriver.chrome.driver", 
"C://chromedriver.exe");
driver.get("http://testing-ground.scraping.pro/login");
}
@When("^title of login pageis free CRM$")
public void title_ofloginpage_is_free_CRM() {
String ActualTitle=driver.getTitle();
Assert.assertEquals("Web Scraper Testing Ground", ActualTitle);
}
@Then("^user enters user name an d password$")
public void user_enters_user_name_and_password()  {
driver.findElement(By.id("usr")).sendKeys("admin");
driver.findElement(By.id("pwd")).sendKeys("12345");
}

@Then("^user clicks on login button$")
public void user_clicks_on_login_button()  {
driver.findElement(By.xpath("//*[@id='case_login']/form/input[3]")).click();
}
@Then("^user is on homepage$")
public void user_is_on_homepage()  {
String pageVeri=driver.findElement(By.xpath("//*[@id='content']/div[@id='case_login']/h3[@class='success']")).getText();    
Assert.assertEquals("WELCOME :)", pageVeri);;
}   
}
Runner file
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features="src/main/java/Features/login.feature",
glue= {"/src/main/java/stepDefinitions/LogInStepDefinition.java"}
//format= {"pretty","html:test-output"}
)
public class TestRunner {
}

聚甲醛.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>FreeCRMBDDFramework</groupId>
<artifactId>FreeCRMBDDFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FreeCRMBDDFramework</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>
</dependency>


<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</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>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</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.2.5</version>
</dependency>

</dependencies>
</project>

问题出在您的胶水代码上,请删除"src"之前的"/"。因此,运行器找不到您的步骤定义文件。

更改应为:glue={"src/main/java/stepDefinitions/LogInStepDefinition.java"}

对于问题:"扫描步骤定义".java.lang.NullPointerException。

在 LogInStepDefinition.java 文件中,添加以下单个导入:

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

而不是:

import cucumber.api.java.en.*;

按上述方式更改后,在 eclipse 中关闭并重新打开功能文件。

相关内容

  • 没有找到相关文章

最新更新