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.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.support.ui.Select;
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.*;
50 * The Class FirstClass.
52 public class FirstClass {
54 /** The login button. */
55 WebElement loginButton;
69 /** The errormessage. */
70 WebElement errormessage;
74 WebDriver driver=new FirefoxDriver();
78 /** The config prop. */
79 private final Properties configProp = new Properties();
83 * Instantiates a new first class.
85 private FirstClass() {
86 // TODO Auto-generated constructor stub
89 // InputStream input =this.getClass().getClassLoader().getResourceAsStream("objectmap.properties");
90 //FileInputStream input1 = new FileInputStream("objectmap.properties");
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");
97 catch(IOException e) {
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();
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"));
127 // TODO Auto-generated method stub
133 //WebDriver driver=new FirefoxDriver();
135 log = Logger.getLogger(FirstClass.class.getName());
140 driver.get(configProp.getProperty("baseURL"));
141 driver.manage().window().maximize();
144 login = driver.findElement(By.xpath(configProp.getProperty("login")));
146 pwd = driver.findElement(By.xpath(configProp.getProperty("pwd")));
147 loginButton = driver.findElement(By.id(configProp.getProperty("loginButton")));
152 * Empty username password.
155 public void emptyUsernamePassword()
159 //User Name and Password field is empty
160 log.info("-----VID-11 TC-8----Username and password empty");
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";
167 //Assert.assertEquals(errmsg,expected);
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"));
174 log.info("Error message validated");
175 log.info("VID-11 TC-8 PASSED");
178 log.error("Failed validation");
188 public void invalidUserName()
191 log.info("-----VID-11 TC-6----Invalid Username and Valid Password");
194 login.sendKeys("xxx");
195 pwd.sendKeys("abc123");
199 } catch (InterruptedException e) {
200 // TODO Auto-generated catch block
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);
210 log.info("VID-11 TC-6 PASSED");
219 public void invalidPassword()
221 log.info("-----VID-11 TC-7----Valid Username and Invalid Password");
222 // Valid user name and Invalid password.
225 login.sendKeys("testuser");
228 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
231 String errmsg= errormessage.getText();
232 String expected = "Invalid username or password, Please try again";
233 Assert.assertEquals(errmsg,expected);
235 //Boolean str2 = driver.getPageSource().contains("Invaild username or password, Please try again");
236 //System.out.print(str2);
238 log.info("VID-11 TC-7 PASSED");
246 public void loginSuccessful()
248 log.info("-----VID-11 TC-1----Valid Username and Valid Password");
249 //Login with valid user name and password.
251 login.sendKeys("su");
253 pwd.sendKeys("fusion");
257 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
261 } catch (InterruptedException e) {
262 // TODO Auto-generated catch block
265 Assert.assertTrue(driver.getPageSource().contains("Search Existing Service Instances"));
266 log.info("VID-11 TC-1 PASSED");
272 * Verify home page elements left pane.
275 public void verifyHomePageElementsLeftPane()
280 log.info("VID-10 TC 1 ");
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();
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();
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();
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();
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();
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();
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();
308 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[3]/td/div/button")).isDisplayed();
311 driver.findElement(By.xpath(".//*[@class='icon-user-small login-snippet-icon']")).isDisplayed();
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"));
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");
328 * Disabled submit button.
331 public void disabledSubmitButton()
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");
341 * Default list box value.
344 public void defaultListBoxValue()
346 log.info("VID-12 TC-2");
349 //WebElement subscribername =driver.findElement(By.xpath(".//*[@id='mContent']/div/div/table/tbody/tr[1]/td[2]/div/select"));
351 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
352 Select iSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown"))));
355 WebElement ielement=iSelect.getFirstSelectedOption();
356 WebElement oelement=oSelect.getFirstSelectedOption();
357 String defaultsubscribername=oelement.getText();
358 String defaultservicetype=ielement.getText();
360 Assert.assertEquals(defaultsubscribername,"Select Subscriber Name");
361 Assert.assertEquals(defaultservicetype,"Select Service Type");
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();
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();
373 log.info("VID-12 TC-2 PASSED");
380 * Select subscriber name drop down.
382 * @throws InterruptedException the interrupted exception
385 public void selectSubscriberNameDropDown() throws InterruptedException
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--------------------");
390 driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")));
392 driver.findElement(By.xpath(configProp.getProperty("serviceTypeDropDown")));
395 //Infrastructure Subscriber Name
396 Select oSelect = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown"))));
398 List <WebElement> elementCount = oSelect.getOptions();
399 log.info("Select Element Count of Service Name");
400 System.out.println(elementCount.size());
403 //Verifying getInfrastructureSubscribersList
404 log.info("VID-29 TC-1");
405 Assert.assertTrue(elementCount.size()>0);
406 log.info("VID-29 TC-1 PASSED");
408 oSelect.selectByIndex(2);
409 String selectedOption = new Select(driver.findElement(By.xpath(configProp.getProperty("subscriberNameDropDown")))).getFirstSelectedOption().getText();
411 System.out.println("Service Name selected is " +selectedOption);
412 log.info("VID-10 TC-2 PASSED");
414 //Submit button is clicked
415 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
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:"))
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"));
430 log.info("VID-12 TC-5 PASSED");
431 log.info("VID-12 TC-11 PASSED");
433 WebElement serviceinstancetable =driver.findElement(By.xpath("//table[@class='tablesorter tablesorter-default ng-isolate-scope']"));
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();
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);
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);
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);
465 //Verify View/Edit isDisplayed and Click
467 driver.findElement(By.xpath("//a[@alt='View/Edit']")).isDisplayed();
469 driver.findElement(By.xpath(".//*[@id='mContent']/div/div/div/div/table/tbody/tr[1]/td[1]/div/a")).click();
471 log.info("User clicked View/Edit");
473 //Verify the Subscriber Name displayed.
474 String header= driver.findElement(By.xpath("//h1[@class='heading1 ng-binding']")).getText();
475 //System.out.println(header);
478 if(header.contains(eg))
480 System.out.println("Header contains the subscriber name");
482 System.out.println("Header does not contain the subscriber name");
486 Assert.assertTrue(driver.getPageSource().contains("PerfTest Subscriber00020021"));
487 log.info("VID-12 TC-6 PASSED");
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");
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");
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");
508 * Refresh subscriber name.
511 public void refreshSubscriberName()
513 log.info("VID-10 TC-4");
516 driver.findElement(By.xpath(configProp.getProperty("refreshButtonSubscriberName"))).isDisplayed();
518 log.info("VID-10 TC-4 PASSED");
525 * Select subscriber type drop down.
527 * @throws InterruptedException the interrupted exception
530 public void selectSubscriberTypeDropDown() throws InterruptedException
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"))));
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);
542 log.info("VID-10 TC-3 PASSED");
545 //Submit button is clicked
546 driver.findElement(By.xpath(configProp.getProperty("submitButton"))).click();
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");
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();
557 //Assert.assertTrue(driver.getPageSource().contains("Global Customer ID"));
558 log.info("Table is displayed");
560 log.info("VID-12 TC-12 PASSED");
567 * Logout under profile.
570 public void logoutUnderProfile()
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);
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"));
583 log.info("VID-11 TC-5 PASSED");
593 public void tearDown()