Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.alpaca.serenity.pages;
import com.alpaca.serenity.AlpacaBase;
import com.alpaca.serenity.Enums.Currency;
import com.alpaca.serenity.models.Customer;
import net.serenitybdd.core.pages.WebElementFacade;
import org.openqa.selenium.By;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import static com.alpaca.serenity.pages.Constants.CURRENCY_CARD_COMBINATION_NOT_ALLOWED;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class SchedulerPage extends AlpacaBase {
@FindBy(xpath = "//*[@id='customerPaymentMethodForm']/div[1]/div[2]/div[1]/h3/span")
private WebElementFacade moreDetails;
@FindBy(id = "customerRef")
private WebElementFacade schedPayerReference;
@FindBy(id = "firstname")
private WebElementFacade schedFirstName;
@FindBy(id = "surname")
private WebElementFacade schedSurname;
@FindBy(id = "email")
private WebElementFacade schedEmail;
@FindBy(id = "mobile")
private WebElementFacade schedMobileNumber;
@FindBy(id = "homephone")
private WebElementFacade schedHomeNumber;
@FindBy(id = "workphone")
private WebElementFacade schedWorkNumber;
@FindBy(id = "company")
private WebElementFacade schedCompany;
@FindBy(id = "address1")
private WebElementFacade schedAddressLine1;
@FindBy(id = "address2")
private WebElementFacade schedAddressLine2;
@FindBy(id = "address3")
private WebElementFacade schedAddressLine3;
@FindBy(id = "county")
private WebElementFacade schedCounty;
@FindBy(id = "country")
private WebElementFacade schedTermCountryAlpha2;
@FindBy(how = How.CLASS_NAME, using = "inputButton")
private WebElementFacade schedulerTerminalResetButton;
@FindBy(how = How.CLASS_NAME, using = "actionButton")
private WebElementFacade submitButton;
@FindBy(id = "repeats_chzn")
private WebElementFacade repeats;
@FindBy(id = "neverRadio")
private WebElementFacade endsNever;
@FindBy(id = "afterRadio")
private WebElementFacade endsAfter;
@FindBy(id = "endsAfter")
private WebElementFacade endsAfterPayments;
@FindBy(id = "onRadio")
private WebElementFacade endsOn;
@FindBy(id = "endsDate")
private WebElementFacade endsDate;
@FindBy(id = "summaryDiv")
private WebElementFacade summary;
@FindBy(id = "weeklyRepeatsOn_chzn")
private WebElementFacade weeklyRepeatsOn;
@FindBy(id = "monthlyEvery_chzn")
private WebElementFacade everyMonth;
@FindBy(id = "monthlyOnDate")
private WebElementFacade monthlyOnDate;
@FindBy(id = "monthlyOnDay")
private WebElementFacade monthlyOnDay;
@FindBy(id = "monthlyWeek_chzn")
private WebElementFacade monthlyWeek;
@FindBy(id = "monthlyDayOfWeek_chzn")
private WebElementFacade monthlyDayOfWeek;
@FindBy(id = "yearlyDate_chzn")
private WebElementFacade yearlyDate;
@FindBy(id = "yearlyMonth_chzn")
private WebElementFacade yearlyMonth;
@FindBy(id = "amount")
private WebElementFacade amount;
@FindBy(css = "[id$='account']") // it has different id when going from customers and going from the terminal
private WebElementFacade account;
@FindBy(css = "[id*='currenc']") //it has different id when going from customers and going from the terminal
private WebElementFacade currencies;
@FindBy(id = "detailIcon")
private WebElementFacade scheduleDetails;
@FindBy(id = "moreOptionIcon")
private WebElementFacade moreOptions;
@FindBy(id = "orderIdStub")
private WebElementFacade orderIdStub;
@FindBy(id = "varRef")
private WebElementFacade variableReference;
@FindBy(id = "prodId")
private WebElementFacade productId;
@FindBy(id = "custNo")
private WebElementFacade customerNumber;
@FindBy(id = "comment")
private WebElementFacade comment;
@FindBy(id = "processButton")
private WebElementFacade processButton;
@FindBy(id = "schedTerminalResponseViewPayer")
private WebElementFacade viewPayer;
@FindBy(id = "processButton")
private WebElementFacade process;
@FindBy(className = "result-terminal")
private WebElementFacade txtResultTerminal;
@FindBy(css = ".alert #viewCustomer")
private WebElementFacade btnViewCustomer;
@FindBy(css = "[ng-if='result.scheduleReference'] #custNumQuickSearch")
private WebElementFacade txtScheduleRef;
/**
* Adding A costumer
*
* @param customer
*/
public void addCustomer(Customer customer) {
moreDetails.click();
schedCompany.type(customer.getCompany());
schedEmail.type(customer.getEmail());
scrollToElement(schedCompany);
schedMobileNumber.type(customer.getMobileNumber());
schedHomeNumber.type(customer.getHomeNumber());
schedWorkNumber.type(customer.getWorkNumber());
schedAddressLine1.type(customer.getAddressLine1());
schedAddressLine2.type(customer.getAddressLine2());
schedAddressLine3.type(customer.getAddressLine3());
schedCounty.type(customer.getCounty());
scrollToElement(schedTermCountryAlpha2);
selectDropdown(schedTermCountryAlpha2, customer.getCountry());
}
/**
* Filling in schedule form, monthly on the first by default
*
* @param account
* @param amount
* @param currency
*/
public void enteringDefaultScheduleDetails(String account, String amount, Currency currency) {
scrollToElement(this.account);
selectDropdown(this.account, account);
this.amount.type(amount);
selectDropdown(this.currencies, currency.getCurrency());
}
/**
* clicks on process schedule and verifies the success alert is displayed
*/
public String processingSchedule(String message,boolean closeAlert) {
String scheduleRef;
scrollToElement(process).click();
waitFor(".alert");
if (!message.equals(CURRENCY_CARD_COMBINATION_NOT_ALLOWED) && txtScheduleRef.isCurrentlyVisible()) {//TODO change to generic error alert
scheduleRef = txtScheduleRef.getText();
} else {
scheduleRef = "You are either coming from customer section or there was an error creating the schedule";
}
waitForLoad();
verifyAlert(message, closeAlert);
return scheduleRef;
}
/**
* clicks on view customer and asserts the user is taken to the customer details screen
*/
public void viewCustomer() {
waitFor(btnViewCustomer);
btnViewCustomer.click();
waitForLoad();
waitForTextToAppear(findBy("#customerTitle"), Constants.CUSTOMER[language]);
assertThat("URL is wrong", getDriver().getCurrentUrl().contains("customerdetails"), is(true));
}
/**
* Returns the status as String
*
* @return
*/
public String verifyStatus() {
waitFor(txtResultTerminal);
return txtResultTerminal.getText();
}
/**
* Returns the result Code as String
*
* @return
*/
public String verifyResultCode() {
return getDriver().findElement(By.id("resultArea"))
.findElements(By.className("resultMessage")).get(1).getText();
}
/**
* @return
*/
public SchedulerPage viewPayment() {
viewPayer.click();
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.