diff --git a/src/main/java/ui/pages/HomePage.java b/src/main/java/ui/pages/HomePage.java index bf967a7..f44c34b 100644 --- a/src/main/java/ui/pages/HomePage.java +++ b/src/main/java/ui/pages/HomePage.java @@ -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; + } + } diff --git a/src/main/java/ui/pages/LibraryPage.java b/src/main/java/ui/pages/LibraryPage.java index de6a811..621c757 100644 --- a/src/main/java/ui/pages/LibraryPage.java +++ b/src/main/java/ui/pages/LibraryPage.java @@ -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; @@ -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 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")); + } + } diff --git a/src/main/java/ui/pages/MarkdownViewer.java b/src/main/java/ui/pages/MarkdownViewer.java new file mode 100644 index 0000000..df31458 --- /dev/null +++ b/src/main/java/ui/pages/MarkdownViewer.java @@ -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 getOutline() { + List headings = new ArrayList<>(); + + List outlineHeadings = this.outline.findElements(By.tagName("div")); + + for (WebElement heading : outlineHeadings) { + String headingTitle = heading.getText(); + headings.add(headingTitle); + } + + return headings; + } + +} diff --git a/src/test/java/stepdefinitions/FileSteps.java b/src/test/java/stepdefinitions/FileSteps.java new file mode 100644 index 0000000..5892ff0 --- /dev/null +++ b/src/test/java/stepdefinitions/FileSteps.java @@ -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 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(); + } + +} diff --git a/src/test/java/stepdefinitions/LibrariesSteps.java b/src/test/java/stepdefinitions/LibrariesSteps.java index 87e78ae..7d08d48 100644 --- a/src/test/java/stepdefinitions/LibrariesSteps.java +++ b/src/test/java/stepdefinitions/LibrariesSteps.java @@ -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 @@ -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") @@ -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); } diff --git a/src/test/resources/features/openArchiveMetadata.feature b/src/test/resources/features/openArchiveMetadata.feature new file mode 100644 index 0000000..2439674 --- /dev/null +++ b/src/test/resources/features/openArchiveMetadata.feature @@ -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()