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.

RadioButtonGroupFocusBlurTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.radiobuttongroup;
  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.RadioButtonGroupElement;
  25. import com.vaadin.testbench.elements.LabelElement;
  26. import com.vaadin.tests.tb3.MultiBrowserTest;
  27. /**
  28. * @author Vaadin Ltd
  29. *
  30. */
  31. public class RadioButtonGroupFocusBlurTest extends MultiBrowserTest {
  32. @Test
  33. public void focusBlurEvents() {
  34. openTestURL();
  35. List<WebElement> radioButtons = $(RadioButtonGroupElement.class).first()
  36. .findElements(By.tagName("input"));
  37. radioButtons.get(0).click();
  38. // Focus event is fired
  39. Assert.assertTrue(logContainsText("1. Focus Event"));
  40. radioButtons.get(1).click();
  41. // click on the second radio button doesn't fire anything
  42. Assert.assertFalse(logContainsText("2."));
  43. // move the cursor to the middle of the first element,
  44. // offset to the middle of the two and perform click
  45. new Actions(getDriver()).moveToElement(radioButtons.get(0))
  46. .moveByOffset(0,
  47. (radioButtons.get(1).getLocation().y
  48. - radioButtons.get(0).getLocation().y) / 2)
  49. .click().build().perform();
  50. // no new events
  51. Assert.assertFalse(logContainsText("2."));
  52. // click to label of a radio button
  53. $(RadioButtonGroupElement.class).first()
  54. .findElements(By.tagName("label")).get(2).click();
  55. // no new events
  56. Assert.assertFalse(logContainsText("2."));
  57. // click on log label => blur
  58. $(LabelElement.class).first().click();
  59. // blur event is fired
  60. Assert.assertTrue(logContainsText("2. Blur Event"));
  61. radioButtons.get(3).click();
  62. // Focus event is fired
  63. Assert.assertTrue(logContainsText("3. Focus Event"));
  64. // move keyboard focus to the next radio button
  65. radioButtons.get(3).sendKeys(Keys.ARROW_DOWN);
  66. // no new events
  67. Assert.assertFalse(logContainsText("4."));
  68. // select the next radio button
  69. radioButtons.get(4).sendKeys(Keys.TAB);
  70. // focus has gone away
  71. waitUntil(driver -> logContainsText("4. Blur Event"), 5);
  72. }
  73. }