17ddae194f8a4f0ed9625baf68a80a6c9140e3d7
[sdc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
21
22 import static org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage.XpathSelector.DATA_TABLE_BODY;
23 import static org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage.XpathSelector.DOWNLOAD_LINK;
24 import static org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage.XpathSelector.MAIN_DIV;
25 import static org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage.XpathSelector.TITLE_DIV;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import lombok.AllArgsConstructor;
30 import lombok.Getter;
31 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.WebDriver;
34 import org.openqa.selenium.WebElement;
35
36 public class ToscaArtifactsPage extends AbstractPageObject {
37
38     private WebElement wrappingElement;
39     private WebElement artifactsTableBody;
40     private final List<String> downloadedArtifactList = new ArrayList<>();
41
42     public ToscaArtifactsPage(final WebDriver webDriver) {
43         super(webDriver);
44     }
45
46     @Override
47     public void isLoaded() {
48         wrappingElement = waitForElementVisibility(By.xpath(MAIN_DIV.getXpath()), 5);
49         waitForElementVisibility(By.xpath(TITLE_DIV.getXpath()), 5);
50         artifactsTableBody = waitForElementVisibility(By.xpath(DATA_TABLE_BODY.getXpath()), 5);
51     }
52
53     public void clickOnDownload(final String artifactName) {
54         artifactsTableBody.findElement(By.xpath(DOWNLOAD_LINK.getXpath(artifactName))).click();
55     }
56
57     public void addToDownloadedArtifactList(final String downloadedArtifactName) {
58         if (downloadedArtifactName == null) {
59             return;
60         }
61         downloadedArtifactList.add(downloadedArtifactName);
62     }
63
64     public List<String> getDownloadedArtifactList() {
65         return new ArrayList<>(downloadedArtifactList);
66     }
67
68     /**
69      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
70      */
71     @AllArgsConstructor
72     public enum XpathSelector {
73         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
74         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'TOSCA Artifacts')]"),
75         DATA_TABLE_BODY("//datatable-body"),
76         DOWNLOAD_LINK("//div[contains(@data-tests-id,'download_%s')]");
77
78         @Getter
79         private String id;
80
81         private final String xpathFormat;
82
83         XpathSelector(final String xpathFormat) {
84             this.xpathFormat = xpathFormat;
85         }
86
87         public String getXpath() {
88             return String.format(xpathFormat, id);
89         }
90
91         public String getXpath(final String... params) {
92             return String.format(xpathFormat, params);
93         }
94
95     }
96 }