package abstract_classes; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import qsf_page_object_pattern.BackEnd.BackEnd_LoginPage; public abstract class BackEnd_BasePage extends BasePage{ public By submitBtn = By.id("btnSubmit"); public By cancelBtn = By.id("btnCancel"); protected By logoutLink = By.linkText("Log Out"); public By content_header = By.className("content_header"); protected final String DefaultAlertMessage = "Please review the comments marked in red and make appropriate corrections."; public BackEnd_BasePage(WebDriver driver) { super(driver); } public BackEnd_LoginPage logout(){ driver.findElement(logoutLink).click(); return new BackEnd_LoginPage(driver); } public Map> getFieldsAlerts(){ List errors = new ArrayList(); Map>formErrors = new HashMap>(); if(isElementPresent(By.cssSelector("form#"+formId+" ul.errors"))){ List errorHolders = driver.findElements(By.cssSelector("form#"+formId+" ul.errors")); for(WebElement errorHolder : errorHolders){ String elementName = errorHolder.findElement(By.xpath("./..//*[@name][@name != 'date'][@name != 'MAX_FILE_SIZE'][@name != 'image[oldFile]'][@name != 'image[del]'][@name != 'headerImage[oldFile]'][@name != 'headerImage[del]'][@name != 'captcha[id]'][@name != 'file[oldFile]']")).getAttribute("name"); List fieldErrorHolders = errorHolder.findElements(By.tagName("li")); for(WebElement fieldErrorHolder : fieldErrorHolders){ errors.add(fieldErrorHolder.getText()); } formErrors.put(elementName, new ArrayList(errors)); errors.clear(); } return formErrors; } else{ throw new NoSuchElementException("Expecting error messages to appear on page. Elements Not Found"); } } public void clearForm(Map>fieldsData) throws InterruptedException{ for(Entry> entry : fieldsData.entrySet()){ if(entry.getValue().containsKey("dependsOn")){ //Time out to resolve element not found exception on dependent field Thread.sleep(1000); inputFormFieldValue(entry.getValue().get("dependsOn"), fieldsData.get(entry.getValue().get("dependsOn")).get("value"), fieldsData.get(entry.getValue().get("dependsOn")).get("type")); } inputFormFieldValue(entry.getKey(), entry.getValue().get("value"), entry.getValue().get("type")); } } public void menu_open(String string) { //WebElement element = driver.findElement(By.className("nav")); driver.findElement(By.linkText("News")).click(); } }