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.

TextAreaEventPropagationTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.vaadin.tests.components.ui;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Test;
  4. import org.openqa.selenium.Keys;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.interactions.Actions;
  7. import com.vaadin.testbench.elements.TextAreaElement;
  8. import com.vaadin.testbench.elements.TextFieldElement;
  9. import com.vaadin.tests.tb3.MultiBrowserTest;
  10. /**
  11. * Tests that the TextArea widget correctly stops ENTER events from propagating.
  12. *
  13. * @author Vaadin Ltd
  14. */
  15. public class TextAreaEventPropagationTest extends MultiBrowserTest {
  16. @Test
  17. public void textAreaEnterEventPropagation() throws InterruptedException {
  18. openTestURL();
  19. WebElement textArea = $(TextAreaElement.class).first();
  20. Actions builder = new Actions(driver);
  21. builder.click(textArea);
  22. builder.sendKeys(textArea, "first line asdf");
  23. builder.perform();
  24. waitUntilLoadingIndicatorNotVisible();
  25. builder.sendKeys(Keys.ENTER);
  26. builder.perform();
  27. waitUntilLoadingIndicatorNotVisible();
  28. builder.sendKeys(textArea, "second line jkl;");
  29. builder.perform();
  30. waitUntilLoadingIndicatorNotVisible();
  31. builder.perform();
  32. // Should not have triggered shortcut
  33. assertEquals(" ", getLogRow(0));
  34. }
  35. @Test
  36. public void testTextAreaEscapeEventPropagation()
  37. throws InterruptedException {
  38. openTestURL();
  39. WebElement textArea = $(TextAreaElement.class).first();
  40. Actions builder = new Actions(driver);
  41. builder.click(textArea);
  42. builder.sendKeys(textArea, "first line asdf");
  43. builder.perform();
  44. waitUntilLoadingIndicatorNotVisible();
  45. builder.sendKeys(Keys.ESCAPE);
  46. builder.perform();
  47. waitUntilLoadingIndicatorNotVisible();
  48. builder.sendKeys(textArea, "second line jkl;");
  49. builder.perform();
  50. waitUntilLoadingIndicatorNotVisible();
  51. assertEquals("1. Escape button pressed", getLogRow(0));
  52. }
  53. @Test
  54. public void testTextFieldEscapeEventPropagation() {
  55. openTestURL();
  56. WebElement textField = $(TextFieldElement.class).first();
  57. Actions builder2 = new Actions(driver);
  58. builder2.click(textField);
  59. builder2.sendKeys("third line");
  60. builder2.perform();
  61. waitUntilLoadingIndicatorNotVisible();
  62. builder2.sendKeys(Keys.ENTER);
  63. builder2.perform();
  64. waitUntilLoadingIndicatorNotVisible();
  65. builder2.sendKeys(Keys.ESCAPE);
  66. builder2.perform();
  67. waitUntilLoadingIndicatorNotVisible();
  68. assertEquals("1. Enter button pressed", getLogRow(1));
  69. assertEquals("2. Escape button pressed", getLogRow(0));
  70. }
  71. @Test
  72. public void testTextFieldEnterEventPropagation() {
  73. openTestURL();
  74. WebElement textField = $(TextFieldElement.class).first();
  75. Actions builder2 = new Actions(driver);
  76. builder2.click(textField);
  77. builder2.sendKeys("third line");
  78. builder2.perform();
  79. waitUntilLoadingIndicatorNotVisible();
  80. builder2.sendKeys(Keys.ENTER);
  81. builder2.perform();
  82. waitUntilLoadingIndicatorNotVisible();
  83. assertEquals("1. Enter button pressed", getLogRow(0));
  84. }
  85. }