summaryrefslogtreecommitdiffstats
path: root/uitest/src/test
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-01-11 16:20:43 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-01-11 16:20:42 +0200
commitb45f30685df11bccbb9c42ae8415bc9b28673166 (patch)
treedd1ada7b05fc95689191abc7c398115955ea8947 /uitest/src/test
parentfc9bf9fc3bc5e7683fcc79059250a0b5f206a243 (diff)
downloadvaadin-framework-b45f30685df11bccbb9c42ae8415bc9b28673166.tar.gz
vaadin-framework-b45f30685df11bccbb9c42ae8415bc9b28673166.zip
Ensure Upload is properly reset after an upload is interrupted (#10522)
Fixes #9635
Diffstat (limited to 'uitest/src/test')
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java b/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java
new file mode 100644
index 0000000000..1df188202d
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java
@@ -0,0 +1,112 @@
+package com.vaadin.tests.components.upload;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.internal.WrapsElement;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.LocalFileDetector;
+import org.openqa.selenium.remote.RemoteWebElement;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import com.vaadin.tests.util.LoremIpsum;
+
+public class InterruptUploadTest extends MultiBrowserTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // PhantomJS fails to upload files for unknown reasons
+ return getBrowsersExcludingPhantomJS();
+ }
+
+ @Test
+ public void testInterruptUpload() throws Exception {
+ openTestURL();
+
+ File tempFile = createTempFile();
+ fillPathToUploadInput(tempFile.getPath());
+
+ waitForElementPresent(By.className("v-window"));
+
+ $(ButtonElement.class).caption("Cancel").first().click();
+
+ String expected = " (counting interrupted at ";
+ String actual = $(LabelElement.class).caption("Line breaks counted")
+ .first().getText();
+ assertTrue("Line break count note does not match expected (was: "
+ + actual + ")", actual.contains(expected));
+
+ $(WindowElement.class).first().close();
+ waitForElementNotPresent(By.className("v-window"));
+
+ tempFile = createTempFile();
+ fillPathToUploadInput(tempFile.getPath());
+
+ waitForElementPresent(By.className("v-window"));
+ $(ButtonElement.class).caption("Cancel").first().click();
+ }
+
+ /**
+ * @return The generated temp file handle
+ * @throws IOException
+ */
+ private File createTempFile() throws IOException {
+ File tempFile = File.createTempFile("TestFileUpload", ".txt");
+ BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
+ writer.write(getTempFileContents());
+ writer.close();
+ tempFile.deleteOnExit();
+ return tempFile;
+ }
+
+ private String getTempFileContents() {
+ StringBuilder sb = new StringBuilder("This is a big test file!");
+ for (int i = 0; i < 70; ++i) {
+ sb.append("\n");
+ sb.append(LoremIpsum.get());
+ }
+ return sb.toString();
+ }
+
+ private void fillPathToUploadInput(String tempFileName) throws Exception {
+ // create a valid path in upload input element. Instead of selecting a
+ // file by some file browsing dialog, we use the local path directly.
+ WebElement input = getInput();
+ setLocalFileDetector(input);
+ input.sendKeys(tempFileName);
+ }
+
+ private WebElement getInput() {
+ return getDriver().findElement(By.className("gwt-FileUpload"));
+ }
+
+ private void setLocalFileDetector(WebElement element) throws Exception {
+ if (getRunLocallyBrowser() != null) {
+ return;
+ }
+
+ if (element instanceof WrapsElement) {
+ element = ((WrapsElement) element).getWrappedElement();
+ }
+ if (element instanceof RemoteWebElement) {
+ ((RemoteWebElement) element)
+ .setFileDetector(new LocalFileDetector());
+ } else {
+ throw new IllegalArgumentException(
+ "Expected argument of type RemoteWebElement, received "
+ + element.getClass().getName());
+ }
+ }
+
+}