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