Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.fireblade.qa.automation.modelbusinesslogic; import com.fireblade.qa.automation.elements.WebElementWrapper; import com.fireblade.qa.automation.pageobjectmodel.HomePage; import com.fireblade.qa.automation.utils.DeviceWebDriver; import com.google.inject.Inject; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; /** * * @author steven.williams */ public class FooterBI { private final HomePage homePage; private final DeviceWebDriver deviceWebDriver; @Inject public FooterBI(HomePage homePage, DeviceWebDriver deviceWebDriver) { this.homePage = homePage; this.deviceWebDriver = deviceWebDriver; } public boolean isFooterPresent() throws Exception { try { deviceWebDriver.waitForElement(homePage.getFooterContainerField().get()); return homePage.getFooterContainerField().get().isDisplayed(); } catch (Exception e) { return false; } } public boolean areSocialIconsPresent() throws Exception { try { return homePage.getSocialIconsField().get().isDisplayed(); } catch (Exception e) { return false; } } public boolean isGamesysLogoPresent() throws Exception { try { return homePage.getGameSysLogoField().get().isDisplayed(); } catch (Exception ex) { return false; } } public boolean isCookieDisclaimerPresent() throws Exception { try { return homePage.getCookiesDisclaimerField().get().isDisplayed(); } catch (Exception ex) { return false; } } public boolean arePaymentMethodsAndTrustmarksLogosPresent() throws Exception { try { return homePage.getSocialIconsField().get().isDisplayed(); } catch (Exception ex) { return false; } } public boolean isWelcomeBonusTermsAndConditionsPresent() throws Exception { try { return homePage.getWelcomeTermsAndConditionsField().get().isDisplayed(); } catch (Exception ex) { return false; } } public boolean isWelcomeBonusTermsAndConditionsOpen() throws Exception { try { return homePage.getWelcomeBonusTermsAndConditionsToggleButton().get().getAttribute("class") .equals("toggle open"); } catch (Exception ex) { return false; } } public boolean isLegalCopyPresent() throws Exception { try { return homePage.getLegalCopy().get().isDisplayed(); } catch (Exception ex) { return false; } } public boolean areInternalLinksPresent() throws Exception { try { return homePage.getSocialIcons().get().isDisplayed(); } catch (Exception ex) { return false; } } public void clickOnFirstFooterLink() throws Exception { WebElementWrapper paymentMethodsAndTrustmarks = homePage.getPaymentMethodsAndTrustmarks(); this.getLinksFromSectionAndClickOnFirstLink(paymentMethodsAndTrustmarks); } public void clickOnWelcomeBonus() throws Exception { deviceWebDriver.waitForElement(homePage.getFooterContainer().get()); homePage.getWelcomeBonusTermsAndConditionsToggleButton().get().click(); } private WebElementWrapper getLinkFromName(String linkName) { WebElementWrapper link = null; switch (linkName) { case "About us": link = homePage.getAboutUsLink(); break; case "Terms & Conditions": link = homePage.getTermsAndConditionsLink(); break; case "Privacy Policy": link = homePage.getPrivacyPolicyLink(); break; case "Cookies": link = homePage.getCookiesLink(); break; case "Responsible Gaming": link = homePage.getResponsibleGamingLink(); break; case "Game and Tournament Rules": link = homePage.getGameTournamentRulesLink(); break; case "Site Map": link = homePage.getSiteMapLink(); break; case "Welcome Bonus Terms and Conditions": link = homePage.getWelcomeBonusTermsAndConditionsToggleButton(); break; } return link; } public void clickOnLink(String linkName) throws Exception { WebElementWrapper link = getLinkFromName(linkName); deviceWebDriver.waitForElement(link.get()); link.get().click(); } private WebElementWrapper getExternalLinkFromName(String linkName) { WebElementWrapper link = null; switch (linkName) { case "gamcare": link = homePage.getGameCareLink(); break; case "gamcarecert": link = homePage.getGameCareCertLink(); break; case "gambleaware": link = homePage.getGambleAwareLink(); break; case "abilott": link = homePage.getAbilottLink(); break; case "gamblingcommission": link = homePage.getGamblingCommissionLink(); break; } return link; } public void clickOnExternalLink(String linkName) throws Exception { WebElementWrapper link = getExternalLinkFromName(linkName); deviceWebDriver.waitForElement(link.get()); link.get().click(); } public boolean isUserOnPageForLink(String pageName) throws Exception { switch (pageName) { case "responsiblegaming": return homePage.getResponsibleGamingPopupHeading().get().getText().equalsIgnoreCase("Alert System"); case "pokerrules": return homePage.getGameTournamentRulesPopupHeading().get().getText().equalsIgnoreCase("Alert System"); default: String url = deviceWebDriver.getRemoteWebDriver().getCurrentUrl(); if (url.contains(pageName)) { return true; } else { return false; } } } private void getLinksFromSectionAndClickOnFirstLink(WebElementWrapper section) throws Exception { List<WebElement> allLinks = section.get().findElements(By.tagName("a")); if (allLinks.size() > 0) { allLinks.get(0).click(); } } public boolean isNewWindowOpened() { String currentWindowHandle = deviceWebDriver.getRemoteWebDriver().getWindowHandle(); deviceWebDriver.switchToTheNewWindow(); String newWindowHandle = deviceWebDriver.getRemoteWebDriver().getWindowHandle(); return currentWindowHandle.equals(newWindowHandle); } }