可能无法在stepdefs类中将“驱动程序”作为参数传递

时间:2018-10-12 19:18:51

标签: java selenium constructor cucumber pageobjects

所以我在运行用黄瓜编写的测试framewrok时遇到了问题(我会说我刚刚开始)。 这是代码here

当我运行“ Register.feature”文件时,它失败并显示:

Error:(13, 55) java: cannot find symbol
  symbol:   variable driver
  location: class stepdefs.RegisterStepDefs

我在初始化LandingPage对象的“ RegesterStepDefs”类出了毛病-我无法将“ driver”作为参数传递。似乎是我无法长时间处理的错误。 任何建议表示赞赏

包页面中的

BasePageObjectSetUp类;

public class BasePageObjectSetUp {

    private WebDriver driver;

    public BasePageObjectSetUp(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public WebDriver getDriver() {
        return driver;
    }
}
包页面中的

LandingPage类;

public class LandingPage extends BasePageObjectSetUp {

    @FindBy(xpath = "//@[//div[contains(@class,'menu-body')]//span[contains(text(),'Logowanie')]]")
    private WebElement buttonLogowanie;

    @FindBy(xpath = ".//*[@class=register-wrapper]")
    private WebElement buttonRejestracja;


    // calling the inherited construtor from PageObject class
    public LandingPage(WebDriver driver){
        super(driver);
    }


    public void clickButtonRejestracja() throws InterruptedException {
        //WebDriverWait wait = new WebDriverWait(getDriver(), 30);
        //wait.until(ExpectedConditions.elementToBeClickable(buttonRejestracja));
        Thread.sleep(5000);
        buttonRejestracja.click();
    }
}
软件包stepdefs中的

LandingPage类;

public class BaseSetUp {

    private WebDriver driver;

    @Before
    public void setUp() {
        System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\src\\main\\resources\\drivers\\chromedriver.exe");

        //Disable geo localization popup
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.managed_default_content_settings.geolocation", 2);
        options.setExperimentalOption("prefs", prefs);

        driver = new ChromeDriver();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();

        driver.get("http://www.vozilla.pl");
    }

    @After
    public void cleanCookies() {
        driver.manage().deleteAllCookies();
        driver.close();
    }

}
软件包stepdefs中的

RegisterStepDefs类;

public class RegisterStepDefs {

    private LandingPage landingPage = new LandingPage(driver); **<<<< I got a problem here**

    @Given("^User navigates to the register page one$")
    public void userNavigatesToTheRegisterPageOne() throws InterruptedException {
        landingPage.clickButtonRejestracja();
    }
}

0 个答案:

没有答案