java - 即使在实施之后,您也可以使用控制台中显示的以下片段来实施缺少的步骤
问题描述
我创建了三个文件 .feature 文件,stepDefinition.java 和 testRunner.java。当我尝试运行 testRunner 类时,它会继续在控制台中显示建议,例如您可以使用以下代码片段实现缺少的步骤:使用功能文件中的步骤。具有讽刺意味的是,我已经在 stepDefinition 中实现了所有步骤。谁能帮我这个?
登录功能
Feature: Amazon login feature
Scenario: Valid and invalid test cases
Given user already in login page
When user enters username
Then user enters password
Then user click login page
步骤定义.java
package stepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class stepdefinitions {
WebDriver driver=new ChromeDriver();
@Given("^user already in login page$")
public void user_already_in_login_page() throws Exception {
System.setProperty("webdriver.chrome.driver","D:\\MuthuKumar\\Documents\\chromedriver.exe");
driver.get("https://www.amazon.in/");
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id("nav-link-accountList"))).click(driver.findElement(By.xpath("//span[text()='Sign in']"))).build().perform();
}
@When("^user enters username$")
public void user_enters_username() throws Exception {
driver.findElement(By.id("ap_email")).sendKeys("8526606990");
driver.findElement(By.id("continue")).click();
}
@Then("^user enters password$")
public void user_enters_password() throws Exception {
driver.findElement(By.id("ap_password")).sendKeys("sample");
}
@Then("^user click login page$")
public void user_click_login_page() throws Exception {
driver.findElement(By.id("signInSubmit")).click();
}
}
testRunners.java
package testRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\feature"},glue= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\stepDefinition"})
public class testRunners {
}
控制台消息
You can implement missing steps with the snippets below:
@Given("^user already in login page$")
public void user_already_in_login_page() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^user enters username$")
public void user_enters_username() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user enters password$")
public void user_enters_password() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user click login page$")
public void user_click_login_page() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
解决方案
与其给出胶水路径,不如给出你的包名。它工作正常
testRunners.java
package testRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\feature"}
,glue= {"stepDefinition"})
public class testRunners {
}
推荐阅读
- json - 从本地主机迁移到服务器后,如何不丢失 json 中的 get?
- python - 将一个列表与列表列表进行比较并替换值
- node.js - 无法从 Node 获取 cookie 到 React
- python - 在python中绘制一个用matplotlib分段定义的函数
- javascript - vue组件之间如何共享数据?
- python - 按年龄将人员分配到不同家庭的代码
- python - `pytest-qt`函数`mouseMove()`不工作
- intel - UEFI DXE 驱动程序是否在实模式下运行?“ring -2”或“ring -3”代码呢?
- javascript - 页面加载后替换 HTML 文档中的字符串
- join - 写入大数据帧时,胶水作业失败,“设备上没有剩余空间”或“ArrayIndexOutOfBoundsException”