2 * Copyright 2000-2016 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.tests.components.radiobuttongroup;
18 import java.util.List;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.Keys;
24 import org.openqa.selenium.WebElement;
25 import org.openqa.selenium.interactions.Actions;
27 import com.vaadin.testbench.customelements.RadioButtonGroupElement;
28 import com.vaadin.testbench.elements.LabelElement;
29 import com.vaadin.tests.tb3.MultiBrowserTest;
35 public class RadioButtonGroupFocusBlurTest extends MultiBrowserTest {
38 public void focusBlurEvents() {
41 List<WebElement> radioButtons = $(RadioButtonGroupElement.class).first()
42 .findElements(By.tagName("input"));
43 radioButtons.get(0).click();
45 // Focus event is fired
46 Assert.assertTrue(logContainsText("1. Focus Event"));
48 radioButtons.get(1).click();
49 // click on the second radio button doesn't fire anything
50 Assert.assertFalse(logContainsText("2."));
52 // move the cursor to the middle of the first element,
53 // offset to the middle of the two and perform click
54 new Actions(getDriver()).moveToElement(radioButtons.get(0))
56 (radioButtons.get(1).getLocation().y
57 - radioButtons.get(0).getLocation().y) / 2)
58 .click().build().perform();
60 Assert.assertFalse(logContainsText("2."));
62 // click to label of a radio button
63 $(RadioButtonGroupElement.class).first()
64 .findElements(By.tagName("label")).get(2).click();
66 Assert.assertFalse(logContainsText("2."));
68 // click on log label => blur
69 $(LabelElement.class).first().click();
70 // blur event is fired
71 Assert.assertTrue(logContainsText("2. Blur Event"));
73 radioButtons.get(3).click();
74 // Focus event is fired
75 Assert.assertTrue(logContainsText("3. Focus Event"));
77 // move keyboard focus to the next radio button
78 radioButtons.get(3).sendKeys(Keys.ARROW_DOWN);
80 Assert.assertFalse(logContainsText("4."));
82 // select the next radio button
83 radioButtons.get(4).sendKeys(Keys.TAB);
84 // focus has gone away
85 waitUntil(driver -> logContainsText("4. Blur Event"), 5);