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