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.WebDriver; import org.openqa.selenium.WebElement; import qsf_page_object_pattern.FrontEnd.FrontEnd_RegistrationPage; public class FrontEnd_BasePage extends BasePage { public FrontEnd_BasePage(WebDriver driver) { super(driver); } public FrontEnd_RegistrationPage openRegistrationPage(){ this.mouseOver(By.linkText("Log In")); driver.findElement(By.linkText("Register Now")).click(); return new FrontEnd_RegistrationPage(driver); } public Map GetShopCategories(){ WebElement holderUl = driver.findElement(By.xpath("//a[text() = 'Shop Products']/../ul[@class = 'dropdown-menu']")); makeElementVisibleByJavascript(holderUl); Map categories = new HashMap(); List items = holderUl.findElements(By.cssSelector("li a")); for (WebElement item : items){ categories.put(item.getText(), item.getAttribute("href")); } return categories; } public Map GetProducts(Map categories) { Map products = new HashMap(); for(Entry entry : categories.entrySet()) { driver.get(entry.getValue()); List items = driver.findElements(By.cssSelector("ul#products-list li h5 a")); for (WebElement item : items){ products.put(item.getText(), item.getAttribute("href")); } } return products; } public List getTopLevelMenuByOrder(){ List result = new ArrayList(); List elements = driver.findElements(By.xpath("//ul[@id='nav-main']/li/a")); for(WebElement element : elements){ result.add(element.getText()); } return result; } public List getSubmenuByParent(String parent){ List result = new ArrayList(); mouseOver(By.xpath("//ul[@id='nav-main']/li/a[text()='"+parent+"']")); List elements = driver.findElements(By.xpath("//ul[@id='nav-main']/li/a[text()='"+parent+"']/../ul/li/a")); for(WebElement element : elements){ result.add(element.getText()); } return result; } public List getFooterItemsByOrder(){ List result = new ArrayList(); List elements = driver.findElements(By.xpath("//div[@id='bottom-navigation']/a")); for(WebElement element : elements){ result.add(element.getText()); } return result; } public List getFooterItemsByParent(String parent){ List result = new ArrayList(); List elements = driver.findElements(By.xpath("//div[@id='bottom-navigation']/div//a[text()='"+parent+"']/../../ul//a")); for(WebElement element : elements){ result.add(element.getText()); } return result; } }