Skip to content

Commit

Permalink
#2 Add 'Receive Certificate' scenario to 'Upload file' feature
Browse files Browse the repository at this point in the history
-> Add new scenario 'Receive Certificate'
- Adapt the test data for the archive metadata: Now the data for the
archive metadata contents have the correct form (condition to receive a
certificate)
- Add SeleniumUtil.switchToFirstTab()
  • Loading branch information
helkv committed Jan 16, 2020
1 parent 6b9fb6c commit eb8f869
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
18 changes: 15 additions & 3 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ public LibraryPage(WebDriver driver) {
super(driver);
}

public boolean containsElements(String... elements) {
for (String element : elements) {
List<WebElement> elementLinks = this.directoryViewDiv.findElements(By.linkText(element));
public boolean containsElements(String... elementNames) {
for (String elementName : elementNames) {
List<WebElement> elementLinks = this.directoryViewDiv.findElements(By.linkText(elementName));
if (elementLinks.isEmpty()) {
return false;
}
}

return true;
}

public boolean containsElementsContainingNameSubstring(String... elementNameSubstrings) {
for (String elementNameSubstring : elementNameSubstrings) {
List<WebElement> elementLinks = this.directoryViewDiv
.findElements(By.partialLinkText(elementNameSubstring));
if (elementLinks.isEmpty()) {
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/ui/pages/MarkdownViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public List<String> getOutlineContent() {
return content;
}

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

Expand All @@ -104,9 +104,8 @@ public void editFile(String title, String author, String description, String yea
this.addAuthor(author);
this.addDescription(description);
this.addYear(year);
// TODO: Should institute and DOI be edited?
// this.addInstitute(institute);
// this.addDOI(doi);
this.addInstitute(institute);
// TODO: Should: Publisher, Resource Type and License be edited?

WebElement saveButton = driver.findElement(By.id("saveButton"));
saveButton.click();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ui/util/SeleniumUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public static void switchToSecondTab(WebDriver driver, WebDriverWait wait) {
driver.switchTo().window(tabs.get(1));
}

public static void switchToFirstTab(WebDriver driver) {
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(0));
}

}
16 changes: 14 additions & 2 deletions src/test/java/stepdefinitions/FileSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ public void archiveMetadataDisplayedCorrectly() {
public void editedArchiveMetadataDisplayedCorrectly() {
List<String> content = markdownViewer.getOutlineContent();

assertThat(content).contains("New Title", "New Author", "New Description", "New Year");
// TODO: Rework (Relocate) the access/initialization of (all) the test data
String title = "Title for a Test-Project";
String author = "Author-Lastname, Author-Firstname";
String description = "This is a Test-Description for a Test-Project.";
String year = "2020";
String institute = "Institute-Name; Department-Name; Director, Director-Lastname";

assertThat(content).contains(title, author, description, year, institute);
}

@When("Fill out archive metadata")
public void fillOutArchiveMetadata() {
markdownViewer.editFile("New Title", "New Author", "New Description", "New Year", "", "");
String title = "Title for a Test-Project";
String author = "Author-Lastname, Author-Firstname";
String description = "This is a Test-Description for a Test-Project.";
String year = "2020";
String institute = "Institute-Name; Department-Name; Director, Director-Lastname";
markdownViewer.editFile(title, author, description, year, institute);
}

}
13 changes: 12 additions & 1 deletion src/test/java/stepdefinitions/LibrariesSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,18 @@ public void libraryContainsFile() {
assertThat(elementContained).isTrue();
}

@After("@createNewLibrary or @openArchiveMetadata or @FillOutArchiveMetadata or @LockArchiveMetadata or @uploadFile")
@Then("Library contains certificate")
public void libraryContainsCertificate() {
// TODO: Rework/Relocate this navigation to the library!?
homePage.navigateTo();
homePage.openLibrary(newLibraryName);

boolean elementContained = libraryPage.containsElementsContainingNameSubstring("cared-data-certificate_");

assertThat(elementContained).isTrue();
}

@After("@createNewLibrary or @openArchiveMetadata or @FillOutArchiveMetadata or @LockArchiveMetadata or @uploadFile or @receiveCertificate")
public void deleteLibrary() {
homePage.navigateTo();
homePage.openMyLibraries();
Expand Down
15 changes: 12 additions & 3 deletions src/test/resources/features/uploadFile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Feature: Upload file
When Upload file to Library
Then Library contains file
# @After LibrariesSteps.deleteLibrary()

#TODO: Further test case: Check -> @And Library contains certificate
# Which preconditions must be met to get the certificate?

@KP-29
@receiveCertificate
Scenario: Receive Certificate
Given Logged in as User
And Create new Library
And Open new Library
When Upload file to Library
And Open archive metadata
And Fill out archive metadata
Then Library contains certificate
# @After LibrariesSteps.deleteLibrary()

0 comments on commit eb8f869

Please sign in to comment.