selenium - 对象为空 - Cucumber Selenium
问题描述
我正在尝试加载菜单但收到此错误:
功能文件:
这是代码:
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();
}
}
将永远感激帮助!
解决方案
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);
}
}
推荐阅读
- javascript - 模块构建失败(来自 ./node_modules/sass-loader/lib/loader.js),复合选择器可能不再扩展
- javascript - 如何以编程方式在 chrome 扩展中显示授权标头
- c# - 获取 ASP.NET Core 中的所有服务器变量
- git - (列表)在提交 SHA 的末尾
- django - Django - django.db.utils.OperationalError:没有这样的表:django_session
- c++ - 以下代码 C++ sfml 似乎有错误。我在这里想念什么。谢谢
- google-maps - Google表格中GOOGLEMAPS自定义应用脚本函数的数组输入
- javascript - 有多个触发器时如何更新 gsap 中目标的坐标?
- firebase - 是否可以在创建 firebase 用户之前发送验证电子邮件并验证电子邮件?
- laravel - Laravel 7 验证规则填充或存在不适用于动态生成的选择