aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/PropertiesAssignmentPage.java
blob: 629753f077cb87596f31de2de141521e63731390 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.pages;


import com.aventstack.extentreports.Status;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.PropertiesAssignmentScreen;
import org.openecomp.sdc.ci.tests.exception.PropertiesAssignmentPageException;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropertiesAssignmentPage {

    private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesAssignmentPage.class);

    private PropertiesAssignmentPage() {

    }

    public static void clickOnInputTab() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Input Tab");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUTS_TAB.getValue());
    }

    public static void clickOnPropertiesTab() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Properties Tab");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.PROPERTIES_TAB.getValue());
    }

    public static void clickOnCompositionRightTab() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Composition Right Tab");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.COMPOSITION_TAB.getValue());
    }

    public static void clickOnPropertyStructureRightTab() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Property Structure Right Tab");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.PROPERTY_STRUCTURE_TAB.getValue());
    }

    public static void clickOnDeclareButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Declare Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DECLARE_BUTTON.getValue());
    }

    public static void clickOnSaveButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_BUTTON.getValue());
    }

    public static void clickOnDiscardButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Discard Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DISCARD_BUTTON.getValue());
    }

    public static void clickOnDialogSaveButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save Button in Dialog Popup");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_SAVE.getValue());
    }

    public static void clickOnDialogDiscardButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Discard Button in Dialog Popup");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_DISCARD.getValue());
    }

    public static void clickOnDialogCancelButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Cancel Button in Dialog Popup");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_CANCEL.getValue());
    }

    public static void clickOnEditButton(String propertyName) {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Edit button ");
        GeneralUIUtils.clickOnElementByTestId(PropertyNameBuilder.buildPopupField(propertyName));
    }

    public static void clickOnSetButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Set button in a property popup ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_SET_BUTTON.getValue());
    }

    public static void clickOnExpandButton(String propertyName, int index) {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Expand Complex Property Button");
        GeneralUIUtils.clickOnElementByTestId(PropertyNameBuilder.buildIExpandButton(propertyName, index));
    }

    public static void findSearchBoxAndClick(final String resourceName) throws PropertiesAssignmentPageException {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in Properties");
        try {
            final WebElement searchTextbox = GeneralUIUtils
                .getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());
            searchTextbox.clear();
            searchTextbox.sendKeys(resourceName);
            GeneralUIUtils.ultimateWait();
        } catch (final Exception e) {
            final String errorMsg = String.format("Could not interact with search bar, test id '%s'",
                PropertiesAssignmentScreen.SEARCH_BOX.getValue());
            LOGGER.error(errorMsg, e);
            SetupCDTest.getExtendTest().log(Status.ERROR, errorMsg);
            throw new PropertiesAssignmentPageException(errorMsg, e);
        }

        try {
            SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", resourceName));
            GeneralUIUtils.clickOnElementByInputTestIdWithoutWait(resourceName);
            GeneralUIUtils.ultimateWait();
            GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
        } catch (final Exception e) {
            final String errorMsg = String.format("Could not click on component named '%s'", resourceName);
            LOGGER.error(errorMsg, e);
            SetupCDTest.getExtendTest().log(Status.ERROR, errorMsg);
            throw new PropertiesAssignmentPageException(errorMsg, e);
        }
    }

    private static void clickOnProperty(String propertyName) {
        SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", propertyName));
        GeneralUIUtils.clickOnElementByTestId(propertyName);
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
    }

    public static void clickOnAddValueToList(String propertyName) throws Exception {
        try {
            SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the Add To List button of %s component in Properties", propertyName));
            GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.ADD_TO_LIST_BUTTON.getValue() + propertyName);
            GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
        } catch (Exception e) {
            SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on Add To List button of component named " + propertyName);
            e.printStackTrace();
        }
    }

    public static void clickODeleteValueFromList(String propertyName, int index) throws Exception {
        try {
            SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the Delete From List button of %s component in Properties", propertyName));
            GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DELETE_FROM_LIST_BUTTON.getValue() + propertyName + "." + index);
            GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
        } catch (Exception e) {
            SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on Delete From List button of component named " + propertyName);
            e.printStackTrace();
        }
    }

    public static void clickOnDeleteInputButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Delete Input Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUT_DELETE_BUTTON.getValue());
    }

    public static void clickOnDeleteInputDialogConfirmationButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Delete Input Dialog Confirmation Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_DELETE.getValue());
    }

    public static void clickOnComponentInComposition(final String resourceName) throws Exception {
        SetupCDTest.getExtendTest()
            .log(Status.INFO, String.format("Clicking on the %s component on Properties screen", resourceName));
        try {
            GeneralUIUtils.clickOnElementByTestId(resourceName);
        } catch (final Exception e) {
            SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
            throw e;
        }
    }

    public static void findInput(String componentName, String resourceName) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + componentName + "_" + resourceName + " on Inputs screen");
        WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());
        String searchPattern = componentName + "_" + resourceName;

        searchTextbox.clear();
        searchTextbox.sendKeys(searchPattern);
        GeneralUIUtils.ultimateWait();
    }

    public static void findProperty(String resourceName) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
        WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());

        searchTextbox.clear();
        searchTextbox.sendKeys(resourceName);
        GeneralUIUtils.ultimateWait();
    }

    public static void editPropertyValue(String resourceName, String value) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
        WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(resourceName);

        clickOnProperty(resourceName);
        valueTextbox.clear();
        SetupCDTest.getExtendTest().log(Status.INFO, "Editing " + resourceName + " property on Properties screen");
        valueTextbox.sendKeys(value);
        GeneralUIUtils.ultimateWait();

    }

    public static void deletePropertyValue(String resourceName) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
        WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(resourceName);

        clickOnProperty(resourceName);
        SetupCDTest.getExtendTest().log(Status.INFO, "Deleting " + resourceName + " property on Properties screen");
        valueTextbox.sendKeys(Keys.chord(Keys.CONTROL, "a"));
        valueTextbox.sendKeys(Keys.BACK_SPACE);
        GeneralUIUtils.ultimateWait();

    }


    public static Boolean isPropertyChecked(String resourceName) {
//		TODO add better implementation for css string
        GeneralUIUtils.ultimateWait();
        Boolean isDisabled = GeneralUIUtils.checkForDisabledAttributeInHiddenElement("checkbox[data-tests-id='" + resourceName + "'] input");
        SetupCDTest.getExtendTest().log(Status.INFO, "Is property checkbox disabled? " + isDisabled);
        return isDisabled;
    }

    public static boolean isButtonDisabled(String dataTestId) {
        return GeneralUIUtils.checkForDisabledAttribute(dataTestId);
    }

    public static String selectBooleanPropertyValue(String propertyName, String propertyValue) {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + propertyName + " property on Properties screen");
        String actualPropertyValue = null;
        try {
            actualPropertyValue = GeneralUIUtils.getSelectedElementFromDropDown(propertyName).getText();
        } catch (NoSuchElementException e) {
            SetupCDTest.getExtendTest().log(Status.INFO, "#selectBooleanPropertyValue - Failed to get selected boolean property value ");
            SetupCDTest.getExtendTest().log(Status.INFO, e);
        }
        try {
            GeneralUIUtils.getSelectList(propertyValue, propertyName);
        } catch (NoSuchElementException e) {
            e.printStackTrace();
        }
        return actualPropertyValue;
    }


    //Filter Actions
    public static void clickOnFilterButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter button ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_BUTTON.getValue());
    }

    public static void clickOnFilterAllCheckbox() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter All Checkbox ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_ALL.getValue());
    }

    public static void clickOnFilterCPCheckbox() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter CP Checkbox ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_CP.getValue());
    }

    public static void clickOnFilterVfcCheckbox() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter VFC Checkbox ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_VFC.getValue());
    }

    public static void clickOnFilterVlCheckbox() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter VL Checkbox ");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_VL.getValue());
    }

    public static void clickOnFilterApplyButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Apply Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_APPLY_BUTTON.getValue());
    }

    public static void clickOnFilterCloseButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Close Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CLOSE_BUTTON.getValue());
    }

    public static void clickOnFilterClearAllButton() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Clear All Button");
        GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.CLEAR_FILTER_BUTTON.getValue());
    }

    public static void findFilterBoxAndClick(String resourceName) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property in Properties table");
        WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.FILTER_BOX.getValue());
        try {
            searchTextbox.clear();
            searchTextbox.sendKeys(resourceName);
            GeneralUIUtils.ultimateWait();
        } catch (Exception e) {
            SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
            e.printStackTrace();
        }

    }


}