Skip to content

Commit

Permalink
#2 Add 'Fill out archive metadata' Feature
Browse files Browse the repository at this point in the history
- Add: fillOutArchiveMetadata.feature
- Enhance: FileSteps, LibrariesSteps, MarkdownViewer
  • Loading branch information
helkv committed Dec 20, 2019
1 parent c9eb4a0 commit feef07d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
71 changes: 71 additions & 0 deletions src/main/java/ui/pages/MarkdownViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
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 @@ -80,4 +82,73 @@ public List<String> getOutline() {
return headings;
}

public List<String> getOutlineContent() {
List<String> content = new ArrayList<>();

List<WebElement> contentElements = driver.findElements(By.xpath("//h2/following-sibling::p"));

for (WebElement contentElement : contentElements) {
String contentText = contentElement.getText();
content.add(contentText);
}

return content;
}

public void editFile(String title, String author, String description, String year, String institute, String doi) {
this.editButton.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("seafile-editor")));

// TODO: Extract to a new Page Class 'MarkdownEditorPage'
this.addTitle(title);
this.addAuthor(author);
this.addDescription(description);
this.addYear(year);
// TODO: Should institute and DOI be edited?
// this.addInstitute(institute);
// this.addDOI(doi);

WebElement saveButton = driver.findElement(By.id("saveButton"));
saveButton.click();

driver.navigate().refresh();
wait.until(ExpectedConditions.stalenessOf(saveButton));
wait.until(ExpectedConditions.elementToBeClickable(By.id("editButton")));
}

public void addTitle(String title) {
this.addTextToOutline("Title", title);
}

public void addAuthor(String author) {
this.addTextToOutline("Author", author);
}

public void addDescription(String description) {
this.addTextToOutline("Description", description);
}

public void addYear(String year) {
this.addTextToOutline("Year", year);
}

public void addInstitute(String institute) {
this.addTextToOutline("Institute", institute);
}

public void addDOI(String doi) {
this.addTextToOutline("DOI", doi);
}

private void addTextToOutline(String outline, String outlineText) {
WebElement outlineElement = driver
.findElement(By.xpath("//div[@class='outline-h2' and text()='" + outline + "']"));
outlineElement.click();
WebElement outlineInput = driver.switchTo().activeElement();
outlineInput.sendKeys(Keys.END);
outlineInput.sendKeys(Keys.RETURN);
WebElement beneathOutlineInput = driver.switchTo().activeElement();
beneathOutlineInput.sendKeys(outlineText);
}

}
13 changes: 13 additions & 0 deletions src/test/java/stepdefinitions/FileSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.context.annotation.Lazy;

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

/**
Expand Down Expand Up @@ -46,4 +47,16 @@ public void archiveMetadataDisplayedCorrectly() {
assertThat(buttonsPresent).isTrue();
}

@Then("Edited archive metadata is displayed correctly")
public void editedArchiveMetadataDisplayedCorrectly() {
List<String> content = markdownViewer.getOutlineContent();

assertThat(content).contains("New Title", "New Author", "New Description", "New Year");
}

@When("Fill out archive metadata")
public void fillOutArchiveMetadata() {
markdownViewer.editFile("New Title", "New Author", "New Description", "New Year", "", "");
}

}
2 changes: 1 addition & 1 deletion src/test/java/stepdefinitions/LibrariesSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void openArchiveMetadata() {
libraryPage.openMarkdownElement("archive-metadata.md");
}

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

@KP-19
@FillOutArchiveMetadata
Scenario: Open archive metadata
Given Logged in as User
And Create new Library
#TODO: Remove the explicte step Open new Library
And Open new Library
And Open archive metadata
When Fill out archive metadata
Then Edited archive metadata is displayed correctly
# @After LibrariesSteps.deleteLibrary()

0 comments on commit feef07d

Please sign in to comment.