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 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.sendKeys(Keys.ENTER);
  24. builder.sendKeys(textArea, "second line jkl;");
  25. builder.perform();
  26. // Should not have triggered shortcut
  27. assertEquals(" ", getLogRow(0));
  28. }
  29. @Test
  30. public void testTextAreaEscapeEventPropagation()
  31. throws InterruptedException {
  32. openTestURL();
  33. WebElement textArea = $(TextAreaElement.class).first();
  34. Actions builder = new Actions(driver);
  35. builder.click(textArea);
  36. builder.sendKeys(textArea, "first line asdf");
  37. builder.sendKeys(Keys.ESCAPE);
  38. builder.sendKeys(textArea, "second line jkl;");
  39. builder.perform();
  40. assertEquals("1. Escape button pressed", getLogRow(0));
  41. }
  42. @Test
  43. public void testTextFieldEscapeEventPropagation() {
  44. openTestURL();
  45. WebElement textField = $(TextFieldElement.class).first();
  46. Actions builder2 = new Actions(driver);
  47. builder2.click(textField);
  48. builder2.sendKeys("third line");
  49. builder2.sendKeys(Keys.ENTER);
  50. builder2.sendKeys(Keys.ESCAPE);
  51. builder2.perform();
  52. assertEquals("1. Enter button pressed", getLogRow(1));
  53. assertEquals("2. Escape button pressed", getLogRow(0));
  54. }
  55. @Test
  56. public void testTextFieldEnterEventPropagation() {
  57. openTestURL();
  58. WebElement textField = $(TextFieldElement.class).first();
  59. Actions builder2 = new Actions(driver);
  60. builder2.click(textField);
  61. builder2.sendKeys("third line");
  62. builder2.sendKeys(Keys.ENTER);
  63. builder2.perform();
  64. assertEquals("1. Enter button pressed", getLogRow(0));
  65. }
  66. }