Fix wait for loader after NewServiceInstanceTest popups-close
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / DrawingBoardTest.java
1 package vid.automation.test.test;
2
3
4 import static org.testng.AssertJUnit.assertFalse;
5 import static vid.automation.test.Constants.DrawingBoard.AVAILABLE_MODELS_TREE;
6 import static vid.automation.test.Constants.DrawingBoard.BACK_BUTTON;
7 import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_BUTTON_HEADER;
8 import static vid.automation.test.Constants.DrawingBoard.CONTEXT_MENU_HEADER_EDIT_ITEM;
9 import static vid.automation.test.Constants.DrawingBoard.DEFAULT_SERVICE_NAME;
10 import static vid.automation.test.Constants.DrawingBoard.DRAWING_BOARD_TREE;
11 import static vid.automation.test.Constants.DrawingBoard.SEARCH_LEFT_TREE;
12 import static vid.automation.test.Constants.DrawingBoard.SERVICE_QUANTITY;
13 import static vid.automation.test.infra.ModelInfo.macroDrawingBoardComplexService;
14 import static vid.automation.test.infra.ModelInfo.macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails;
15
16 import com.google.common.collect.ImmutableList;
17 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
18 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
19 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2;
20 import org.openqa.selenium.WebDriver;
21 import org.testng.Assert;
22 import org.testng.annotations.AfterClass;
23 import org.testng.annotations.BeforeMethod;
24 import org.testng.annotations.Test;
25 import vid.automation.test.Constants;
26 import vid.automation.test.infra.Click;
27 import vid.automation.test.infra.Exists;
28 import vid.automation.test.infra.Get;
29 import vid.automation.test.infra.Input;
30 import vid.automation.test.infra.ModelInfo;
31 import vid.automation.test.infra.SelectOption;
32 import vid.automation.test.infra.Wait;
33 import vid.automation.test.model.User;
34 import vid.automation.test.sections.BrowseASDCPage;
35 import vid.automation.test.sections.DrawingBoardPage;
36 import vid.automation.test.sections.VidBasePage;
37
38 public class DrawingBoardTest extends VidBaseTestCase {
39
40     private DrawingBoardPage drawingBoardPage = new DrawingBoardPage();
41     private String loadedServiceModelId = macroDrawingBoardComplexService.modelVersionId;
42
43     @Override
44     protected UserCredentials getUserCredentials() {
45         String userName = Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA;
46         User user = usersService.getUser(userName);
47         return new UserCredentials(user.credentials.userId, user.credentials.password, userName, "", "");
48     }
49
50     public DrawingBoardTest() {
51     }
52
53     @AfterClass
54     private void goOutFromIframe() {
55         VidBasePage.goOutFromIframe();
56     }
57
58
59     @BeforeMethod
60     private void setNewServiceToDefault() throws Exception {
61         final String currentUrl = getDriver().getCurrentUrl();
62         System.out.println("currentUrl in @BeforeMethod setNewServiceToDefault: " + currentUrl);
63
64         if (currentUrl.endsWith("/servicePlanning?serviceModelId=" + macroDrawingBoardComplexService.modelVersionId)) {
65             getDriver().navigate().refresh();
66         } else {
67             setNewService(macroDrawingBoardComplexService, null);
68         }
69         GeneralUIUtils.ultimateWait();
70         drawingBoardPage.goToIframe();
71     }
72
73     private void setNewService(ModelInfo modelInfo, String instanceName) {
74         goOutFromIframe();
75         BrowseASDCPage browseASDCPage = new BrowseASDCPage();
76
77         prepareServicePreset(modelInfo.zipFileName, modelInfo.modelVersionId);
78
79         loadServicePopup(modelInfo.modelVersionId);
80
81         if (instanceName != null) {
82             Input.text(instanceName,Constants.BrowseASDC.NewServicePopup.INSTANCE_NAME);
83         }
84
85         Wait.waitByClassAndText("subscriber","",3);
86         GeneralUIUtils.ultimateWait();
87         VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
88
89         GeneralUIUtils.ultimateWait();
90         GeneralUIUtils.ultimateWait();
91         browseASDCPage.selectProductFamily("e433710f-9217-458d-a79d-1c7aff376d89");
92         GeneralUIUtils.ultimateWait();
93         String serviceType = "TYLER SILVIA";
94 //        Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
95         browseASDCPage.selectServiceTypeByName(serviceType);
96         GeneralUIUtils.ultimateWait();
97         GeneralUIUtils.ultimateWait();
98         browseASDCPage.selectLcpRegion("hvf6");
99         browseASDCPage.selectTenant("3f21eeea6c2c486bba31dab816c05a32");
100         Click.onFirstSelectOptionByTestId(Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID);
101
102         browseASDCPage.selectAicZone("NFT1");
103         Click.onFirstSelectOptionByTestId(Constants.OwningEntity.PROJECT_SELECT_TEST_ID);
104
105         // select mandatory field
106         Click.onFirstSelectOptionByTestId(Constants.ServiceModelInfo.ROLLBACK_ON_FAILURE_TEST_ID);
107
108         Click.byTestId("form-set");
109         VidBasePage.goOutFromIframe();
110     }
111
112     private void prepareServicePreset(String zipFileName, String serviceModelId) {
113         String modelInvariantId = "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0";
114         String subscriberId = "e433710f-9217-458d-a79d-1c7aff376d89";
115         registerExpectationForServiceDeployment(
116                 ImmutableList.of(
117                         new ModelInfo(serviceModelId, modelInvariantId, zipFileName)
118                 ),
119                 subscriberId, new PresetMSOCreateServiceInstanceGen2());
120     }
121
122     static final String leftTreeNodeName = "VF_vGeraldine 0";
123     static final String leftTreeNodeNameWithoutChildren = "Port Mirroring Configuration By Policy 0";
124     static final String[] leftTreeNodeChildren = {"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1", "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2", "vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0"};
125     static final String[] leftTreeInitialElements = new String[]{"VNF", "VF_vGeraldine 0", "1", "C","Port Mirroring Configuration By Policy 0"};
126
127     static final String rightTreeNodeName = "d6557200-ecf2-4641-8094-5393ae3aae60-VF_vGeraldine 0";
128     static final String rightTreeNodeNameWithoutChildren = "ddc3f20c-08b5-40fd-af72-c6d14636b986-ExtVL 0";
129     static final String[] rightTreeNodeChildren = {"522159d5-d6e0-4c2a-aa44-5a542a12a830-vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1", "41708296-e443-4c71-953f-d9a010f059e1-vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2", "a27f5cfc-7f12-4f99-af08-0af9c3885c87-vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0"};
130
131     private static final String EMPTY_BOARD_TITLE = "Please add objects (VNF a-la-carteVNFs, network, modules etc.) from the left tree to design the service instance";
132     private static final String EMPTY_BOARD_SUBTITLE = "Once done, click Deploy to start instantiation";
133
134
135     static final String[] rightTreeInitialElements = new String[]{
136         "Vnf:",
137         "vnf instance 1",
138         "Vf Module:",
139         "vf module instance 1",
140         "Vf Module:",
141         "vf module instance 2",
142         "Vf Module",
143         "Configuration:",
144         "configuration instance 1",
145         "Network:",
146         "network instance 1"};
147
148     @Test
149     private void expandCollapseLeftTreeByClickOnRow() {
150         Wait.byText(leftTreeNodeName);
151         drawingBoardPage.expandTreeByClickingNode(leftTreeNodeName, leftTreeNodeChildren);
152         //should chec   king with Golan if click also collapse
153         //drawingBoardPage.collapseTreeByClickingNode(leftTreeNodeName, leftTreeNodeChildren)));
154         drawingBoardPage.verifyNonCollapsableTreeByClickingNode(leftTreeNodeName, leftTreeNodeChildren);
155     }
156
157     @Test
158     private void expandCollapseLeftTreeByClickOnIcon() {
159         drawingBoardPage.expandFirstItemInTreeByExpanderIcon(AVAILABLE_MODELS_TREE, leftTreeNodeChildren);
160         drawingBoardPage.collapseFirstItemInTreeByCollapseIcon(AVAILABLE_MODELS_TREE, leftTreeNodeChildren);
161     }
162
163     @Test
164     private void checkInitialStateLeftTree() {
165         drawingBoardPage.assertInitalTextOfTree(AVAILABLE_MODELS_TREE, leftTreeInitialElements);
166     }
167
168 //    @Test
169 //    private void checkAddButton() {
170 //        drawingBoardPage.checkAddButton(leftTreeRootElements);
171 //    }
172
173     @Test
174     private void checkLeafNodeLeftTreeHasNoExpander() {
175         drawingBoardPage.checkLeafNodeHasNoExpander(leftTreeNodeNameWithoutChildren);
176     }
177
178
179     @Test(groups = { "underDevelopment" })
180     private void collapseExpandRightTreeByClickOnRow() {
181         drawingBoardPage.collapseFirstItemInTreeByCollapseIcon(DRAWING_BOARD_TREE, rightTreeNodeChildren);
182         //should checking with Golan if click also collapse
183         //drawingBoardPage.collapseTreeByClickingNode(rightTreeNodeName, rightTreeNodeChildren)));
184         drawingBoardPage.expandTreeByClickingNode(rightTreeNodeName, rightTreeNodeChildren);
185     }
186
187     @Test(groups = { "underDevelopment" })
188     private void collapseExpandRightTreeByClickOnIcon() {
189         drawingBoardPage.collapseFirstItemInTreeByCollapseIcon(DRAWING_BOARD_TREE, rightTreeNodeChildren);
190         drawingBoardPage.expandFirstItemInTreeByExpanderIcon(DRAWING_BOARD_TREE, rightTreeNodeChildren);
191     }
192
193     @Test(groups = { "underDevelopment" })
194     private void checkInitialStateRightTree() {
195         drawingBoardPage.assertInitalTextOfTree(DRAWING_BOARD_TREE, rightTreeInitialElements);
196     }
197
198     @Test(groups = { "underDevelopment" })
199     private void checkLeafNodeRightTreeHasNoExpander() {
200         drawingBoardPage.checkLeafNodeHasNoExpander(rightTreeNodeNameWithoutChildren);
201     }
202
203     @Test(groups = { "underDevelopment" })
204     private void clickRightTreeNode_verifyLeftTreeNodeIsBlueAndExpanded() {
205
206         //// setup
207         drawingBoardPage.checkNodesVisible(leftTreeNodeChildren, false);
208
209         clickAndVerifyCrossTreeSync(
210                 DrawingBoardTest.rightTreeNodeName,
211                 DrawingBoardTest.leftTreeNodeName,
212                 DrawingBoardTest.leftTreeNodeChildren
213         );
214     }
215
216     @Test(groups = { "underDevelopment" })
217     private void clickLeftTreeNode_verifyRightTreeNodeIsBlueAndExpanded() {
218
219         //// setup
220         drawingBoardPage.collapseFirstItemInTreeByCollapseIcon(DRAWING_BOARD_TREE, rightTreeNodeChildren);
221
222         clickAndVerifyCrossTreeSync(
223                 leftTreeNodeName,
224                 rightTreeNodeName,
225                 rightTreeNodeChildren
226         );
227     }
228
229     @Test(groups = { "underDevelopment" })
230     private void clickRightTreeChild_verifyLeftTreeChildIsBlueAndParentExpanded() {
231
232         //// setup
233         drawingBoardPage.checkNodesVisible(leftTreeNodeChildren, false);
234
235         clickAndVerifyCrossTreeSync(
236                 rightTreeNodeChildren[0],
237                 leftTreeNodeChildren[0],
238                 leftTreeNodeChildren
239         );
240     }
241
242     @Test(groups = { "underDevelopment" })
243     private void clickLeftTreeChild_verifyRightTreeChildIsBlueAndParentExpanded() {
244
245         //// setup
246         drawingBoardPage.expandTreeByClickingNode(leftTreeNodeName, leftTreeNodeChildren);
247         drawingBoardPage.collapseFirstItemInTreeByCollapseIcon(DRAWING_BOARD_TREE, rightTreeNodeChildren);
248
249         clickAndVerifyCrossTreeSync(
250                 leftTreeNodeChildren[0],
251                 rightTreeNodeChildren[0],
252                 rightTreeNodeChildren
253         );
254     }
255
256     private void clickAndVerifyCrossTreeSync(String clickOn, String verifyHighlight, String[] verifyVisible) {
257         //// test
258         drawingBoardPage.clickNode(clickOn);
259
260         //// verify
261         drawingBoardPage.checkNodesHighlighted(new String[]{verifyHighlight});
262         drawingBoardPage.checkNodesVisible(verifyVisible, true);
263     }
264
265
266     /*
267       + Search box
268         - exists
269         - works (skimmy)
270     */
271     @Test
272     private void insertTestInSerachBox_verifyMatchesMarkedAndVisible() {
273         Wait.byText("vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1");
274         drawingBoardPage.checkSearch();
275
276         final String searchTerm = "Vgeraldine..vflorence";
277         GeneralUIUtils.setWebElementByTestId(SEARCH_LEFT_TREE, searchTerm);
278         drawingBoardPage.checkNodesVisibleAndMatchIsHighlighted(searchTerm,"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1", "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2");
279     }
280
281     /*
282       + Context menu
283         - click opens popup
284         - click closes popup
285     */
286     @Test(groups = { "underDevelopment" })
287     private void clickOnParentEllipsis_menuIsVisible() {
288         drawingBoardPage.checkContextMenu(rightTreeNodeNameWithoutChildren);
289     }
290
291     @Test(groups = { "underDevelopment" })
292     private void clickOnNodeEllipsis_menuIsVisible() {
293         drawingBoardPage.checkContextMenu(rightTreeNodeChildren[1]);
294     }
295
296     /*
297       + Tooltip
298         - hover: text appears
299         - again for "child"
300         - hover on no-icon: text does not appear
301      */
302     @Test(groups = { "underDevelopment" })
303     private void hoverAboveParentAlert_verifyDescriptionAppears() {
304         drawingBoardPage.showTooltipByHoverAboveAlertIcon(rightTreeNodeName);
305     }
306
307     @Test(groups = { "underDevelopment" })
308     private void hoverAboveNodeAlert_verifyDescriptionAppears() {
309         drawingBoardPage.showTooltipByHoverAboveAlertIcon(rightTreeNodeChildren[1]);
310     }
311
312     @Test
313     private void clickOnHeaderEllipsis_menuIsVisible() {
314         final String contextMenu = CONTEXT_MENU_HEADER_EDIT_ITEM;
315         drawingBoardPage.checkThatContextMenuNotExist(contextMenu);
316         Click.byTestId(CONTEXT_MENU_BUTTON_HEADER);
317         drawingBoardPage.checkThatContextMenuExist(contextMenu);
318     }
319
320     private void setAndAssertServiceWithName(String instanceName){
321         goOutFromIframe();
322         setNewService(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, instanceName);
323         GeneralUIUtils.ultimateWait();
324         drawingBoardPage.goToIframe();
325         drawingBoardPage.checkServiceInstanceName(instanceName);
326     }
327
328
329
330     @Test
331     private void editPopup_quantityNumberAndNameAreUpdated() {
332         String initialInstanceName = "MyInstanceName";
333         String updatedInstanceName = "UpdatedInstanceName";
334         setAndAssertServiceWithName(initialInstanceName);
335         final int updatedQuantity = 10;
336         Click.byTestId(CONTEXT_MENU_BUTTON_HEADER);
337         Click.byTestId(CONTEXT_MENU_HEADER_EDIT_ITEM);
338         Assert.assertTrue(Exists.byId("instance-popup"), "context menu should not appear");
339         GeneralUIUtils.ultimateWait();
340         SelectOption.byIdAndVisibleText("quantity-select", String.valueOf(updatedQuantity));
341         Input.replaceText(updatedInstanceName,Constants.BrowseASDC.NewServicePopup.INSTANCE_NAME );
342         Click.byTestId(Constants.BrowseASDC.NewServicePopup.SET_BUTTON);
343         GeneralUIUtils.ultimateWait();
344         drawingBoardPage.checkQuantityNumberIsCorrect(updatedQuantity);
345         drawingBoardPage.checkServiceInstanceName(updatedInstanceName);
346     }
347
348     @Test
349     private void cancelEditPopup_quantityNumberAndNameNotUpdated() {
350         String initialInstanceName = "MyInstanceName";
351         String updatedInstanceName = "UpdatedInstanceName";
352         setAndAssertServiceWithName(initialInstanceName);
353         final int updatedQuantity = 10;
354         String initialQuantity = Get.byTestId(SERVICE_QUANTITY).getText();
355         Click.byTestId(CONTEXT_MENU_BUTTON_HEADER);
356         Click.byTestId(CONTEXT_MENU_HEADER_EDIT_ITEM);
357         Assert.assertTrue(Exists.byId("instance-popup"), "context menu should not appear");
358         GeneralUIUtils.ultimateWait();
359         SelectOption.byIdAndVisibleText("quantity-select", String.valueOf(updatedQuantity));
360         Input.replaceText(updatedInstanceName,Constants.BrowseASDC.NewServicePopup.INSTANCE_NAME );
361         Click.byTestId(Constants.BrowseASDC.NewServicePopup.CANCEL_BUTTON);
362         GeneralUIUtils.ultimateWait();
363         drawingBoardPage.checkQuantityNumberIsCorrect(Integer.valueOf(initialQuantity));
364         drawingBoardPage.checkServiceInstanceName(initialInstanceName);
365     }
366
367
368     @Test
369     private void checkHeader_verifyElementsExist(){
370         drawingBoardPage.checkExistsAndEnabled(BACK_BUTTON);
371         drawingBoardPage.checkServiceInstanceName(DEFAULT_SERVICE_NAME);
372         drawingBoardPage.checkQuantityNumberIsCorrect(1);
373         drawingBoardPage.checkExistsAndEnabled(CONTEXT_MENU_BUTTON_HEADER);
374         assertFalse(Get.byTestId("orchStatusLabel").isDisplayed());
375         assertFalse(Get.byTestId("orchStatusValue").isDisplayed());
376     }
377
378     private void assertResultsInBrowseAsdcPage(){
379         goOutFromIframe();
380         BrowseASDCPage browseASDCPage = new BrowseASDCPage();
381         browseASDCPage.assertSearchFilterValue(loadedServiceModelId);
382     }
383
384     @Test
385     private void BackButtonWithCancel_verifyStayInTheSamePage(){
386         String currentUrl = getCurrentUrl();
387         Click.byTestId(BACK_BUTTON);
388         Click.byTestId(Constants.DrawingBoard.CANCEL_BUTTON);
389         String newUrl = getCurrentUrl();
390         org.testng.Assert.assertEquals(currentUrl, newUrl);
391     }
392
393     private String getCurrentUrl(){
394         WebDriver driver = GeneralUIUtils.getDriver();
395         return driver.getCurrentUrl();
396     }
397
398     @Test
399     private void BackButton_verifyReturnToSearchResults(){
400         Click.byTestId(BACK_BUTTON);
401         Click.byTestId(Constants.DrawingBoard.STOP_INSTANTIATION_BUTTON);
402         assertResultsInBrowseAsdcPage();
403     }
404
405 }
406