我正在尝试加载一个菜单,但是得到了这个错误:
功能文件:
代码如下:
Step Definition (Failing @When step):
public class ThresholdsAndAlertsPageSteps {
private LoginPage loginPage = new LoginPage(DriverFactory.getDriver());
private DashboardPage dashboardPage;
private ThresholdsAndAlertsPage thralertPage;
@When("user clicks on ThresholdsAndAlerts link")
public void user_clicks_on_thresholds_alerts_link() {
dashboardPage.clickMenu();
thralertPage = dashboardPage.clickMenu();
}
@Then("user gets the title of the page menu {string}")
public void user_gets_the_title_of_the_page_menu(String expectedTitle) {
String actualTitle = thralertPage.getPageMenu();
Assert.assertTrue(actualTitle.contains(expectedTitle));
System.out.println(actualTitle);
}
}页面:
package com.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class ThresholdsAndAlertsPage {
private WebDriver driver;
//1. Locators
private By dfn_thrs = By.xpath("//html[@id='konga']/body/div/div[2]/div[2]/div/div/div[2]/div/div/div/a");
private By cfg_thrs_on1 = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div/div/div/div/span[3]");
private By ent_srvc = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[2]/div/select");
private By lim_typ = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[3]/div/select");
private By thrs_typ = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[4]/div/select");
private By act_typ = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[5]/div/select");
private By act_cfg = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[6]/div/chips/div[2]/input");
private By act_frq = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[7]/div/input");
private By cfg_thrs_on2 = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[8]/div/div/div/span[3]");
private By val = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[9]/div/input");
private By unit = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[10]/div/select");
private By add_thrs = By.xpath("//html[@id='konga']/body/div/div/div/div[3]/div/form/div[11]/div/button");
private By menu_title = By.xpath("//div/div[2]/div[2]/div/div/div/h3/span");
//2. Constructor
public ThresholdsAndAlertsPage(WebDriver driver) {
this.driver = driver;
}
//3. Page Actions
public String getPageMenu() {
return menu_title.toString();
}
public ThresholdsAndAlertsPage navigateThresholdsAndAlertsPage() {
return new ThresholdsAndAlertsPage(driver);
}
public void clickDefineThresh() {
driver.findElement(dfn_thrs).click();
}
}会永远感谢你的帮助!
发布于 2021-07-30 11:16:43
未初始化DashboardPage和ThresholdsAndAlertsPage类。而且你还得超过司机。
Step Definition (Failing @When step):
public class ThresholdsAndAlertsPageSteps {
private LoginPage loginPage = new LoginPage(DriverFactory.getDriver());
private DashboardPage dashboardPage;
private ThresholdsAndAlertsPage thralertPage;
@When("user clicks on ThresholdsAndAlerts link")
public void user_clicks_on_thresholds_alerts_link() {
dashboardPage = new DashboardPage(DriverFactory.getDriver());
dashboardPage.clickMenu();
thralertPage = new ThresholdsAndAlertsPage(DriverFactory.getDriver());
thralertPage = dashboardPage.clickMenu();
}
@Then("user gets the title of the page menu {string}")
public void user_gets_the_title_of_the_page_menu(String expectedTitle) {
String actualTitle = thralertPage.getPageMenu();
Assert.assertTrue(actualTitle.contains(expectedTitle));
System.out.println(actualTitle);
}
}https://stackoverflow.com/questions/68581977
复制相似问题