Skip to content

Commit

Permalink
#2 Add 'Open Footer links' Feature
Browse files Browse the repository at this point in the history
- Add the openFooterLinks.feature, which checks all the links in the
footer
- Add SeleniumUtil.java for Selenium Wrapper methods
  • Loading branch information
helkv committed Jan 8, 2020
1 parent c38d426 commit 3e7ff0d
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 20 deletions.
175 changes: 175 additions & 0 deletions src/main/java/ui/components/FooterComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package ui.components;

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import ui.pages.BasePage;
import ui.util.SeleniumUtil;

/**
* Page Object encapsulates the Footer component.
*
* @author helk
*
*/
@Lazy
@Component
@Scope(SCOPE_CUCUMBER_GLUE)
public class FooterComponent extends BasePage {

@FindBy(linkText = "Project Catalog")
private WebElement projectCatalogLink;

@FindBy(linkText = "Help / Knowledge Base")
private WebElement helpLink;

@FindBy(linkText = "About")
private WebElement aboutLink;

@FindBy(id = "footer-img")
private WebElement footerFoldOutElement;

@FindBy(linkText = "About Keeper")
private WebElement aboutKeeperLink;

@FindBy(linkText = "Cared Data Commitment")
private WebElement caredDataCommitmentLink;

@FindBy(linkText = "Terms of Service")
private WebElement termsOfServiceLink;

@FindBy(linkText = "Download the Keeper client for Windows, Linux, Mac, Android and iPhone")
private WebElement downloadClientLink;

@FindBy(id = "seafile-logo")
private WebElement seafileLogo;

@FindBy(id = "MPDL-logo")
private WebElement mpdlLogo;

@FindBy(linkText = "Contact Keeper Support")
private WebElement contactKeeperSupportLink;

@FindBy(linkText = "Impressum")
private WebElement impressumLink;

@FindBy(linkText = "Privacy Policy")
private WebElement privacyPolicyLink;

@Autowired
public FooterComponent(WebDriver driver) {
super(driver);
}

public void openProjectCatalog() {
this.projectCatalogLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.titleContains("Catalog"));
}

public void openHelpPage() {
this.helpLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.titleIs("Keeper – Max Planck Digital Library"));
}

public void openAboutDialog() {
this.aboutLink.click();

wait.until(ExpectedConditions.elementToBeClickable(By.id("simplemodal-container")));
}

public void openAboutKeeper() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.aboutKeeperLink));
this.aboutKeeperLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@title='About.markdown']")));
}

public void openCaredDataCommitment() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.caredDataCommitmentLink));
this.caredDataCommitmentLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@title='CaredDataPrinciples.markdown']")));
}

public void openTermsOfService() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.termsOfServiceLink));
this.termsOfServiceLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@title='TermsOfService.markdown']")));
}

public void openDownloadClientPage() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.downloadClientLink));
this.downloadClientLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.titleIs("Download - KEEPER"));
}

public String getSeafileLink() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.seafileLogo));
String onclick = this.seafileLogo.getAttribute("onclick");

String seafileLink = onclick.replace("window.open('", "").replace("');", "");
return seafileLink;
}

public String getMpdlLink() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.mpdlLogo));
String onclick = this.mpdlLogo.getAttribute("onclick");

String mpdlLink = onclick.replace("window.open('", "").replace("');", "");
return mpdlLink;
}

public String getKeeperEmail() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.contactKeeperSupportLink));
String href = this.contactKeeperSupportLink.getAttribute("href");

String keeperEmail = href.replace("mailto:", "");
return keeperEmail;
}

public void openImpressum() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.impressumLink));
this.impressumLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@title='Impressum.markdown']")));
}

public void openPrivacyPolicy() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.privacyPolicyLink));
this.privacyPolicyLink.click();
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@title='DSGVO_Keeper.md']")));
}

}
31 changes: 31 additions & 0 deletions src/main/java/ui/pages/DownloadClientPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ui.pages;

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
* Page Object encapsulates the Download Client page.
*
* @author helk
*
*/
@Lazy
@Component
@Scope(SCOPE_CUCUMBER_GLUE)
public class DownloadClientPage extends BasePage {

@Autowired
public DownloadClientPage(WebDriver driver) {
super(driver);
}

public String getTitle() {
return driver.getTitle();
}

}
36 changes: 36 additions & 0 deletions src/main/java/ui/pages/FileViewer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ui.pages;

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
* Page Object encapsulates the File viewer page.
*
* @author helk
*
*/
@Lazy
@Component
@Scope(SCOPE_CUCUMBER_GLUE)
public class FileViewer extends BasePage {

@FindBy(xpath = "//*[@id='shared-file-view-hd']//h2")
private WebElement fileTitle;

@Autowired
public FileViewer(WebDriver driver) {
super(driver);
}

public String getFileTitle() {
return this.fileTitle.getAttribute("title");
}

}
31 changes: 31 additions & 0 deletions src/main/java/ui/pages/HelpPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ui.pages;

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
* Page Object encapsulates the Help page.
*
* @author helk
*
*/
@Lazy
@Component
@Scope(SCOPE_CUCUMBER_GLUE)
public class HelpPage extends BasePage {

@Autowired
public HelpPage(WebDriver driver) {
super(driver);
}

public String getURL() {
return driver.getCurrentUrl();
}

}
16 changes: 4 additions & 12 deletions src/main/java/ui/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
Expand Down Expand Up @@ -42,9 +41,6 @@ public class HomePage extends BasePage {
@FindBy(id = "side-nav")
private WebElement sideNavigationDiv;

@FindBy(linkText = "Project Catalog")
private WebElement projectCatalogElement;

@Lazy
@Autowired
HomePage homePage;
Expand Down Expand Up @@ -138,15 +134,11 @@ public HomePage openMyLibraries() {
return homePage;
}

public void openProjectCatalog() {
this.projectCatalogElement.click();

// TODO: Rework window handling
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
public boolean aboutDialogIsOpened() {
WebElement dialog = driver.findElement(By.id("simplemodal-container"));
List<WebElement> seafileLogo = dialog.findElements(By.xpath(".//img[@title='Seafile']"));

wait.until(ExpectedConditions.titleContains("Catalog"));
return !seafileLogo.isEmpty();
}

public HomePage navigateTo() {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
Expand All @@ -18,6 +17,8 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import ui.util.SeleniumUtil;

/**
* Page Object encapsulates the Library page (showing the content of a single
* library).
Expand Down Expand Up @@ -55,11 +56,7 @@ public boolean containsElements(String... elements) {
public void openMarkdownElement(String elementName) {
WebElement element = this.directoryViewDiv.findElement(By.linkText(elementName));
element.click();

// TODO: Rework window handling
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.titleContains(elementName));
wait.until(ExpectedConditions.elementToBeClickable(By.id("editButton")));
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/ui/util/SeleniumUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ui.util;

import java.util.ArrayList;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
* Utility class to enhance basic Selenium actions with additional
* functionality.
*
* @author helk
*
*/
public class SeleniumUtil {

private SeleniumUtil() {
// SeleniumUtil should not be instantiated
}

public static void switchToSecondTab(WebDriver driver, WebDriverWait wait) {
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
}

}
Loading

0 comments on commit 3e7ff0d

Please sign in to comment.