我对Java有点陌生,正在将它与硒一起使用。我有一个通用的页面对象类,该类具有执行相同任务的不同方法,但是根据到达的方式返回不同的页面(即,调用哪种方法)。所以我想做的是创建一个带有switch语句的方法,该方法将返回不同的页面实例。
由于页面上的标题文本将反映前往共享页面的过程,所以我想我可以使用INVOICE_HEADER_IDENTIFIER
作为切换值吗?在这种情况下,只是寻找一些指导和最佳实践。
public AccomodationInvoiceDetails searchForStudentAccomodationInvoice(String studentNo){
assertThat(getTextFromElement(INVOICE_HEADER_IDENTIFIER).equals("Create Accommodation Invoice : Select Invoice")).isTrue();
enterTextIntoElement(SELECT_STUDENT_FIELD_IDENTIFIER, "1990514");
clickElement(NEXT_BUTTON_IDENTIFIER);
waitForElementToBeDisplayed(By.id("ANSWER.TTQ.MENSYS.1."), driver, 10);
return new AccomodationInvoiceDetails(driver);
}
public CreditNoteSelectInvoicePage searchForStudentAccomodationCreditNote(String studentNo){
assertThat(getTextFromElement(INVOICE_HEADER_IDENTIFIER).equals("Create Accommodation Credit Note : Select Student")).isTrue();
enterTextIntoElement(SELECT_STUDENT_FIELD_IDENTIFIER, "1990514");
clickElement(NEXT_BUTTON_IDENTIFIER);
waitForElementToBeDisplayed(By.id("ANSWER.TTQ.MENSYS.1."), driver, 10);
return new CreditNoteSelectInvoicePage(driver);
}
您可以尝试这个:
public Object searchForStudentAccomodation(String studentNo){
String invoiceHeader = getTextFromElement(INVOICE_HEADER_IDENTIFIER);
switch (invoiceHeader){
case "Create Accommodation Credit Note : Select Student" :
commonInvoiceAction(studentNo);
return new CreditNoteSelectInvoicePage(driver);
case "Create Accommodation Invoice : Select Invoice" :
commonInvoiceAction(studentNo);
return new AccomodationInvoiceDetails(driver);
default :
System.out.println("Invalid invoice header : "+invoiceHeader);
return null;
}
}
public void commonInvoiceAction(String studentNo){
enterTextIntoElement(SELECT_STUDENT_FIELD_IDENTIFIER, studentNo);
clickElement(NEXT_BUTTON_IDENTIFIER);
waitForElementToBeDisplayed(By.id("ANSWER.TTQ.MENSYS.1."), driver, 10);
}