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