Skip to content

Commit

Permalink
#2 Add "Open archive metadata" Feature
Browse files Browse the repository at this point in the history
- Add: openArchiveMetadata.feature, FileSteps, MarkdownViewer
- Enhance: LibrarySteps, HomePage, LibraryPage
  • Loading branch information
helkv committed Dec 20, 2019
1 parent f6153c9 commit c9eb4a0
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/ui/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ public HomePage openMyLibraries() {
return homePage;
}

public HomePage navigateTo() {
driver.navigate().to(BasePage.KEEPER_URL);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("my-libs-more-op")));
wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState")
.equals("complete"));

return homePage;
}

}
18 changes: 18 additions & 0 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

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

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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;
Expand Down Expand Up @@ -44,4 +47,19 @@ public boolean containsElements(String... elements) {
return true;
}

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));

wait.until(ExpectedConditions.titleContains(elementName));
wait.until(ExpectedConditions.elementToBeClickable(By.id("editButton")));
wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState")
.equals("complete"));
}

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

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

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

import org.openqa.selenium.By;
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 Markdown viewer page.
*
* @author helk
*
*/
@Lazy
@Component
@Scope(SCOPE_CUCUMBER_GLUE)
public class MarkdownViewer extends BasePage {

@FindBy(className = "file-name")
private WebElement fileName;

@FindBy(className = "file-modifier-name")
private WebElement modifierName;

@FindBy(className = "file-modifier-time")
private WebElement modifierTime;

@FindBy(id = "shareBtn")
private WebElement shareButton;

@FindBy(id = "parentDirectory")
private WebElement parentDirectroyButton;

@FindBy(id = "editButton")
private WebElement editButton;

@FindBy(className = "seafile-viewer-outline")
private WebElement outline;

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

public String getFileName() {
return fileName.getText();
}

public String getModifierName() {
return modifierName.getText();
}

public String getModifierTime() {
return modifierTime.getText();
}

public boolean buttonsPresent() {
return (shareButton.isDisplayed() && this.parentDirectroyButton.isDisplayed() && this.editButton.isDisplayed());
}

public List<String> getOutline() {
List<String> headings = new ArrayList<>();

List<WebElement> outlineHeadings = this.outline.findElements(By.tagName("div"));

for (WebElement heading : outlineHeadings) {
String headingTitle = heading.getText();
headings.add(headingTitle);
}

return headings;
}

}
49 changes: 49 additions & 0 deletions src/test/java/stepdefinitions/FileSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package stepdefinitions;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

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

import io.cucumber.java.en.Then;
import ui.pages.MarkdownViewer;

/**
* Tests steps: Files domain
*
* @author helk
*
*/
public class FileSteps {

@Autowired
WebDriver driver;

@Lazy
@Autowired
MarkdownViewer markdownViewer;

@Then("Archive metadata is displayed correctly")
public void archiveMetadataDisplayedCorrectly() {
String fileName = markdownViewer.getFileName();
String modifierName = markdownViewer.getModifierName();
// TODO: Handle Check for modifier time correctly
// String modifierTime = markdownViewer.getModifierTime();

boolean buttonsPresent = markdownViewer.buttonsPresent();

List<String> outline = markdownViewer.getOutline();

assertThat(fileName).isEqualTo("archive-metadata.md");
assertThat(modifierName).isEqualTo("keeper");
// assertThat(modifierTime).isEqualTo("archive-metadata.md");

assertThat(outline).contains("Title", "Author", "Description", "Year", "Institute", "DOI");

assertThat(buttonsPresent).isTrue();
}

}
29 changes: 28 additions & 1 deletion src/test/java/stepdefinitions/LibrariesSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import org.springframework.context.annotation.Lazy;

import io.cucumber.java.After;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import ui.pages.HomePage;
import ui.pages.LibraryPage;

/**
* Tests steps: Libraries domain
Expand All @@ -28,6 +30,11 @@ public class LibrariesSteps {
@Autowired
HomePage homePage;

@Lazy
@Autowired
LibraryPage libraryPage;

// TODO: move newLibraryName as variable to the feature file
private String newLibraryName;

@When("Create new Library")
Expand Down Expand Up @@ -61,8 +68,28 @@ public void newLibraryContainsDefaultDocuments() {
assertThat(defaultElementsContained).isTrue();
}

@After("@createNewLibrary")
@Given("Open new Library")
public void openNewLibrary() {
// FIXME: Replace sleep with a appropriate wait
// Wait implicitly until Cared-Data-Certificate gets added to the new library
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Handle exception
e.printStackTrace();
}

homePage.openLibrary(newLibraryName);
}

@Given("Open archive metadata")
public void openArchiveMetadata() {
libraryPage.openMarkdownElement("archive-metadata.md");
}

@After("@createNewLibrary or @openArchiveMetadata")
public void deleteLibrary() {
homePage.navigateTo();
homePage.openMyLibraries();
homePage.deleteLibrary(newLibraryName);
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/features/openArchiveMetadata.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Open Archive Metadata
Logged in user can open the Archive Metadata of a newly created library.

@KP-18
@openArchiveMetadata
Scenario: Open archive metadata
Given Logged in as User
And Create new Library
And Open new Library
When Open archive metadata
Then Archive metadata is displayed correctly
# @After LibrariesSteps.deleteLibrary()

0 comments on commit c9eb4a0

Please sign in to comment.