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.

PanelRemoveShortcutListenerTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.vaadin.tests.components.panel;
  2. import static org.hamcrest.Matchers.is;
  3. import static org.junit.Assert.assertThat;
  4. import java.util.List;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.remote.DesiredCapabilities;
  9. import org.openqa.selenium.support.ui.ExpectedCondition;
  10. import com.google.common.base.Objects;
  11. import com.vaadin.testbench.elements.ButtonElement;
  12. import com.vaadin.testbench.elements.PanelElement;
  13. import com.vaadin.testbench.elements.TextFieldElement;
  14. import com.vaadin.testbench.parallel.Browser;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. /**
  17. * Test for removing a shortcut listener from Panel.
  18. *
  19. * @author Vaadin Ltd
  20. */
  21. public class PanelRemoveShortcutListenerTest extends MultiBrowserTest {
  22. private PanelElement panel;
  23. @Override
  24. public void setup() throws Exception {
  25. super.setup();
  26. openTestURL();
  27. waitForElementPresent(By.className("v-panel"));
  28. panel = $(PanelElement.class).first();
  29. }
  30. @Override
  31. public List<DesiredCapabilities> getBrowsersToTest() {
  32. List<DesiredCapabilities> list = super.getBrowsersToTest();
  33. // For some reason the shortcut isn't working for these browsers when
  34. // tested through TestBench:
  35. list.remove(Browser.FIREFOX.getDesiredCapabilities());
  36. list.remove(Browser.CHROME.getDesiredCapabilities());
  37. return list;
  38. }
  39. @Test
  40. public void testToggleWithShortcut() {
  41. assertThat(
  42. panel.findElement(By.className("v-panel-caption"))
  43. .findElement(By.tagName("span")).getText(),
  44. is("No shortcut effects (press 'A')"));
  45. attemptShortcut("A on");
  46. attemptShortcut("A off");
  47. }
  48. @Test
  49. public void testShortcutGetsRemoved() {
  50. attemptShortcut("A on");
  51. $(ButtonElement.class).first().click();
  52. waitForElementPresent(By.className("v-label"));
  53. attemptShortcut("A on");
  54. // add a bit more delay to make sure the caption doesn't change later
  55. sleep(2000);
  56. assertThat(panel.findElement(By.className("v-panel-caption"))
  57. .findElement(By.tagName("span")).getText(), is("A on"));
  58. }
  59. private void attemptShortcut(final String expectedCaption) {
  60. $(TextFieldElement.class).first().sendKeys("A");
  61. waitUntil(new ExpectedCondition<Boolean>() {
  62. private String actualCaption;
  63. @Override
  64. public Boolean apply(WebDriver input) {
  65. actualCaption = panel
  66. .findElement(By.className("v-panel-caption"))
  67. .findElement(By.tagName("span")).getText();
  68. return Objects.equal(actualCaption, expectedCaption);
  69. }
  70. @Override
  71. public String toString() {
  72. // Timed out after 10 seconds waiting for ...
  73. return "panel's caption to become " + expectedCaption
  74. + " (was: " + actualCaption + ")";
  75. }
  76. });
  77. }
  78. }