Skip to content

Commit

Permalink
#2 Improve some Assertions
Browse files Browse the repository at this point in the history
-> Use contains-Assertions to check whether a certain name of an element
(file, library, ...) is present in a list of elements! (Instead of
having a method on page-object level which only returns a boolean)
-> Add a assertion-description to assertions which have to check a
boolean value
- Add methods: readLibraryNames(), readFileNames()
- Remove unused methods
  • Loading branch information
helkv committed Jan 21, 2020
1 parent 3266d2a commit c7c76b8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
10 changes: 7 additions & 3 deletions src/main/java/ui/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -95,10 +96,13 @@ public HomePage createNewLibrary(String newLibraryName) {
return homePage;
}

public boolean containsLibrary(String libraryName) {
List<WebElement> libraryLinks = this.myLibrariesDiv.findElements(By.linkText(libraryName));
public List<String> readLibraryNames() {
List<WebElement> libraryLinks = this.myLibrariesDiv.findElements(By.xpath(".//*[@class='repo-name-span']/a"));

return !libraryLinks.isEmpty();
List<String> libraryNames = new ArrayList<>();
libraryLinks.forEach(libraryLink -> libraryNames.add(libraryLink.getText()));

return libraryNames;
}

public HomePage deleteLibrary(String libraryName) {
Expand Down
31 changes: 6 additions & 25 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
Expand Down Expand Up @@ -44,31 +43,13 @@ public LibraryPage(WebDriver driver) {
super(driver);
}

public boolean containsElements(Collection<String> elementNames) {
for (String elementName : elementNames) {
List<WebElement> elementLinks = this.directoryViewDiv.findElements(By.linkText(elementName));
if (elementLinks.isEmpty()) {
return false;
}
}
public List<String> readFileNames() {
List<WebElement> fileLinks = this.directoryViewDiv.findElements(By.xpath(".//*[@class='dirent-name']/a"));

return true;
}

public boolean containsElements(String... elementNames) {
return this.containsElements(Arrays.asList(elementNames));
}

public boolean containsElementsContainingNameSubstring(String... elementNameSubstrings) {
for (String elementNameSubstring : elementNameSubstrings) {
List<WebElement> elementLinks = this.directoryViewDiv
.findElements(By.partialLinkText(elementNameSubstring));
if (elementLinks.isEmpty()) {
return false;
}
}
List<String> fileNames = new ArrayList<>();
fileLinks.forEach(fileLink -> fileNames.add(fileLink.getText()));

return true;
return fileNames;
}

public void openMarkdownElement(String elementName) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/stepdefinitions/FileSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void markdownFileTitlePresent(String fileName) {
public void markdownViewerButtonsPresent() {
boolean buttonsPresent = markdownViewer.buttonsPresent();

assertThat(buttonsPresent).isTrue();
assertThat(buttonsPresent).as("Check presence of the Markdown-Viewer buttons.").isTrue();
}

@Then("Archive metadata content consists of:")
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/stepdefinitions/LibrariesSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public void createNewLibrary(String libraryName) {

@Then("My Libraries contains {string}")
public void myLibrariesContains(String libraryName) {
boolean containsLibrary = homePage.containsLibrary(libraryName);
List<String> containedLibraryNames = homePage.readLibraryNames();

assertThat(containsLibrary).isTrue();
assertThat(containedLibraryNames).contains(libraryName);
}

@Then("Library {string} contains:")
Expand All @@ -68,9 +68,9 @@ public void libraryContains(String libraryName, List<String> fileNames) {
logger.error("Waiting for Library was interrupted.", e);
}

boolean defaultElementsContained = homePage.openLibrary(libraryName).containsElements(fileNames);
List<String> containedFileNames = homePage.openLibrary(libraryName).readFileNames();

assertThat(defaultElementsContained).isTrue();
assertThat(containedFileNames).containsAll(fileNames);
}

@Given("Open Library {string}")
Expand Down Expand Up @@ -98,7 +98,9 @@ public void lockFile(String fileName) {

@Then("Lock symbole displayed for {word}")
public void lockSymboleDisplayedForFile(String fileName) {
assertThat(libraryPage.lockedIconVisible(fileName)).isTrue();
boolean lockedIconVisible = libraryPage.lockedIconVisible(fileName);

assertThat(lockedIconVisible).as("Check visibility of the Locked-Icon.").isTrue();
}

@When("Unlock {word} file")
Expand All @@ -108,7 +110,9 @@ public void unlockFile(String fileName) {

@Then("Lock symbole not displayed for {word}")
public void lockSymboleNotDisplayedForFile(String fileName) {
assertThat(libraryPage.lockedIconVisible(fileName)).isFalse();
boolean lockedIconVisible = libraryPage.lockedIconVisible(fileName);

assertThat(lockedIconVisible).as("Check non-visibility of the Locked-Icon.").isFalse();
}

@When("Upload file {word} to Library")
Expand All @@ -118,11 +122,9 @@ public void uploadFileToLibrary(String fileName) {

@Then("Library contains file {word}")
public void libraryContainsFile(String fileName) {
// TODO: Return all files of the library and assert whether fileName is
// contained. Rework this for all assertions which only check true/false!
boolean elementContained = libraryPage.containsElements(fileName);
List<String> containedFileNames = libraryPage.readFileNames();

assertThat(elementContained).isTrue();
assertThat(containedFileNames).contains(fileName);
}

@Then("Library {string} contains certificate")
Expand All @@ -131,10 +133,9 @@ public void libraryContainsCertificate(String libraryName) {
homePage.navigateTo();
homePage.openLibrary(libraryName);

// TODO: How to handle "cared-data-certificate_" correctly
boolean elementContained = libraryPage.containsElementsContainingNameSubstring("cared-data-certificate_");
List<String> containedFileNames = libraryPage.readFileNames();

assertThat(elementContained).isTrue();
assertThat(containedFileNames).anyMatch(fileName -> fileName.startsWith("cared-data-certificate_"));
}

}

0 comments on commit c7c76b8

Please sign in to comment.