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.

NotificationElement.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.testbench.elements;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import org.openqa.selenium.By;
  20. import org.openqa.selenium.TimeoutException;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.support.ui.ExpectedConditions;
  23. import org.openqa.selenium.support.ui.WebDriverWait;
  24. import com.vaadin.testbench.elementsbase.AbstractElement;
  25. import com.vaadin.testbench.elementsbase.ServerClass;
  26. @ServerClass("com.vaadin.ui.Notification")
  27. public class NotificationElement extends AbstractElement {
  28. /**
  29. * Closes a notification
  30. *
  31. * @throws TimeoutException
  32. * If a notification can not be closed and the timeout expires.
  33. */
  34. public void close() {
  35. click();
  36. WebDriverWait wait = new WebDriverWait(getDriver(), 10);
  37. wait.until(ExpectedConditions
  38. .not(ExpectedConditions.presenceOfAllElementsLocatedBy(
  39. By.className("v-Notification"))));
  40. }
  41. /**
  42. * Returns the caption of the Notification element
  43. *
  44. * @since
  45. * @return the caption of the Notification element
  46. */
  47. public String getCaption() {
  48. WebElement popup = findElement(By.className("popupContent"));
  49. WebElement caption = popup.findElement(By.tagName("h1"));
  50. return caption.getText();
  51. }
  52. /**
  53. * Returns description of the Notification element
  54. *
  55. * @return description of the Notification element
  56. */
  57. public String getDescription() {
  58. WebElement popup = findElement(By.className("popupContent"));
  59. WebElement caption = popup.findElement(By.tagName("p"));
  60. return caption.getText();
  61. }
  62. /**
  63. * Returns type of the Notification element
  64. *
  65. * @return type of the Notification element
  66. */
  67. public String getType() {
  68. // The info about notification type can be taken only from css rule of
  69. // the notification
  70. // To get type we search for css rules which represent notification type
  71. // This map maps css style rule to type of a notification
  72. HashMap<String, String> styleToTypeMap = initStyleToTypeMap();
  73. for (Map.Entry<String, String> entry : styleToTypeMap.entrySet()) {
  74. String notifType = entry.getKey();
  75. // Check notification has css style which describes notification
  76. // type
  77. if (getAttribute("class").contains(notifType)) {
  78. return entry.getValue();
  79. }
  80. }
  81. return "";
  82. }
  83. private HashMap<String, String> initStyleToTypeMap() {
  84. HashMap<String, String> styleToType = new HashMap<String, String>();
  85. styleToType.put("v-Notification-error", "error");
  86. styleToType.put("v-Notification-warning", "warning");
  87. styleToType.put("v-Notification-humanized", "humanized");
  88. styleToType.put("v-Notification-tray", "tray_notification");
  89. return styleToType;
  90. }
  91. }