Skip to content

Commit

Permalink
#2 Add 'Upload file' Feature
Browse files Browse the repository at this point in the history
- Add: uploadFile.feature, Test.txt
- Enhance: LibrariesSteps, LibraryPage
  • Loading branch information
helkv committed Jan 7, 2020
1 parent 659aafe commit 7851c1e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

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

Expand Down Expand Up @@ -31,6 +33,9 @@ public class LibraryPage extends BasePage {
@FindBy(id = "dir-view")
private WebElement directoryViewDiv;

@FindBy(id = "advanced-upload")
private WebElement uploadButton;

@Autowired
public LibraryPage(WebDriver driver) {
super(driver);
Expand Down Expand Up @@ -95,4 +100,27 @@ public boolean lockedIconVisible(String elementName) {
return !lockIcon.isEmpty();
}

public void uploadFile(String fileName) {
// Check upload buttons are clickable:
this.uploadButton.click();
WebElement uploadFilesButton = driver.findElement(By.className("advanced-upload-file"));
wait.until(ExpectedConditions.elementToBeClickable(uploadFilesButton));
// Click on 'Upload' again to hide the field again
this.uploadButton.click();

// Upload done using the upload input element:
WebElement uploadInputElement = driver.findElement(By.id("advanced-upload-file-input"));
((JavascriptExecutor) driver).executeScript("arguments[0].style.visibility = 'visible';", uploadInputElement);

// TODO: Move the extraction of the filepath to another class/method
URL fileUrl = this.getClass().getClassLoader().getResource("files/" + fileName);
String filePath = fileUrl.getPath();
File systemIndependentFile = new File(filePath);
String systemIndependentFilePath = systemIndependentFile.getPath();

uploadInputElement.sendKeys(systemIndependentFilePath);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(fileName)));
}

}
14 changes: 13 additions & 1 deletion src/test/java/stepdefinitions/LibrariesSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,19 @@ public void archiveMetadataLockSymboleIsNotDisplayed() {
assertThat(libraryPage.lockedIconVisible("archive-metadata.md")).isFalse();
}

@After("@createNewLibrary or @openArchiveMetadata or @FillOutArchiveMetadata or @LockArchiveMetadata")
@When("Upload file to Library")
public void uploadFileToLibrary() {
libraryPage.uploadFile("Test.txt");
}

@Then("Library contains file")
public void libraryContainsFile() {
boolean elementContained = libraryPage.containsElements("Test.txt");

assertThat(elementContained).isTrue();
}

@After("@createNewLibrary or @openArchiveMetadata or @FillOutArchiveMetadata or @LockArchiveMetadata or @uploadFile")
public void deleteLibrary() {
homePage.navigateTo();
homePage.openMyLibraries();
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/features/uploadFile.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Upload file
Logged in user can upload a file to a library.

@KP-17
@uploadFile
Scenario: Upload file
Given Logged in as User
And Create new Library
And Open new Library
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?
1 change: 1 addition & 0 deletions src/test/resources/files/Test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test .txt

0 comments on commit 7851c1e

Please sign in to comment.