summaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/home/HomePage.java
blob: b4f17dd255ff650007bb6c5d2b3d4828ffa09858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation
 *  ================================================================================
 *  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.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.onap.sdc.frontend.ci.tests.pages.home;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onap.sdc.frontend.ci.tests.pages.home.HomePage.XpathSelector.ADD_BUTTONS_AREA;
import static org.onap.sdc.frontend.ci.tests.pages.home.HomePage.XpathSelector.ADD_SERVICE_BTN;

import lombok.Getter;
import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
import org.onap.sdc.frontend.ci.tests.pages.ServiceCreatePage;
import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

/**
 * Represents the user home page
 */
public class HomePage extends AbstractPageObject {

    @Getter
    private final TopNavComponent topNavComponent;

    public HomePage(final WebDriver webDriver, final TopNavComponent topNavComponent) {
        super(webDriver);
        this.topNavComponent = topNavComponent;
    }

    @Override
    public void isLoaded() {
        topNavComponent.isLoaded();
        assertThat("The Home tab should be selected", topNavComponent.isHomeSelected(), is(true));
    }

    /**
     * Clicks on the add service button.
     *
     * @return the following service create page
     */
    public ServiceCreatePage clickOnAddService() {
        hoverToAddArea();
        final By addServiceBtnLocator = By.xpath(ADD_SERVICE_BTN.getXpath());
        waitForElementVisibility(addServiceBtnLocator);
        final WebElement addServiceBtn = findElement(addServiceBtnLocator);
        addServiceBtn.click();
        return new ServiceCreatePage(webDriver);
    }

    /**
     * Hovers to the Add buttons area.
     *
     * @return the add buttons area element
     */
    public WebElement hoverToAddArea() {
        final Actions actions = new Actions(webDriver);
        final By addButtonsAreaLocator = By.xpath(ADD_BUTTONS_AREA.getXpath());
        final WebElement addButtonsAreaElement = findElement(addButtonsAreaLocator);
        actions.moveToElement(addButtonsAreaElement).build().perform();
        return addButtonsAreaElement;
    }

    /**
     * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
     */
    public enum XpathSelector {
        ADD_SERVICE_BTN("createServiceButton", "//*[@data-tests-id='%s']"),
        ADD_BUTTONS_AREA("AddButtonsArea", "//*[@data-tests-id='%s']");

        private final String id;
        private final String xpathFormat;

        XpathSelector(final String id, final String xpathFormat) {
            this.id = id;
            this.xpathFormat = xpathFormat;
        }

        public String getId() {
            return id;
        }

        public String getXpath() {
            return String.format(xpathFormat, id);
        }
    }
}