2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.ecomp.vid.selenium;
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;
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;
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.*;
51 * The Class FirstClass.
53 public class FirstClass {
55 /** The login button. */
56 WebElement loginButton;
70 /** The errormessage. */
71 WebElement errormessage;
75 WebDriver driver=new FirefoxDriver();
79 /** The config prop. */
80 private final Properties configProp = new Properties();
84 * Instantiates a new first class.
86 private FirstClass() {
87 // TODO Auto-generated constructor stub
90 // InputStream input =this.getClass().getClassLoader().getResourceAsStream("objectmap.properties");
91 //FileInputStream input1 = new FileInputStream("objectmap.properties");
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");
98 catch(IOException e) {
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();
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"));
128 // TODO Auto-generated method stub
134 //WebDriver driver=new FirefoxDriver();
136 log = Logger.getLogger(FirstClass.class.getName());
141 driver.get(configProp.getProperty("baseURL"));
142 driver.manage().window().maximize();
145 login = driver.findElement(By.xpath(configProp.getProperty("login")));
147 pwd = driver.findElement(By.xpath(configProp.getProperty("pwd")));
148 loginButton = driver.findElement(By.id(configProp.getProperty("loginButton")));
153 * Empty username password.
156 public void emptyUsernamePassword()
160 //User Name and Password field is empty
161 log.info("-----VID-11 TC-8----Username and password empty");
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";
168 //Assert.assertEquals(errmsg,expected);
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"));
175 log.info("Error message validated");
176 log.info("VID-11 TC-8 PASSED");
179 log.error("Failed validation");
189 public void invalidUserName()
192 log.info("-----VID-11 TC-6----Invalid Username and Valid Password");
195 login.sendKeys("xxx");
196 pwd.sendKeys("abc123");
200 } catch (InterruptedException e) {
201 // TODO Auto-generated catch block
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);
211 log.info("VID-11 TC-6 PASSED");
220 public void invalidPassword()
222 log.info("-----VID-11 TC-7----Valid Username and Invalid Password");
223 // Valid user name and Invalid password.
226 login.sendKeys("testuser");
229 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
232 String errmsg= errormessage.getText();
233 String expected = "Invalid username or password, Please try again";
234 Assert.assertEquals(errmsg,expected);
236 //Boolean str2 = driver.getPageSource().contains("Invaild username or password, Please try again");
237 //System.out.print(str2);
239 log.info("VID-11 TC-7 PASSED");
247 public void loginSuccessful()
249 log.info("-----VID-11 TC-1----Valid Username and Valid Password");
250 //Login with valid user name and password.
252 login.sendKeys("su");
254 pwd.sendKeys("fusion");
258 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
262 } catch (InterruptedException e) {
263 // TODO Auto-generated catch block
266 Assert.assertTrue(driver.getPageSource().contains("Search Existing Service Instances"));
267 log.info("VID-11 TC-1 PASSED");
273 * Verify home page elements left pane.
276 public void verifyHomePageElementsLeftPane()
281 log.info("VID-10 TC 1 ");
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();
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();
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();
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();
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();
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();
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();
309 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[3]/td/div/button")).isDisplayed();
312 driver.findElement(By.xpath(".//*[@class='icon-user-small login-snippet-icon']")).isDisplayed();
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"));
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");
329 * Disabled submit button.
332 public void disabledSubmitButton()
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");
342 * Default list box value.
345 public void defaultListBoxValue()
347 log.info("VID-12 TC-2");
350 //WebElement subscribername =driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[2]/div/select"));
352 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
353 Select iSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown"))));
356 WebElement ielement=iSelect.getFirstSelectedOption();
357 WebElement oelement=oSelect.getFirstSelectedOption();
358 String defaultsubscribername=oelement.getText();
359 String defaultservicetype=ielement.getText();
361 Assert.assertEquals(defaultsubscribername,"Select Subscriber Name");
362 Assert.assertEquals(defaultservicetype,"Select Service Type");
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();
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();
374 log.info("VID-12 TC-2 PASSED");
381 * Select subscriber name drop down.
383 * @throws InterruptedException the interrupted exception
386 public void selectSubscriberNameDropDown() throws InterruptedException
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--------------------");
391 driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")));
393 driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown")));
396 //Infrastructure Subscriber Name
397 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
399 List <WebElement> elementCount = oSelect.getOptions();
400 log.info("Select Element Count of Service Name");
401 System.out.println(elementCount.size());
404 //Verifying getInfrastructureSubscribersList
405 log.info("VID-29 TC-1");
406 Assert.assertTrue(elementCount.size()>0);
407 log.info("VID-29 TC-1 PASSED");
409 oSelect.selectByIndex(2);
410 String selectedOption = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")))).getFirstSelectedOption().getText();
412 System.out.println("Service Name selected is " +selectedOption);
413 log.info("VID-10 TC-2 PASSED");
415 //Submit button is clicked
416 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
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:"))
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"));
431 log.info("VID-12 TC-5 PASSED");
432 log.info("VID-12 TC-11 PASSED");
434 WebElement serviceinstancetable =driver.findElement(By.xpath("//table[@class='tablesorter tablesorter-default ng-isolate-scope']"));
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();
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);
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);
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);
466 //Verify View/Edit isDisplayed and Click
468 driver.findElement(By.xpath("//a[@alt='View/Edit']")).isDisplayed();
470 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/div/table/tbody/tr[1]/td[1]/div/a")).click();
472 log.info("User clicked View/Edit");
474 //Verify the Subscriber Name displayed.
475 String header= driver.findElement(By.xpath("//h1[@class='heading1 ng-binding']")).getText();
476 //System.out.println(header);
479 if(header.contains(eg))
481 System.out.println("Header contains the subscriber name");
483 System.out.println("Header does not contain the subscriber name");
487 Assert.assertTrue(driver.getPageSource().contains("PerfTest Subscriber00020021"));
488 log.info("VID-12 TC-6 PASSED");
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");
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");
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");
509 * Refresh subscriber name.
512 public void refreshSubscriberName()
514 log.info("VID-10 TC-4");
517 driver.findElement(By.xpath(configProp.getProperty("refreshButtonSubscriberName"))).isDisplayed();
519 log.info("VID-10 TC-4 PASSED");
526 * Select subscriber type drop down.
528 * @throws InterruptedException the interrupted exception
531 public void selectSubscriberTypeDropDown() throws InterruptedException
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"))));
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);
543 log.info("VID-10 TC-3 PASSED");
546 //Submit button is clicked
547 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
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");
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();
558 //Assert.assertTrue(driver.getPageSource().contains("Global Customer ID"));
559 log.info("Table is displayed");
561 log.info("VID-12 TC-12 PASSED");
568 * Logout under profile.
571 public void logoutUnderProfile()
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);
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"));
584 log.info("VID-11 TC-5 PASSED");
594 public void tearDown()