diff --git a/src/main/java/ui/pages/MarkdownEditor.java b/src/main/java/ui/pages/MarkdownEditor.java new file mode 100644 index 0000000..8bd2d00 --- /dev/null +++ b/src/main/java/ui/pages/MarkdownEditor.java @@ -0,0 +1,82 @@ +package ui.pages; + +import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE; + +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.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; + +/** + * Page Object encapsulates the Markdown editor page. + * + * @author helk + * + */ +@Lazy +@Component +@Scope(SCOPE_CUCUMBER_GLUE) +public class MarkdownEditor extends BasePage { + + @Autowired + public MarkdownEditor(WebDriver driver) { + super(driver); + } + + public MarkdownEditor editContent(String title, String author, String description, String year, String institute) { + this.addTitle(title); + this.addAuthor(author); + // Publisher (has default value) + this.addDescription(description); + this.addYear(year); + this.addInstitute(institute); + // Resource Type (has default value) + // License (Optional) + + WebElement saveButton = driver.findElement(By.id("saveButton")); + saveButton.click(); + + driver.navigate().refresh(); + wait.until(ExpectedConditions.stalenessOf(saveButton)); + wait.until(ExpectedConditions.elementToBeClickable(By.id("editButton"))); + + return this; + } + + 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); + } + + 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/main/java/ui/pages/MarkdownViewer.java b/src/main/java/ui/pages/MarkdownViewer.java index 8618e5d..b754188 100644 --- a/src/main/java/ui/pages/MarkdownViewer.java +++ b/src/main/java/ui/pages/MarkdownViewer.java @@ -6,7 +6,6 @@ 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; @@ -48,6 +47,10 @@ public class MarkdownViewer extends BasePage { @FindBy(className = "seafile-viewer-outline") private WebElement outline; + @Lazy + @Autowired + MarkdownEditor markdownEditor; + @Autowired public MarkdownViewer(WebDriver driver) { super(driver); @@ -95,59 +98,11 @@ public List getOutlineContent() { return content; } - public void editFile(String title, String author, String description, String year, String institute) { + public MarkdownEditor edit() { 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); - this.addInstitute(institute); - // TODO: Should: Publisher, Resource Type and License be edited? - - 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); + return markdownEditor; } } diff --git a/src/test/java/stepdefinitions/FileSteps.java b/src/test/java/stepdefinitions/FileSteps.java index 15bcb44..0669485 100644 --- a/src/test/java/stepdefinitions/FileSteps.java +++ b/src/test/java/stepdefinitions/FileSteps.java @@ -13,6 +13,7 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import ui.pages.FileViewer; +import ui.pages.MarkdownEditor; import ui.pages.MarkdownViewer; /** @@ -78,7 +79,8 @@ public void editArchiveMetadata(DataTable archiveMetadataTable) { Map archiveMetadataMap = archiveMetadataTable.asMap(String.class, String.class); - markdownViewer.editFile(archiveMetadataMap.get("title"), archiveMetadataMap.get("author"), + MarkdownEditor markdownEditor = markdownViewer.edit(); + markdownEditor.editContent(archiveMetadataMap.get("title"), archiveMetadataMap.get("author"), archiveMetadataMap.get("description"), archiveMetadataMap.get("year"), archiveMetadataMap.get("institute")); }