首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象为空- Cucumber Selenium

对象为空- Cucumber Selenium
EN

Stack Overflow用户
提问于 2021-07-29 19:39:26
回答 1查看 42关注 0票数 0

我正在尝试加载一个菜单,但是得到了这个错误:

Preview

功能文件:

Preview

代码如下:

代码语言:javascript
复制
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);
    }
}

页面:

代码语言:javascript
复制
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();
    }
    
}

会永远感谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2021-07-30 11:16:43

未初始化DashboardPageThresholdsAndAlertsPage类。而且你还得超过司机。

代码语言:javascript
复制
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);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68581977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档