Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

NotificationsWaiAriaTest.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2000-2014 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.notification;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.WebElement;
  20. import com.vaadin.data.util.converter.StringToEnumConverter;
  21. import com.vaadin.shared.ui.ui.NotificationRole;
  22. import com.vaadin.testbench.By;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.testbench.elements.NativeSelectElement;
  25. import com.vaadin.testbench.elements.NotificationElement;
  26. import com.vaadin.testbench.elements.TextFieldElement;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. /**
  29. * Unit test class for Notification ARIA (Accessible Rich Internet Applications)
  30. * roles.
  31. *
  32. * @since 7.2
  33. * @author Vaadin Ltd
  34. */
  35. public class NotificationsWaiAriaTest extends MultiBrowserTest {
  36. /**
  37. * Checks if the ARIA roles are correctly applied to Notification.
  38. *
  39. * @since 7.2
  40. * @throws Exception
  41. */
  42. @Test
  43. public void notificationTest() throws Exception {
  44. openTestURL();
  45. TextFieldElement prefix = $(TextFieldElement.class).first();
  46. TextFieldElement postfix = $(TextFieldElement.class).get(1);
  47. NativeSelectElement type = $(NativeSelectElement.class).first();
  48. ButtonElement show = $(ButtonElement.class).first();
  49. prefix.clear();
  50. prefix.sendKeys("Prefix:");
  51. postfix.clear();
  52. postfix.sendKeys("- press ESC to close");
  53. type.selectByText(StringToEnumConverter.enumToString(
  54. NotificationRole.ALERT, null));
  55. show.click();
  56. waitForElementPresent(By.className("v-Notification"));
  57. NotificationElement notification = $(NotificationElement.class).first();
  58. String text = notification.getAttribute("role");
  59. Assert.assertTrue("Expected attribute 'role' to equal 'alert', found "
  60. + text, text.equals("alert"));
  61. text = getHiddenText(notification.findElements(
  62. By.className("v-assistive-device-only")).get(0));
  63. Assert.assertTrue("Expected 'Prefix:', found " + text,
  64. text.equals("Prefix:"));
  65. text = getHiddenText(notification.findElements(
  66. By.className("v-assistive-device-only")).get(1));
  67. Assert.assertTrue("Expected '- press ESC to close', found " + text,
  68. text.equals("- press ESC to close"));
  69. notification.close();
  70. type.selectByText(StringToEnumConverter.enumToString(
  71. NotificationRole.STATUS, null));
  72. show.click();
  73. waitForElementPresent(By.className("v-Notification"));
  74. notification = $(NotificationElement.class).first();
  75. text = notification.getAttribute("role");
  76. Assert.assertTrue("Expected attribute 'role' to equal 'status', found "
  77. + text, text.equals("status"));
  78. notification.close();
  79. prefix.clear();
  80. postfix.clear();
  81. show.click();
  82. waitForElementPresent(By.className("v-Notification"));
  83. WebElement element;
  84. try {
  85. element = getDriver()
  86. .findElement(
  87. By.vaadin("Root/VNotification[0]/domChild[0]/domChild[0]/domChild[1]"));
  88. } catch (Exception e) {
  89. element = null;
  90. }
  91. Assert.assertNull(
  92. "Notification shouldn't have assistive-device-only spans",
  93. element);
  94. }
  95. private String getHiddenText(WebElement element) {
  96. return (String) getTestBenchCommandExecutor().executeScript(
  97. "return arguments[0].innerHTML", element);
  98. }
  99. }