You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UploadNoSelectionTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.components.upload;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertTrue;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebElement;
  7. import com.vaadin.testbench.elements.ButtonElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class UploadNoSelectionTest extends MultiBrowserTest {
  10. @Test
  11. public void testUploadNoSelection() throws Exception {
  12. openTestURL();
  13. // empty content is populated by com.vaadin.tests.util.Log
  14. assertEquals(" ", getLogRow(0));
  15. WebElement submitButton = getSubmitButton();
  16. assertTrue("Upload button should be disabled when no selection.",
  17. hasCssClass(submitButton, "v-disabled"));
  18. submitButton.click();
  19. // clicking the disabled default button doesn't do a thing
  20. assertEquals(" ", getLogRow(0));
  21. $(ButtonElement.class).id("programmatic").click();
  22. // neither does triggering upload programmatically
  23. assertEquals(" ", getLogRow(0));
  24. // add an extension that allows upload without filename
  25. $(ButtonElement.class).id("extend").click();
  26. submitButton.click();
  27. // expecting empty file name
  28. assertLogRow(0, 4, UploadNoSelection.FILE_NAME_PREFIX);
  29. // expecting 0-length file
  30. assertLogRow(1, 3, UploadNoSelection.FILE_LENGTH_PREFIX + " " + 0);
  31. assertLogRow(2, 2, UploadNoSelection.UPLOAD_FINISHED);
  32. assertLogRow(3, 1, UploadNoSelection.RECEIVING_UPLOAD);
  33. // and the same programmatically
  34. $(ButtonElement.class).id("programmatic").click();
  35. // expecting empty file name
  36. assertLogRow(0, 8, UploadNoSelection.FILE_NAME_PREFIX);
  37. // expecting 0-length file
  38. assertLogRow(1, 7, UploadNoSelection.FILE_LENGTH_PREFIX + " " + 0);
  39. assertLogRow(2, 6, UploadNoSelection.UPLOAD_FINISHED);
  40. assertLogRow(3, 5, UploadNoSelection.RECEIVING_UPLOAD);
  41. }
  42. private WebElement getSubmitButton() {
  43. WebElement element = getDriver()
  44. .findElement(By.id(UploadNoSelection.UPLOAD_ID));
  45. WebElement submitButton = element.findElement(By.className("v-button"));
  46. return submitButton;
  47. }
  48. private void assertLogRow(int index, int expentedRowNo,
  49. String expectedValueWithoutRowNo) {
  50. assertEquals(expentedRowNo + ". " + expectedValueWithoutRowNo,
  51. getLogRow(index));
  52. }
  53. }