diff --git a/src/main/java/ui/pages/LibraryPage.java b/src/main/java/ui/pages/LibraryPage.java index e53cebf..9ecfe8c 100644 --- a/src/main/java/ui/pages/LibraryPage.java +++ b/src/main/java/ui/pages/LibraryPage.java @@ -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; @@ -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); @@ -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))); + } + } diff --git a/src/test/java/stepdefinitions/LibrariesSteps.java b/src/test/java/stepdefinitions/LibrariesSteps.java index ee895b7..faba934 100644 --- a/src/test/java/stepdefinitions/LibrariesSteps.java +++ b/src/test/java/stepdefinitions/LibrariesSteps.java @@ -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(); diff --git a/src/test/resources/features/uploadFile.feature b/src/test/resources/features/uploadFile.feature new file mode 100644 index 0000000..52dbeb4 --- /dev/null +++ b/src/test/resources/features/uploadFile.feature @@ -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? \ No newline at end of file diff --git a/src/test/resources/files/Test.txt b/src/test/resources/files/Test.txt new file mode 100644 index 0000000..334de2c --- /dev/null +++ b/src/test/resources/files/Test.txt @@ -0,0 +1 @@ +Test .txt \ No newline at end of file