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.

CheckBoxGroupFocusBlurTest.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.checkboxgroup;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.Keys;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.interactions.Actions;
  24. import com.vaadin.testbench.customelements.CheckBoxGroupElement;
  25. import com.vaadin.testbench.elements.LabelElement;
  26. import com.vaadin.tests.tb3.MultiBrowserTest;
  27. /**
  28. * @author Vaadin Ltd
  29. *
  30. */
  31. public class CheckBoxGroupFocusBlurTest extends MultiBrowserTest {
  32. @Test
  33. public void focusBlurEvents() {
  34. openTestURL();
  35. List<WebElement> checkBoxes = $(CheckBoxGroupElement.class).first()
  36. .findElements(By.tagName("input"));
  37. checkBoxes.get(0).click();
  38. // Focus event is fired
  39. Assert.assertTrue(logContainsText("1. Focus Event"));
  40. checkBoxes.get(1).click();
  41. // click on the second checkbox doesn't fire anything
  42. Assert.assertFalse(logContainsText("2."));
  43. // click in the middle between the first and the second (inside group).
  44. WebElement first = checkBoxes.get(0);
  45. int middle = (first.getLocation().y + first.getSize().height
  46. + checkBoxes.get(1).getLocation().y) / 2;
  47. new Actions(getDriver()).moveByOffset(first.getLocation().x, middle)
  48. .click().build().perform();
  49. // no new events
  50. Assert.assertFalse(logContainsText("2."));
  51. // click to label of a checkbox
  52. $(CheckBoxGroupElement.class).first().findElements(By.tagName("label"))
  53. .get(2).click();
  54. // no new events
  55. Assert.assertFalse(logContainsText("2."));
  56. // click on log label => blur
  57. $(LabelElement.class).first().click();
  58. // blur event is fired
  59. Assert.assertTrue(logContainsText("2. Blur Event"));
  60. checkBoxes.get(3).click();
  61. // Focus event is fired
  62. Assert.assertTrue(logContainsText("3. Focus Event"));
  63. // move keyboard focus to the next checkbox
  64. checkBoxes.get(3).sendKeys(Keys.TAB);
  65. // no new events
  66. Assert.assertFalse(logContainsText("4."));
  67. // select the next checkbox
  68. checkBoxes.get(4).sendKeys(Keys.SPACE);
  69. // no new events
  70. Assert.assertFalse(logContainsText("4."));
  71. }
  72. }