From bb2e224a79026b5085a09b38faedf8c9d62b448d Mon Sep 17 00:00:00 2001 From: Heikki Ohinmaa Date: Fri, 25 Jul 2014 18:59:01 +0300 Subject: [PATCH] NotificationsWaiAria test rewrite to TB3. Change-Id: Ifd83ec30c02e7c39eb8d3d4b1c1cf058da939ce1 --- .../notification/NotificationsWaiAria.html | 107 --------------- .../notification/NotificationsWaiAria.java | 29 ++-- .../NotificationsWaiAriaTest.java | 126 ++++++++++++++++++ 3 files changed, 144 insertions(+), 118 deletions(-) delete mode 100644 uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.html create mode 100644 uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAriaTest.java diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.html b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.html deleted file mode 100644 index fb00953e48..0000000000 --- a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - -NotificationsWaiAria - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NotificationsWaiAria
open/run/com.vaadin.tests.components.notification.NotificationsWaiAria?restartApplication
enterCharactervaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VTextField[0]Prefix:
enterCharactervaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VTextField[0]- press ESC to close
selectvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VNativeSelect[0]/domChild[0]label=ALERT
clickvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
assertElementPresentvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::Root/VNotification[0]
assertAttributevaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::Root/VNotification[0]@rolealert
assertTextxpath=//div[@class='v-Notification humanized v-Notification-humanized']//span[@class='v-assistive-device-only'][1]Prefix:
assertTextxpath=//div[@class='v-Notification humanized v-Notification-humanized']//span[@class='v-assistive-device-only'][2]- press ESC to close
closeNotificationvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::Root/VNotification[0]0,0
selectvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VNativeSelect[0]/domChild[0]label=STATUS
clickvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
assertAttributexpath=/html/body/div[2]/div@rolestatus
closeNotificationvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::Root/VNotification[0]0,0
typevaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VTextField[0]
typevaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VTextField[0]
clickvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsnotificationNotificationsWaiAria::Root/VNotification[0]/domChild[0]/domChild[0]/domChild[1]
- - diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java index 7a12168af4..e85d60d7c2 100644 --- a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java +++ b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java @@ -2,8 +2,9 @@ package com.vaadin.tests.components.notification; import com.vaadin.data.Item; import com.vaadin.server.Page; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.NotificationRole; -import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; @@ -16,10 +17,15 @@ import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; -public class NotificationsWaiAria extends TestBase { +/** + * Test UI for different roles of Notifications. + * + * @since 7.2 + * @author Vaadin Ltd + */ +public class NotificationsWaiAria extends AbstractTestUI { private static final String CAPTION = "CAPTION"; - private static final String ROLE = "ROLE"; private TextField prefix; private TextField postfix; @@ -28,9 +34,9 @@ public class NotificationsWaiAria extends TestBase { private TextArea tf; private ComboBox type; - @SuppressWarnings("deprecation") + @SuppressWarnings("unchecked") @Override - protected void setup() { + protected void setup(VaadinRequest request) { prefix = new TextField("Prefix", "Info"); addComponent(prefix); @@ -53,16 +59,16 @@ public class NotificationsWaiAria extends TestBase { type.setItemCaptionPropertyId(CAPTION); - Item item = type.addItem(Notification.TYPE_HUMANIZED_MESSAGE); + Item item = type.addItem(Notification.Type.HUMANIZED_MESSAGE); item.getItemProperty(CAPTION).setValue("Humanized"); - item = type.addItem(Notification.TYPE_ERROR_MESSAGE); + item = type.addItem(Notification.Type.ERROR_MESSAGE); item.getItemProperty(CAPTION).setValue("Error"); - item = type.addItem(Notification.TYPE_WARNING_MESSAGE); + item = type.addItem(Notification.Type.WARNING_MESSAGE); item.getItemProperty(CAPTION).setValue("Warning"); - item = type.addItem(Notification.TYPE_TRAY_NOTIFICATION); + item = type.addItem(Notification.Type.TRAY_NOTIFICATION); item.getItemProperty(CAPTION).setValue("Tray"); item = type.addItem(Notification.Type.ASSISTIVE_NOTIFICATION); @@ -81,13 +87,12 @@ public class NotificationsWaiAria extends TestBase { } @Override - protected String getDescription() { + protected String getTestDescription() { return "Generic test case for notifications"; } @Override protected Integer getTicketNumber() { - // TODO Auto-generated method stub return null; } @@ -97,6 +102,7 @@ public class NotificationsWaiAria extends TestBase { Type typeValue = (Type) type.getValue(); Notification n = new Notification(tf.getValue(), typeValue); + n.setDelayMsec(-1); n.setHtmlContentAllowed(true); NotificationConfiguration notificationConf = UI.getCurrent() .getNotificationConfiguration(); @@ -118,4 +124,5 @@ public class NotificationsWaiAria extends TestBase { n.show(Page.getCurrent()); } } + } diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAriaTest.java b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAriaTest.java new file mode 100644 index 0000000000..6b517e9887 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAriaTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.notification; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.shared.ui.ui.NotificationRole; +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Unit test class for Notification ARIA (Accessible Rich Internet Applications) + * roles. + * + * @since 7.2 + * @author Vaadin Ltd + */ +public class NotificationsWaiAriaTest extends MultiBrowserTest { + + /** + * Checks if the ARIA roles are correctly applied to Notification. + * + * @since 7.2 + * @throws Exception + */ + @Test + public void notificationTest() throws Exception { + openTestURL(); + + TextFieldElement prefix = $(TextFieldElement.class).first(); + TextFieldElement postfix = $(TextFieldElement.class).get(1); + NativeSelectElement type = $(NativeSelectElement.class).first(); + ButtonElement show = $(ButtonElement.class).first(); + + prefix.clear(); + prefix.sendKeys("Prefix:"); + + postfix.clear(); + postfix.sendKeys("- press ESC to close"); + + type.selectByText(NotificationRole.ALERT.toString()); + + show.click(); + waitForElementPresent(By.className("v-Notification")); + + NotificationElement notification = $(NotificationElement.class).first(); + + String text = notification.getAttribute("role"); + Assert.assertTrue("Expected attribute 'role' to equal 'alert', found " + + text, text.equals("alert")); + + text = getHiddenText(notification.findElements( + By.className("v-assistive-device-only")).get(0)); + Assert.assertTrue("Expected 'Prefix:', found " + text, + text.equals("Prefix:")); + + text = getHiddenText(notification.findElements( + By.className("v-assistive-device-only")).get(1)); + Assert.assertTrue("Expected '- press ESC to close', found " + text, + text.equals("- press ESC to close")); + + try { + notification.closeNotification(); + } catch (Exception e) { + } + + type.selectByText("STATUS"); + + show.click(); + waitForElementPresent(By.className("v-Notification")); + + notification = $(NotificationElement.class).first(); + + text = notification.getAttribute("role"); + Assert.assertTrue("Expected attribute 'role' to equal 'status', found " + + text, text.equals("status")); + + try { + notification.closeNotification(); + } catch (Exception e) { + } + + prefix.clear(); + postfix.clear(); + + show.click(); + waitForElementPresent(By.className("v-Notification")); + + WebElement element; + try { + element = getDriver() + .findElement( + By.vaadin("Root/VNotification[0]/domChild[0]/domChild[0]/domChild[1]")); + } catch (Exception e) { + element = null; + } + Assert.assertNull( + "Notification shouldn't have assistive-device-only spans", + element); + + } + + private String getHiddenText(WebElement element) { + return (String) getTestBenchCommandExecutor().executeScript( + "return arguments[0].innerHTML", element); + } +} -- 2.39.5