From feef07dcdb6d10843b26f5c926082e184409d05c Mon Sep 17 00:00:00 2001 From: helkv Date: Fri, 20 Dec 2019 14:22:37 +0100 Subject: [PATCH] #2 Add 'Fill out archive metadata' Feature - Add: fillOutArchiveMetadata.feature - Enhance: FileSteps, LibrariesSteps, MarkdownViewer --- src/main/java/ui/pages/MarkdownViewer.java | 71 +++++++++++++++++++ src/test/java/stepdefinitions/FileSteps.java | 13 ++++ .../java/stepdefinitions/LibrariesSteps.java | 2 +- .../features/fillOutArchiveMetadata.feature | 14 ++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/features/fillOutArchiveMetadata.feature diff --git a/src/main/java/ui/pages/MarkdownViewer.java b/src/main/java/ui/pages/MarkdownViewer.java index df31458..65206b3 100644 --- a/src/main/java/ui/pages/MarkdownViewer.java +++ b/src/main/java/ui/pages/MarkdownViewer.java @@ -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; @@ -80,4 +82,73 @@ public List getOutline() { return headings; } + public List getOutlineContent() { + List content = new ArrayList<>(); + + List 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); + } + } diff --git a/src/test/java/stepdefinitions/FileSteps.java b/src/test/java/stepdefinitions/FileSteps.java index 5892ff0..cf6b35f 100644 --- a/src/test/java/stepdefinitions/FileSteps.java +++ b/src/test/java/stepdefinitions/FileSteps.java @@ -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; /** @@ -46,4 +47,16 @@ public void archiveMetadataDisplayedCorrectly() { assertThat(buttonsPresent).isTrue(); } + @Then("Edited archive metadata is displayed correctly") + public void editedArchiveMetadataDisplayedCorrectly() { + List 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", "", ""); + } + } diff --git a/src/test/java/stepdefinitions/LibrariesSteps.java b/src/test/java/stepdefinitions/LibrariesSteps.java index 7d08d48..4d7eb24 100644 --- a/src/test/java/stepdefinitions/LibrariesSteps.java +++ b/src/test/java/stepdefinitions/LibrariesSteps.java @@ -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(); diff --git a/src/test/resources/features/fillOutArchiveMetadata.feature b/src/test/resources/features/fillOutArchiveMetadata.feature new file mode 100644 index 0000000..864877a --- /dev/null +++ b/src/test/resources/features/fillOutArchiveMetadata.feature @@ -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() \ No newline at end of file