2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.ci.tests.utilities;
22 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.support.ui.ExpectedConditions;
25 import org.openqa.selenium.support.ui.WebDriverWait;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import static org.openecomp.sdc.ci.tests.utilities.NotificationHelper.XpathSelector.MAIN_CONTAINER_DIV;
30 import static org.openecomp.sdc.ci.tests.utilities.NotificationHelper.XpathSelector.MESSAGE_CONTENT_DIV;
31 import static org.openecomp.sdc.ci.tests.utilities.NotificationHelper.XpathSelector.MESSAGE_SUCCESS_DIV;
33 public class NotificationHelper {
35 private static final Logger LOGGER = LoggerFactory.getLogger(NotificationHelper.class);
37 public void waitForNotification(final NotificationType notificationType, final int timeout) {
38 final By messageLocator = getMessageLocator(notificationType);
39 waitForVisibility(messageLocator, timeout);
40 waitForInvisibility(messageLocator, timeout);
43 private By getMessageLocator(final NotificationType notificationType) {
44 return By.xpath(getMessageXpath(notificationType));
47 private String getMessageXpath(final NotificationType notificationType) {
48 if (notificationType == NotificationType.SUCCESS) {
49 return String.format("%s%s%s", MAIN_CONTAINER_DIV.getXpath(), MESSAGE_CONTENT_DIV.getXpath(), MESSAGE_SUCCESS_DIV.getXpath());
52 LOGGER.warn("Xpath for NotificationType {} not yet implemented. Returning empty Xpath.", notificationType);
56 private void waitForVisibility(By messageLocator, final int timeout) {
58 .until(ExpectedConditions.visibilityOfElementLocated(messageLocator));
61 private void waitForInvisibility(By messageLocator, int timeout) {
63 .until(ExpectedConditions.invisibilityOfElementLocated(messageLocator));
66 private WebDriverWait getWait(final int timeout) {
67 return new WebDriverWait(DriverFactory.getDriver(), timeout);
70 public enum XpathSelector {
71 MAIN_CONTAINER_DIV("notification-container", "//div[@class='%s']"),
72 MESSAGE_CONTENT_DIV("msg-content", "//div[@class='%s']"),
73 MESSAGE_SUCCESS_DIV("message", "//div[contains(@class, '%s') and contains(text(),'successfully')]");
75 private final String id;
76 private final String xpath;
78 XpathSelector(String id, String xpath) {
83 public String getId() {
87 public String getXpath() {
88 return String.format(xpath, id);
92 public enum NotificationType {