From 269ce1beac0fb164cada94342654e96ccfe0425f Mon Sep 17 00:00:00 2001 From: Mehdi Javan <32511762+mehdi-vaadin@users.noreply.github.com> Date: Wed, 19 Sep 2018 09:20:04 +0300 Subject: Fix/focus inside window chrome (#11142) Fixes #11087 --- .../tests/components/window/InitialFocusTest.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 uitest/src/test/java/com/vaadin/tests/components/window/InitialFocusTest.java (limited to 'uitest/src/test/java') diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/InitialFocusTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/InitialFocusTest.java new file mode 100644 index 0000000000..a6ab48803c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/window/InitialFocusTest.java @@ -0,0 +1,54 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +public class InitialFocusTest extends MultiBrowserTest { + /** + * To test an implementation of + * {@code com.google.gwt.user.client.ui.Focusable} which is nameField of + * TextField type + */ + @Test + public void window_callingFocusNameField_nameFieldShouldGetFocused() { + openTestURL(); + WebElement openWindowButton = findElement( + By.id(InitialFocus.FOCUS_NAME_BUTTON_ID)); + openWindowButton.click(); + waitForElementPresent(By.id(InitialFocus.NAME_FIELD_ID)); + WebElement focusedElement = getFocusedElement(); + Assert.assertNotNull( + "Name TextField should have focus while focusedElement is null.", + focusedElement); + String focusedElementId = focusedElement.getAttribute("id"); + Assert.assertEquals( + "Name TextField should have focus while " + focusedElementId + + " has focus.", + InitialFocus.NAME_FIELD_ID, focusedElementId); + } + + /** + * To test an implementation of {@code com.vaadin.client.Focusable} which is + * genderField of ComboBox type + */ + @Test + public void window_callingFocusGenderField_genderFieldShouldGetFocused() { + openTestURL(); + WebElement openWindowButton = findElement( + By.id(InitialFocus.FOCUS_GENDER_BUTTON_ID)); + openWindowButton.click(); + waitForElementPresent(By.id(InitialFocus.GENDER_FIELD_ID)); + WebElement focusedElement = getFocusedElement(); + Assert.assertNotNull( + "Gender ComboBox should have focus while focusedElement is null.", + focusedElement); + ComboBoxElement genderField = $(ComboBoxElement.class).first(); + Assert.assertEquals( + "Gender ComboBox should have focus while another element has focus.", + genderField.getInputField(), focusedElement); + } +} -- cgit v1.2.3