Как объект инициализируется без ключевого слова «new» в подходе PageObject - PullRequest
0 голосов
/ 13 марта 2020

Может кто-нибудь описать, почему я могу создать новый объект Page в классе Steps без ключевого слова "new"? Мне не ясно, как это работает на самом деле. Я пытался удалить наследование из класса PageObject, а затем он не работает и выбрасывает NPE. Вот часть моего класса Page:

public class PrototypePage extends PageObject {
private String userName = "//*[@id='x-auto-1-input']";
private String password = "//*[@id='x-auto-2-input']";
private String loginButton = "//*[@id='login_btn']";
private String usersDropDown = "//*[@id='x-auto-3-input']";
private String pid = "//*[@id='x-auto-4-input']";
private String pmid = "//*[@id='x-auto-5-input']";
private String fName = "//*[@id='x-auto-6-input']";
private String lName = "//*[@id='x-auto-7-input']";
private String address = "//*[@id='x-auto-8-input']";
private String city = "//*[@id='x-auto-10-input']";
private String state = "//*[@id='x-auto-11-input']";
private String zip = "//*[@id='x-auto-12-input']";
private String email = "//*[@id='x-auto-13-input']";
private String birthday = "//*[@id='x-auto-14-input']";
private String ssn = "//*[@id='x-auto-15-input']";
private String ssoServer = "//*[@id='x-auto-20-input']";
private String ssoRelayState = "//*[@id='x-auto-21-input']";
private String useIframe = "//label[contains(text(), 'Use iFrame:')]/following-sibling::div/div/div/div/div/label[contains(text(), '%s')]";
private String buttonSubmit = "//*[@id='submit_saml_btn']";

public WebElement findElementByXpath(String xpath) {
    return getDriver().findElement(By.xpath(xpath));
}

public String getPmid()
{
    waitFor(ExpectedConditions.presenceOfElementLocated(By.xpath(pmid)));
    return findElementByXpath(pmid).getAttribute("value");
}

А вот мой класс Steps:

public class PrototypePageSteps {

PrototypePage prototypePage;

@Step
public void openPrototypePage() {
    prototypePage.getDriver().get("https://url.com/");
    prototypePage.getDriver().manage().window().maximize();
}

@Step
public void login(String uname, String pass) {
    prototypePage.login(uname, pass);
}

@Step
public void selectUserFromDropDown(String user) {
    prototypePage.selectUserFromDropDown(user);
}

@Step
public String getPmid() {
    return prototypePage.getPmid();
}

На самом деле, я хочу знать, почему инициализация объекта PrototypePage prototypePage; работает и ничего не выходит из строя. Заранее спасибо.

...