我无法在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时
然后用户输入用户名和密码
然后用户单击登录按钮
然后用户位于主页上
步骤定义文件
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 {
}
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>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>
答案 0 :(得分:0)
问题出在您的粘合代码上,请删除"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中关闭并重新打开功能文件。