|
|
@@ -7,19 +7,19 @@ import java.io.IOException; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.openqa.selenium.By; |
|
|
|
import org.openqa.selenium.JavascriptExecutor; |
|
|
|
import org.openqa.selenium.WebDriver; |
|
|
|
import org.openqa.selenium.WebElement; |
|
|
|
import org.openqa.selenium.internal.WrapsElement; |
|
|
|
import org.openqa.selenium.remote.LocalFileDetector; |
|
|
|
import org.openqa.selenium.remote.RemoteWebElement; |
|
|
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
public class InterruptUploadTest extends MultiBrowserTest { |
|
|
|
|
|
|
|
private static final String EXPECTED_COUNTER_TEXT = " (counting interrupted at "; |
|
|
@@ -29,36 +29,42 @@ public class InterruptUploadTest extends MultiBrowserTest { |
|
|
|
openTestURL(); |
|
|
|
|
|
|
|
File tempFile = createTempFile(); |
|
|
|
scheduleUploadCancel(); |
|
|
|
|
|
|
|
fillPathToUploadInput(tempFile.getPath()); |
|
|
|
|
|
|
|
// Wait for 3 seconds until everything is done. |
|
|
|
Thread.sleep(3000); |
|
|
|
|
|
|
|
String actual = $(LabelElement.class).caption("Line breaks counted") |
|
|
|
.first().getText(); |
|
|
|
assertTrue("Line break count note does not match expected (was: " |
|
|
|
+ actual + ")", actual.contains(EXPECTED_COUNTER_TEXT)); |
|
|
|
waitForElementPresent(By.className("v-window")); |
|
|
|
$(ButtonElement.class).caption("Cancel").first().click(); |
|
|
|
waitUntilInterruptionRegistered(); |
|
|
|
|
|
|
|
$(WindowElement.class).first().close(); |
|
|
|
waitForElementNotPresent(By.className("v-window")); |
|
|
|
|
|
|
|
// Check if second upload happens |
|
|
|
tempFile = createTempFile(); |
|
|
|
scheduleUploadCancel(); |
|
|
|
fillPathToUploadInput(tempFile.getPath()); |
|
|
|
|
|
|
|
actual = $(LabelElement.class).caption("Line breaks counted").first() |
|
|
|
.getText(); |
|
|
|
assertTrue("Line break count note does not match expected (was: " |
|
|
|
+ actual + ")", actual.contains(EXPECTED_COUNTER_TEXT)); |
|
|
|
waitForElementPresent(By.className("v-window")); |
|
|
|
$(ButtonElement.class).caption("Cancel").first().click(); |
|
|
|
waitUntilInterruptionRegistered(); |
|
|
|
} |
|
|
|
|
|
|
|
private void scheduleUploadCancel() { |
|
|
|
// Schedule upload cancel in 2 seconds |
|
|
|
((JavascriptExecutor) getDriver()).executeScript( |
|
|
|
"setTimeout( function () {window.document.querySelector(\".v-window .v-button\").click()},2000)"); |
|
|
|
private void waitUntilInterruptionRegistered() { |
|
|
|
waitUntil(new ExpectedCondition<Boolean>() { |
|
|
|
String actual; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean apply(WebDriver arg0) { |
|
|
|
actual = $(LabelElement.class).caption("Line breaks counted") |
|
|
|
.first().getText(); |
|
|
|
return actual.contains(EXPECTED_COUNTER_TEXT); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
// Expected condition failed: waiting for ... |
|
|
|
return "line break count note to mention interruption (was: " |
|
|
|
+ actual + ")"; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |