blob: b1db197c4ef2786fdd3f2fc4bbb5998b0f13917a [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.ecomp.vid.selenium;
24
25import org.testng.annotations.AfterClass;
26import org.testng.annotations.AfterMethod;
27import org.testng.annotations.AfterSuite;
28import org.testng.annotations.BeforeClass;
29import org.testng.annotations.BeforeMethod;
30import org.testng.annotations.BeforeSuite;
31import org.testng.annotations.BeforeTest;
32import org.testng.annotations.Test;
33
34
35import org.openqa.selenium.By;
36import org.openqa.selenium.WebDriver;
37import org.openqa.selenium.WebElement;
38import org.openqa.selenium.firefox.FirefoxDriver;
39import org.openqa.selenium.ie.InternetExplorerDriver;
40import org.openqa.selenium.support.ui.Select;
41
42import java.io.FileInputStream;
43import java.io.IOException;
44import java.io.InputStream;
45import java.util.List;
46import java.util.Properties;
47import java.util.concurrent.TimeUnit;
48import org.apache.log4j.Logger;
49import org.testng.Assert;
50import org.testng.asserts.*;
51
52public class FirstClass {
53
54 WebElement loginButton;
55
56 /** The eg. */
57 String eg;
58
59 /** The login. */
60 WebElement login;
61
62 /** The pwd. */
63 WebElement pwd;
64
65 /** The log. */
66 Logger log;
67
68 /** The errormessage. */
69 WebElement errormessage;
70
71
72 /** The driver. */
73 WebDriver driver=new FirefoxDriver();
74
75
76
77 /** The config prop. */
78 private final Properties configProp = new Properties();
79
80
81 /**
82 * Instantiates a new first class.
83 */
84 private FirstClass() {
85 // TODO Auto-generated constructor stub
86 //
87 try{
88 // InputStream input =this.getClass().getClassLoader().getResourceAsStream("objectmap.properties");
89 //FileInputStream input1 = new FileInputStream("objectmap.properties");
90
91 InputStream input =new FileInputStream("objectconfig.properties");
92 System.out.println("Read all properties from file");
93 configProp.load(input);
94 System.out.println("Read all properties from file completed");
95 }
96 catch(IOException e) {
97
98 e.printStackTrace();
99 }
100 }
101
102
103 /*
104
105
106 @BeforeClass
107 public void setUp() {
108 System.out.println("*******************");
109 System.out.println("launching IE browser");
110 System.setProperty("webdriver.ie.driver", driverPath+"IEDriverServer.exe");
111 driver = new InternetExplorerDriver();
112 driver.findElement(By.className());
113 driver.manage().window().maximize();
114
115
116 login = driver.findElement(By.xpath("//input[@class='fn-ebz-text ng-pristine ng-valid']"));
117 pwd = driver.findElement(By.xpath("//input[@class='span3 ng-pristine ng-valid']"));
118 loginButton = driver.findElement(By.id("loginBtn"));
119 }
120
121
122 */
123 /**
124 * Sets the up.
125 */
126 // TODO Auto-generated method stub
127 @BeforeClass
128 public void setUp()
129 {
130
131
132 //WebDriver driver=new FirefoxDriver();
133
134 log = Logger.getLogger(FirstClass.class.getName());
135
136
137
138 // Get url
139 driver.get(configProp.getProperty("baseURL"));
140 driver.manage().window().maximize();
141
142
143 login = driver.findElement(By.xpath(configProp.getProperty("login")));
144
145 pwd = driver.findElement(By.xpath(configProp.getProperty("pwd")));
146 loginButton = driver.findElement(By.id(configProp.getProperty("loginButton")));
147 }
148
149
150 /**
151 * Empty username password.
152 */
153 @Test(priority=1)
154 public void emptyUsernamePassword()
155 {
156
157
158 //User Name and Password field is empty
159 log.info("-----VID-11 TC-8----Username and password empty");
160 loginButton.click();
161 errormessage=driver.findElement(By.xpath("//*[@id='errorInfo']/span"));
162 String errmsg= errormessage.getText();
163 //System.out.println("Error message is"+errmsg);
164 //String expected = "Invaild username or password, Please try again";
165
166 //Assert.assertEquals(errmsg,expected);
167
168 Boolean str = driver.getPageSource().contains("Invalid username or password, Please try again");
169 System.out.println(driver.getPageSource().contains("Invalid username or password, Please try again"));
170
171 if(str==true)
172 {
173 log.info("Error message validated");
174 log.info("VID-11 TC-8 PASSED");
175
176 }else
177 log.error("Failed validation");
178
179 }
180
181
182
183 /**
184 * Invalid user name.
185 */
186 @Test(priority=2)
187 public void invalidUserName()
188 {
189
190 log.info("-----VID-11 TC-6----Invalid Username and Valid Password");
191
192
193 login.sendKeys("xxx");
194 pwd.sendKeys("abc123");
195 loginButton.click();
196 try {
197 Thread.sleep(5000);
198 } catch (InterruptedException e) {
199 // TODO Auto-generated catch block
200 e.printStackTrace();
201 }
202
203 String errmsg= errormessage.getText();
204 String expected = "Invalid username or password, Please try again";
205 Assert.assertEquals(errmsg,expected);
206 //Boolean str1 = driver.getPageSource().contains("Invalid username or password, Please try again");
207 //System.out.print(str1);
208
209 log.info("VID-11 TC-6 PASSED");
210
211 }
212
213
214 /**
215 * Invalid password.
216 */
217 @Test(priority=3)
218 public void invalidPassword()
219 {
220 log.info("-----VID-11 TC-7----Valid Username and Invalid Password");
221 // Valid user name and Invalid password.
222 login.clear();
223 pwd.clear();
224 login.sendKeys("testuser");
225 pwd.sendKeys("xxx");
226 loginButton.click();
227 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
228
229
230 String errmsg= errormessage.getText();
231 String expected = "Invalid username or password, Please try again";
232 Assert.assertEquals(errmsg,expected);
233
234 //Boolean str2 = driver.getPageSource().contains("Invaild username or password, Please try again");
235 //System.out.print(str2);
236
237 log.info("VID-11 TC-7 PASSED");
238 }
239
240
241 /**
242 * Login successful.
243 */
244 @Test(priority=4)
245 public void loginSuccessful()
246 {
247 log.info("-----VID-11 TC-1----Valid Username and Valid Password");
248 //Login with valid user name and password.
249 login.clear();
250 login.sendKeys("su");
251 pwd.clear();
252 pwd.sendKeys("fusion");
253
254
255 loginButton.click();
256 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
257
258 try {
259 Thread.sleep(6000);
260 } catch (InterruptedException e) {
261 // TODO Auto-generated catch block
262 e.printStackTrace();
263 }
264 Assert.assertTrue(driver.getPageSource().contains("Search Existing Service Instances"));
265 log.info("VID-11 TC-1 PASSED");
266
267 }
268
269
270 /**
271 * Verify home page elements left pane.
272 */
273 @Test(priority=5)
274 public void verifyHomePageElementsLeftPane()
275
276 {
277
278
279 log.info("VID-10 TC 1 ");
280 //VID Home
281 log.info("VID 11 TC-2");
282 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[1]/a/span")).isDisplayed();
283 //Create New Service Instance
284 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[2]/a/span")).isDisplayed();
285
286 //Browse Service Type
287 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[3]/a/span")).isDisplayed();
288 //View Log
289 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[4]/a/span")).isDisplayed();
290
291 //Profile
292 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[5]/a/span")).isDisplayed();
293 //Admin
294 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[6]/a/span")).isDisplayed();
295 //Logout
296 driver.findElement(By.xpath("html/body/div[1]/div[1]/div/div/div[2]/div/div/div[1]/div/div/accordion/div/div[7]/a/span")).isDisplayed();
297
298 //Infrastructure Subscriber Name
299 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[1]/div/label")).isDisplayed();
300 //Infrastructure Subscriber Name Select Drop down
301 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[2]/div/select")).isDisplayed();
302 //Infrastructure Service Type
303 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[2]/td[1]/div/label")).isDisplayed();
304 //Infrastructure Service Type Select Drop down
305 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[2]/td[2]/div/select")).isDisplayed();
306 //Submit button
307 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[3]/td/div/button")).isDisplayed();
308
309 //Login Snippet Icon
310 driver.findElement(By.xpath(".//*[@class='icon-user-small login-snippet-icon']")).isDisplayed();
311
312
313 //String bodyText = driver.findElement(By.tagName("body")).getText();
314 //Assert.assertTrue("Text not found!", bodyText.contains("Search Existing Service Instances"));
315 //Assert.IsTrue(driver.getPageSource.Contains("Search Existing Service Instances"));
316
317 log.info("VID-12 TC-1");
318 Assert.assertTrue(driver.getPageSource().contains("Search Existing Service Instances"));
319 Assert.assertTrue(driver.getPageSource().contains("Please search by the Subscriber name or Service Type from below:"));
320 log.info("VID-12 TC-1 PASSED");
321 log.info("VID-10 TC 1 PASSED");
322 log.info("VID-11 TC-2 PASSED");
323 }
324
325
326 /**
327 * Disabled submit button.
328 */
329 @Test(priority=6)
330 public void disabledSubmitButton()
331 {
332 log.info("VID-12 TC-13");
333 //Assert submit button disabled.
334 Assert.assertFalse(driver.findElement(By.xpath(configProp.getProperty("submitButton"))).isEnabled());
335 log.info("VID-12 TC-13 PASSED");
336
337 }
338
339 /**
340 * Default list box value.
341 */
342 @Test(priority=7)
343 public void defaultListBoxValue()
344 {
345 log.info("VID-12 TC-2");
346
347
348 //WebElement subscribername =driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[2]/div/select"));
349
350 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
351 Select iSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown"))));
352
353
354 WebElement ielement=iSelect.getFirstSelectedOption();
355 WebElement oelement=oSelect.getFirstSelectedOption();
356 String defaultsubscribername=oelement.getText();
357 String defaultservicetype=ielement.getText();
358
359 Assert.assertEquals(defaultsubscribername,"Select Subscriber Name");
360 Assert.assertEquals(defaultservicetype,"Select Service Type");
361
362
363
364
365 //Verify Select Subscriber Name isDisplayed.
366 //driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[2]/div/select/option[1]")).isSelected();
367
368 //Verify Select Service Type isDisplayed.
369 //driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[2]/td[2]/div/select/option[1]")).isSelected();
370
371
372 log.info("VID-12 TC-2 PASSED");
373
374 }
375
376
377
378 /**
379 * Select subscriber name drop down.
380 *
381 * @throws InterruptedException the interrupted exception
382 */
383 @Test(priority=8)
384 public void selectSubscriberNameDropDown() throws InterruptedException
385 {
386 log.info("------------------VID-10 TC-2,VID-12 TC-11, VID-12 TC-9, VID 12 TC-10,VID-12 TC-6, VID 12 TC-5--------------------");
387
388
389 driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")));
390
391 driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown")));
392 Thread.sleep(5000);
393
394 //Infrastructure Subscriber Name
395 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
396
397 List <WebElement> elementCount = oSelect.getOptions();
398 log.info("Select Element Count of Service Name");
399 System.out.println(elementCount.size());
400
401
402 //Verifying getInfrastructureSubscribersList
403 log.info("VID-29 TC-1");
404 Assert.assertTrue(elementCount.size()>0);
405 log.info("VID-29 TC-1 PASSED");
406
407 oSelect.selectByIndex(2);
408 String selectedOption = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")))).getFirstSelectedOption().getText();
409
410 System.out.println("Service Name selected is " +selectedOption);
411 log.info("VID-10 TC-2 PASSED");
412
413 //Submit button is clicked
414 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
415
416
417 //Verify whether the page header is displayed "Selected Subscriber's Service Instance Details:"
418 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/h1")).isDisplayed();
419 //Assert.assertTrue(driver.getPageSource().contains("Selected Subscriber's Service Instance Details:"))
420
421
422 //Verify whether the page header is displayed "Global Customer ID"
423 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/div/table/thead/tr/th[2]/div")).isDisplayed();
424 Assert.assertTrue(driver.getPageSource().contains("Global Customer ID"));
425 Assert.assertTrue(driver.getPageSource().contains("Subscriber Name"));
426 Assert.assertTrue(driver.getPageSource().contains("Service Type"));
427 Assert.assertTrue(driver.getPageSource().contains("Service Instance ID"));
428
429 log.info("VID-12 TC-5 PASSED");
430 log.info("VID-12 TC-11 PASSED");
431
432 WebElement serviceinstancetable =driver.findElement(By.xpath("//table[@class='tablesorter tablesorter-default ng-isolate-scope']"));
433
434 List<WebElement> rows_table = serviceinstancetable.findElements(By.tagName("tr"));
435 //To calculate no of rows In table.
436 int rows_count = rows_table.size();
437
438 //Loop will execute till the last row of table.
439 for (int row=0; row<rows_count; row++){
440 //To locate columns(cells) of that specific row.
441 List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
442 //To calculate no of columns(cells) In that specific row.
443 int columns_count = Columns_row.size();
444 //System.out.println("Number of cells In Row "+row+" are "+columns_count);
445
446 //Loop will execute till the last cell of that specific row.
447 for (int column=0; column<columns_count; column++){
448 //To retrieve text from that specific cell.
449 String celtext = Columns_row.get(column).getText();
450 //System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext);
451
452
453
454 //log.info("Testing Get column and row value");
455 List <WebElement> exx= rows_table.get(1).findElements(By.tagName("td"));
456 eg=Columns_row.get(2).getText();
457 // System.out.println("Cell value of row 1 and column 2 is" +eg);
458 }
459 }
460
461
462
463
464 //Verify View/Edit isDisplayed and Click
465
466 driver.findElement(By.xpath("//a[@alt='View/Edit']")).isDisplayed();
467
468 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/div/table/tbody/tr[1]/td[1]/div/a")).click();
469
470 log.info("User clicked View/Edit");
471
472 //Verify the Subscriber Name displayed.
473 String header= driver.findElement(By.xpath("//h1[@class='heading1 ng-binding']")).getText();
474 //System.out.println(header);
475
476
477 if(header.contains(eg))
478 {
479 System.out.println("Header contains the subscriber name");
480 }else
481 System.out.println("Header does not contain the subscriber name");
482
483
484
485 Assert.assertTrue(driver.getPageSource().contains("PerfTest Subscriber00020021"));
486 log.info("VID-12 TC-6 PASSED");
487
488
489
490 driver.navigate().back();
491 //Cancel button isDisplayed
492 driver.findElement(By.xpath("//button[@class='button button--small button--primary']")).isDisplayed();
493 log.info("VID-12 TC-9 PASSED");
494
495 //Cancel button is clicked
496 driver.findElement(By.xpath("//button[@class='button button--small button--primary']")).click();
497 log.info("Cancel button is clicked");
498
499 //Verifying VID Home page is displayed
500 Assert.assertTrue(driver.getPageSource().contains("Search Existing Service Instances"));
501 log.info("VID-12 TC-10 PASSED");
502
503 }
504
505
506 /**
507 * Refresh subscriber name.
508 */
509 @Test(priority=9)
510 public void refreshSubscriberName()
511 {
512 log.info("VID-10 TC-4");
513
514
515 driver.findElement(By.xpath(configProp.getProperty("refreshButtonSubscriberName"))).isDisplayed();
516
517 log.info("VID-10 TC-4 PASSED");
518
519
520 }
521
522
523 /**
524 * Select subscriber type drop down.
525 *
526 * @throws InterruptedException the interrupted exception
527 */
528 @Test(priority=9)
529 public void selectSubscriberTypeDropDown() throws InterruptedException
530 {
531 Thread.sleep(5000);
532 log.info("------------------VID-10 TC-3, VID-12 TC-12,--------------------");
533 //Infrastructure Subscriber Type
534 Select iSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown"))));
535
536 List <WebElement> ielementCount = iSelect.getOptions();
537 log.info("Select Element Count of Service type");
538 System.out.println(ielementCount.size());
539 iSelect.selectByIndex(1);
540
541 log.info("VID-10 TC-3 PASSED");
542
543
544 //Submit button is clicked
545 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
546
547 //Verify whether the page header is displayed "Selected Subscriber's Service Instance Details:"
548 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/h1")).isDisplayed();
549 //Assert.assertTrue(driver.getPageSource().contains("Selected Subscriber's Service Instance Details:"))
550 log.info("Page Header: Selected Subscriber's Service Instance Details");
551
552
553 //Verify whether the page header is displayed "Global Customer ID"
554 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/div/table/thead/tr/th[2]/div")).isDisplayed();
555
556 //Assert.assertTrue(driver.getPageSource().contains("Global Customer ID"));
557 log.info("Table is displayed");
558
559 log.info("VID-12 TC-12 PASSED");
560
561 }
562
563
564
565 /**
566 * Logout under profile.
567 */
568 @Test(priority=10)
569 public void logoutUnderProfile()
570 {
571
572 log.info("-----------VID-11 TC-5---------------------");
573 //driver.findElement(By.partialLinkText("Click here to login")).click();
574 //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
575
576
577 driver.findElement(By.xpath(".//*[@class='icon-user-small login-snippet-icon']")).click();
578 driver.findElement(By.xpath(".//*[@id='reg-logout-div']/a")).click();
579 //Validate that the user has logged out of VID. Displays "Portal"
580 Assert.assertTrue(driver.getPageSource().contains("Portal"));
581
582 log.info("VID-11 TC-5 PASSED");
583
584 }
585
586
587
588 /**
589 * Tear down.
590 */
591 @AfterClass
592 public void tearDown()
593 {
594 driver.close();
595
596 }
597
598
599
600 }
601
602
603
604