Saturday, August 13, 2016

sample pom

<?xml version="1.0" encoding="UTF-8"?>  
 <project xmlns="http://maven.apache.org/POM/4.0.0"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
   <modelVersion>4.0.0</modelVersion>  
   <groupId>com.mridul.auotmation.webservices</groupId>  
   <artifactId>WeatherAPI</artifactId>  
   <version>1.0-SNAPSHOT</version>  
   <properties>  
     <java>1.8</java>  
     <maven.compiler>3.5.1</maven.compiler>  
     <maven.failsafe>2.19.1</maven.failsafe>  
     <maven.failsafe.parallel>methods</maven.failsafe.parallel>  
     <maven.failsafe.threadcount>10</maven.failsafe.threadcount>  
     <apache.cxf>3.1.7</apache.cxf>  
     <serenity.core>1.1.36</serenity.core>  
     <serenity.maven.plugin>1.1.36</serenity.maven.plugin>  
     <serenity.junit>1.1.36</serenity.junit>  
     <serenity.spring>1.1.36</serenity.spring>  
     <google.guava>19.0</google.guava>  
     <spring.boot.web>1.4.0.RELEASE</spring.boot.web>  
   </properties>  
   <dependencies>  
     <!--core java specific libraries-->  
     <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->  
     <dependency>  
       <groupId>com.google.guava</groupId>  
       <artifactId>guava</artifactId>  
       <version>${google.guava}</version>  
     </dependency>  
     <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->  
     <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->  
     <dependency>  
       <groupId>org.springframework.boot</groupId>  
       <artifactId>spring-boot-starter-web</artifactId>  
       <version>${spring.boot.web}</version>  
     </dependency>  
     <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxrs -->  
     <dependency>  
       <groupId>org.apache.cxf</groupId>  
       <artifactId>cxf-rt-frontend-jaxrs</artifactId>  
       <version>${apache.cxf}</version>  
     </dependency>  
     <!--Serenity plugins-->  
     <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->  
     <dependency>  
       <groupId>net.serenity-bdd</groupId>  
       <artifactId>serenity-core</artifactId>  
       <version>${serenity.core}</version>  
     </dependency>  
     <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->  
     <dependency>  
       <groupId>net.serenity-bdd</groupId>  
       <artifactId>serenity-junit</artifactId>  
       <version>${serenity.junit}</version>  
     </dependency>  
     <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-spring -->  
     <dependency>  
       <groupId>net.serenity-bdd</groupId>  
       <artifactId>serenity-spring</artifactId>  
       <version>${serenity.spring}</version>  
     </dependency>  
     <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-failsafe-plugin -->  
     <dependency>  
       <groupId>org.apache.maven.plugins</groupId>  
       <artifactId>maven-failsafe-plugin</artifactId>  
       <version>${maven.failsafe}</version>  
     </dependency>  
   </dependencies>  
   <build>  
     <plugins>  
       <plugin>  
         <groupId>org.apache.maven.plugins</groupId>  
         <artifactId>maven-compiler-plugin</artifactId>  
         <version>${maven.compiler}</version>  
         <configuration>  
           <source>${java}</source>  
           <target>${java}</target>  
         </configuration>  
       </plugin>  
       <plugin>  
         <groupId>org.apache.maven.plugins</groupId>  
         <artifactId>maven-failsafe-plugin</artifactId>  
         <version>${maven.failsafe}</version>  
         <configuration>  
           <parallel>${maven.failsafe.parallel}</parallel>  
           <threadCount>${maven.failsafe.threadcount}</threadCount>  
           <includes>  
             <include>**/features/**/When*.java</include>  
           </includes>  
         </configuration>  
       </plugin>  
       <plugin>  
         <groupId>net.serenity-bdd.maven.plugins</groupId>  
         <artifactId>serenity-maven-plugin</artifactId>  
         <version>${serenity.maven.plugin}</version>  
         <executions>  
           <execution>  
             <id>serenity-reports</id>  
             <phase>post-integration-test</phase>  
             <goals>  
               <goal>aggregate</goal>  
             </goals>  
           </execution>  
         </executions>  
       </plugin>  
     </plugins>  
   </build>  
 </project>  

Friday, August 5, 2016

TestWebAuthorHelp

package com.mridul.framework.selenium.tests;  
 import com.mridul.framework.selenium.pages.LoginPage;  
 import org.testng.annotations.Test;  
 import static org.testng.Assert.assertNotNull;  
 /**  
  * Created by Mridul on 3/16/2016.  
  */  
 public class TestWebAuthorHelp extends AbstractTest{  
   @Test(enabled = true, groups = "prerequisite") //, dependsOnMethods = {"testURLToDash"} )  
   public void testLoginToDashFluently(){  
     try {  
       loginPage = new LoginPage(driver);  
       assertNotNull(loginPage);  
       homePage=loginPage.navigateToURL(expectedURL).and().typeInUserId("UserId")  
           .and().typeInPassword("Password").and().then().clickOnSubmitButton();  
       assertNotNull(homePage);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n", e);  
     }  
   }  
   @Test(enabled = true, dependsOnMethods = {"testLoginToDashFluently"}, groups = "prerequisite" )  
   public void testWebAuthorHelpModal(){  
     try {  
       webAuthorHelpModal=homePage.clickOnWebAuthorHelp();  
       assertNotNull(webAuthorHelpModal);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n",e);  
     }  
   }  
   @Test(enabled = true, dependsOnMethods = {"testWebAuthorHelpModal"}, dependsOnGroups = "prerequisite")  
   public void testOpenWebAuthorHelp(){  
     try {  
       webAuthorHelpModal.selectPleaseChooseACategory("Company Directory")  
           .and().selectNatureOfRequest("Terminated User showing in directory")  
           .and().fillInRequestDetails("Testing WebAuthor Help")  
           .and().fillInNotesOrComments("Testing POC for WebAuthor Help")  
           .and().clickOnOrderNowButton()  
           .and().clickOnSubmitOrder();  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n%n", e);  
       e.printStackTrace();  
     }  
   }  
 }  

TestReportAnIssue

package com.mridul.framework.selenium.tests;  
 import com.mridul.framework.selenium.pages.LoginPage;  
 import static org.testng.Assert.*;  
 import org.testng.annotations.Test;  
 /**  
  * Created by Mridul on 3/10/2016.  
  */  
 //@ContextConfiguration(classes = ApplicationConfig.class)  
 public class TestReportAnIssue extends AbstractTest{  
   //Fluent tests  
   @Test(enabled = true, groups = "prerequisite") //, dependsOnMethods = {"testURLToDash"} )  
   public void testLoginToDashFluently(){  
     try {  
       loginPage = new LoginPage(driver);  
       assertNotNull(loginPage);  
       homePage=loginPage.navigateToURL(expectedURL).and().typeInUserId("UserId")  
           .and().typeInPassword("Password").and().then().clickOnSubmitButton();  
       assertNotNull(homePage);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n", e);  
     }  
   }  
   @Test(enabled = true, dependsOnMethods = {"testLoginToDashFluently"}, groups = "prerequisite" )  
   public void testReportAnIssueModal(){  
     try {  
       reportAnIssueModal=homePage.clickOnReportAnIssue();  
       assertNotNull(reportAnIssueModal);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n",e);  
     }  
   }  
   @Test(enabled = false, dependsOnMethods = {"testReportAnIssueModal"} , dependsOnGroups = "prerequisite")  
   public void testReportAnIncidentWithoutUnlistedUser(){  
     try {  
       reportAnIssueModal.and().fillInRequestedBy("MRIDUL JAYAN")  
           .and().fillInCallbackNumber("1111111111")  
           .and().selectAnyBusinessUrgency()  
           .and().selectAnyBusinessImpact()  
           .and().selectAnyTypeOfIssue()  
           .and().selectAnyCategory()  
           .and().fillInPleaseDescribeYourIssue("Testing Portal")  
           .and().clickOnSubmitButton();  
       assertNotNull(reportAnIssueModal);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n%n", e);  
       e.printStackTrace();  
     }  
   }  
   @Test(enabled = false, dependsOnMethods = {"testReportAnIssueModal"}, dependsOnGroups = "prerequisite" )  
   public void testReportAnIncidentWithUnlistedUser(){  
     try {  
       reportAnIssueModal.  
           and().fillInRequestedBy("MRIDUL JAYAN").  
           and().fillInCallbackNumber("1111111111").  
           and().checkUnlistedUser().  
           and().fillInUnlistedContactName("MRIDUL JAYAN").  
           and().fillInUnlistedContactEmail("test@testmail.com").  
           and().selectAnyBusinessUrgency().  
           and().selectAnyBusinessImpact().  
           and().selectAnyTypeOfIssue().  
           and().selectAnyCategory().  
           and().fillInPleaseDescribeYourIssue("Testing Portal").  
           and().clickOnSubmitButton();  
       assertNotNull(reportAnIssueModal);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n%n", e);  
       e.printStackTrace();  
     }  
   }  
   @Test(enabled = true, dependsOnMethods = {"testReportAnIssueModal"}, dependsOnGroups = "prerequisite")  
   public void testReportAnIncidentWithUnlistedUserUsingSpecificText(){  
     try {  
       reportAnIssueModal.  
           and().fillInRequestedBy("MRIDUL JAYAN").  
           and().fillInCallbackNumber("1111111111").  
           and().checkUnlistedUser().  
           and().fillInUnlistedContactName("MRIDUL JAYAN").  
           and().fillInUnlistedContactEmail("test@testmail.com").  
           and().selectBusinessUrgency("Short amount of time").  
           and().selectBusinessImpact("Small business impact").  
           and().selectTypeOfIssue("Hardware").  
           and().selectCategory("Printer").  
           and().fillInPleaseDescribeYourIssue("Testing Portal").  
           and().clickOnSubmitButton();  
       assertNotNull(reportAnIssueModal);  
     }catch (Exception e){  
       System.out.printf("Exception thrown : %s%n%n", e);  
       e.printStackTrace();  
     }  
   }  
 }  

AbstractTest

package com.mridul.framework.selenium.tests;  
 import com.mridul.framework.selenium.modals.WebAuthorHelpModal;  
 import com.mridul.framework.selenium.pages.HomePage;  
 import com.mridul.framework.selenium.pages.LoginPage;  
 import com.mridul.framework.selenium.modals.ReportAnIssueModal;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.testng.annotations.*;  
 import static org.testng.Assert.assertNotNull;  
 /**  
  * Created by Mridul on 3/11/2016.  
  */  
 public abstract class AbstractTest {  
   protected WebDriver driver;  
   protected LoginPage loginPage;  
   protected HomePage homePage;  
   protected ReportAnIssueModal reportAnIssueModal;  
   protected WebAuthorHelpModal webAuthorHelpModal;  
   public String expectedURL="https://www.google.com";  
   //@BeforeSuite(enabled = true)  
   @BeforeTest(enabled = true)  
   public void setUp() {  
     ////TODO-Fix spring injection  
     System.setProperty("webdriver.chrome.driver", "src/main/resources/drivers/chromedriver.exe");  
     driver = new ChromeDriver();  
 /*  
     System.setProperty("webdriver.ie.driver", "src/main/resources/drivers/IEDriverServer.exe");  
     driver = new InternetExplorerDriver();*/  
   }  
   @AfterTest(enabled = false)  
   public void closePage(){  
     loginPage.closePage();  
   }  
   @AfterSuite(enabled = false)  
   public void tearDown() {  
     if (driver != null) {  
       driver.quit();  
     }  
   }  
 }  

ExtentReporterNG

package com.mridul.framework.selenium.reports;  
 import com.relevantcodes.extentreports.ExtentReports;  
 import com.relevantcodes.extentreports.ExtentTest;  
 import com.relevantcodes.extentreports.LogStatus;  
 import org.testng.*;  
 import org.testng.xml.XmlSuite;  
 import java.io.File;  
 import java.util.Calendar;  
 import java.util.Date;  
 import java.util.List;  
 import java.util.Map;  
 /**  
  * Created by Mridul on 3/16/2016.  
  */  
   public class ExtentReporterNG implements IReporter {  
     private ExtentReports extent;  
     @Override  
     public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {  
       extent = new ExtentReports(outputDirectory + File.separator + "ExtentReportTestNG.html", false);  
       for (ISuite suite : suites) {  
         Map<String, ISuiteResult> result = suite.getResults();  
         for (ISuiteResult r : result.values()) {  
           ITestContext context = r.getTestContext();  
           buildTestNodes(context.getPassedTests(), LogStatus.PASS);  
           buildTestNodes(context.getFailedTests(), LogStatus.FAIL);  
           buildTestNodes(context.getSkippedTests(), LogStatus.SKIP);  
         }  
       }  
       extent.flush();  
       extent.close();  
     }  
     private void buildTestNodes(IResultMap tests, LogStatus status) {  
       ExtentTest test;  
       if (tests.size() > 0) {  
         for (ITestResult result : tests.getAllResults()) {  
           test = extent.startTest(result.getMethod().getMethodName());  
           test.getTest().setStartedTime(getTime(result.getStartMillis()));  
           test.getTest().setEndedTime(getTime(result.getEndMillis()));  
           for (String group : result.getMethod().getGroups())  
             test.assignCategory(group);  
           String message = "Test " + status.toString().toLowerCase() + "ed";  
           if (result.getThrowable() != null)  
             message = result.getThrowable().getMessage();  
           test.log(status, message);  
           extent.endTest(test);  
         }  
       }  
     }  
     private Date getTime(long millis) {  
       Calendar calendar = Calendar.getInstance();  
       calendar.setTimeInMillis(millis);  
       return calendar.getTime();  
     }  
 }  

LoginPage

 package com.mridul.framework.selenium.pages;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.support.FindBy;  
 import java.util.Arrays;  
 import java.util.List;  
 /**  
  * Created by Mridul on 3/10/2016.  
  */  
 public final class LoginPage extends AbstractPage {  
   @FindBy(id="lblTop")  
   private WebElement lbl_DashStaging_Anchor;  
   @FindBy(id="LogoImage")  
   private WebElement lbl_Southwest_Anchor;  
   @FindBy(id="ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid")  
   private WebElement txtfld_UserId;  
   @FindBy(id="ContentPlaceHolder1_MFALoginControl1_UserIDView_tbxPassword" )  
   private WebElement txtfld_Password;  
   @FindBy(id="ContentPlaceHolder1_MFALoginControl1_UserIDView_btnSubmit")  
   private WebElement btn_Submit;  
   public LoginPage(WebDriver driver){  
     super(driver);  
   }  
   @Override  
   protected List<WebElement> registerAnchors() {  
     return Arrays.asList(lbl_DashStaging_Anchor, lbl_Southwest_Anchor);  
   }  
   @Override  
   public LoginPage and() {  
     return this;  
   }  
   @Override  
   public LoginPage then() {  
     return this;  
   }  
   public LoginPage navigateToURL(String url){  
     super.getURL(url);  
     return this;  
   }  
   public LoginPage typeInUserId(String userid){  
     super.populateTextField(txtfld_UserId, userid);  
     return this;  
   }  
   public LoginPage typeInPassword(String userid){  
     super.populateTextField(txtfld_Password, userid);  
     return this;  
   }  
   ////TODO-change this to new page  
   public HomePage clickOnSubmitButton(){  
     super.clickOnButton(btn_Submit);  
     return new HomePage(driver);  
   }  
 }  

HomePage

 package com.mridul.framework.selenium.pages;  
 import com.mridul.framework.selenium.modals.ReportAnIssueModal;  
 import com.mridul.framework.selenium.modals.WebAuthorHelpModal;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.interactions.Actions;  
 import org.openqa.selenium.support.FindBy;  
 import java.util.Arrays;  
 import java.util.List;  
 /**  
  * Created by Mridul on 3/11/2016.  
  */  
 public final class HomePage extends AbstractPage {  
   //anchors  
   @FindBy(css = "a[href='home.do'] > img")  
   private WebElement img_DashLogo_Anchor;  
   //page elements  
   @FindBy(css = "a[label='Logout']")  
   private WebElement lnk_Logout;  
   @FindBy(id = "menu_search")  
   private WebElement fld_MenuSearch;  
   @FindBy(xpath = "//*[@id='cssmenu']/ul/li[4]/a/span")  
   private WebElement lbl_ReportAnIssue;  
   @FindBy(xpath = "//*[@id='cssmenu']/ul/li[5]/a/span")  
   private WebElement lbl_OrderStuff;  
   //@FindBy(xpath="(//li[contains(@class,'sc_menu_item')]/a[contains(text(),'WebAuthor')])[2]")  
   @FindBy(xpath = "//*a[@data-target='#myModal' and contains(text(),'WebAuthor')][1]")  
   private WebElement lbl_WebAuthorHelp;  
   public HomePage(WebDriver driver) {  
     super(driver);  
   }  
   @Override  
   protected List<WebElement> registerAnchors() {  
     return Arrays.asList(img_DashLogo_Anchor);  
   }  
   @Override  
   public HomePage and() {  
     return this;  
   }  
   @Override  
   public HomePage then() {  
     return this;  
   }  
   public ReportAnIssueModal clickOnReportAnIssue() {  
     super.clickOnWebElement(lbl_ReportAnIssue);  
     return new ReportAnIssueModal(driver, this);  
   }  
   ////TODO-Hack, refactor later  
   public WebAuthorHelpModal clickOnWebAuthorHelp() {  
     Actions actions= new Actions(driver);  
     actions.moveToElement(lbl_OrderStuff).build().perform();  
     actions.moveByOffset(lbl_OrderStuff.getSize().getWidth(),0).click().build().perform();  
     this.sleep(2);  
     driver.findElement(By.partialLinkText("WebAuthor")).click();  
     return new WebAuthorHelpModal(driver, this);  
   }  
 }  

AbstractPage

 package com.mridul.framework.selenium.pages;  
 import com.mridul.framework.selenium.interfaces.AbstractContainer;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.support.ui.ExpectedCondition;  
 /**  
  * Created by Mridul on 3/10/2016.  
  */  
 public abstract class AbstractPage extends AbstractContainer {  
   public AbstractPage(WebDriver driver){  
     super(driver);  
   }  
   protected void getURL(String url){  
     driver.manage().window().maximize();  
     driver.get(url);  
     ////TODO-format into separate code sometime  
     wait.until(new ExpectedCondition<Boolean>() {  
       public Boolean apply(WebDriver webDriver) {  
         return ((JavascriptExecutor) driver).executeScript(  
             "return document.readyState"  
         ).equals("complete");  
       }  
     });  
     driver.switchTo().defaultContent();  
     //invoking validate anchors  
     validateAnchors();  
   }  
   public String getCurrentURL(){  
     return driver.getCurrentUrl();  
   }  
   public void closePage(){  
     driver.quit();  
   }  
 }  

WebAuthorHelpModal

package com.mridul.framework.selenium.modals;  
 import com.mridul.framework.selenium.pages.AbstractPage;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.support.FindBy;  
 import java.util.Arrays;  
 import java.util.List;  
 /**  
  * Created by Mridul on 3/17/2016.  
  */  
 public class WebAuthorHelpModal extends AbstractModal{  
   @FindBy(id = "myModalLabel")  
   private WebElement lbl_WebAuthorHelp_Anchor;  
   @FindBy(id="order_now")  
   private WebElement btn_OrderNow_Anchor;  
   @FindBy(id="submit_order")  
   private WebElement btn_SubmitOrder;  
   @FindBy(id = "modaliframe")  
   private WebElement iframe_modaliframe;  
   @FindBy(xpath = "//*[@id='IO:155e5bb00fc7060040a7945f62050eff']")  
   private WebElement selfld_Category;  
   @FindBy(xpath = "//*[@id='IO:dd5e9bb00fc7060040a7945f62050e01']")  
   private WebElement selfld_NatureOfRequest;  
   @FindBy(xpath = "//*[@id='IO:255e9bb00fc7060040a7945f62050e05']")  
   private WebElement txtarea_RequestDetails;  
   @FindBy(xpath = "//*[@id='IO:3823341e0a0a0b27003118193596953f']")  
   private WebElement txtarea_NotesOrComments;  
   @Override  
   protected List<WebElement> registerAnchors() {  
     return Arrays.asList(lbl_WebAuthorHelp_Anchor, btn_OrderNow_Anchor);  
   }  
   @Override  
   public WebAuthorHelpModal and() {  
     return this;  
   }  
   @Override  
   public WebAuthorHelpModal then() {  
     return this;  
   }  
   public WebAuthorHelpModal(WebDriver driver, AbstractPage parentPage) {  
     super(driver, parentPage);  
     super.switchToIFrame(iframe_modaliframe);  
   }  
   public WebAuthorHelpModal selectPleaseChooseACategory(String text) {  
     super.selectOptionByText(selfld_Category, text);  
     return this;  
   }  
   public WebAuthorHelpModal selectNatureOfRequest(String text) {  
     super.selectOptionByText(selfld_NatureOfRequest, text);  
     return this;  
   }  
   public WebAuthorHelpModal fillInRequestDetails(String text) {  
     super.populateTextField(txtarea_RequestDetails, text);  
     return this;  
   }  
   public WebAuthorHelpModal fillInNotesOrComments(String text) {  
     super.populateTextField(txtarea_NotesOrComments, text);  
     return this;  
   }  
   public WebAuthorHelpModal clickOnOrderNowButton() {  
     super.clickOnButton(btn_OrderNow_Anchor);  
     return this;  
   }  
   public WebAuthorHelpModal clickOnSubmitOrder() {  
     super.clickOnButton(btn_SubmitOrder);  
     return this;  
   }  
 }  

ReportAnIssueModal

package com.mridul.framework.selenium.modals;  
 import com.mridul.framework.selenium.pages.HomePage;  
 import com.mridul.framework.selenium.pages.AbstractPage;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.support.FindAll;  
 import org.openqa.selenium.support.FindBy;  
 import java.util.Arrays;  
 import java.util.Collections;  
 import java.util.List;  
 import java.util.concurrent.ThreadLocalRandom;  
 /**  
  * Created by Mridul on 3/12/2016.  
  */  
 public final class ReportAnIssueModal extends AbstractModal {  
   //anchor elements  
   @FindBy(id = "myModalLabel")  
   private WebElement lbl_ReportAnIssue_Anchor;  
   @FindBy(id = "submit_button")  
   private WebElement btn_Submit_Anchor;  
   //Modal elements  
   @FindBy(id = "favorite_icon")  
   private WebElement icon_Favorite;  
   @FindBy(css = "span[class='glyphicon-remove-circle']")  
   private WebElement icon_Close;  
   @FindBy(id = "modaliframe")  
   private WebElement iframe_modaliframe;  
   @FindBy(css = "div[class='navbar-right'] > div > button")  
   private WebElement btn_ExpandCollapse;  
   //@FindBy(xpath = "//*div[@class='input-group']/input[starts-with(@id,'sys_display.IO:')][1]")  
   //@FindBy(xpath = "//*div[@class='input-group']/input[1]")  
   @FindBy(xpath = "//*[@id='sys_display.IO:5c9dc8300f9521008783918172050e2c']")  
   private WebElement txtfld_RequestedBy;  
   //@FindBy(xpath = "//*div[@class='input-group']/input[starts-with(@id,'sys_display.IO:')][2]")  
   //@FindBy(xpath = "//*div[@class='input-group']/input[2]")  
   @FindBy(xpath = "//*[@id='sys_display.IO:dfedc8300f9521008783918172050e48']")  
   private WebElement txtfld_RequestedFor;  
   //@FindBy(xpath = "//*input[starts-with(@id,'IO:')][1]")  
   //@FindBy(xpath = "//*div[@class='input_controls']/input[2]")  
   @FindBy(xpath = "//*[@id='IO:a6c626970f55a10040a7945f62050e98']")  
   private WebElement txtfld_CallBackNumber;  
   @FindBy(name = "checkbox_container")  
   private WebElement chkbox_UnlistedUser;  
   @FindBy(xpath = "//*[@id='IO:84c9eed30f55a10040a7945f62050e83']")  
   private WebElement txtfld_UnlistedContactName;  
   @FindBy(xpath = "//*[@id='IO:201aaa970f55a10040a7945f62050e9d']")  
   private WebElement txtfld_UnlistedContactEmail;  
   @FindBy(xpath = "//*[@id='IO:d4665dce0f9806008783918172050e13']")  
   private WebElement txtfld_Other;  
   //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][1]")  
   @FindBy(xpath = "//*[@id='IO:081b7d970f3b310040a7945f62050eb2']")  
   private WebElement selfld_BusinessUrgency;  
   //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][2]")  
   @FindBy(xpath = "//*[@id='IO:c56c79d70f3b310040a7945f62050ead']")  
   private WebElement selfld_BusinessImpact;  
   //@FindBy(xpath = "//*select[starts-with(@id,'IO:')][3]")  
   @FindBy(xpath = "//*[@id='IO:48ec3dd70f3b310040a7945f62050ef5']")  
   private WebElement selfld_TypeOfIssue;  
   @FindAll({  
       @FindBy(xpath = "//*[@id='IO:f32d391b0f3b310040a7945f62050e4a']"),  
       @FindBy(xpath = "//*[@id='IO:b25d7dd70f3b310040a7945f62050ef0']"),  
       @FindBy(xpath = "//*[@id='IO:a032194e0f9806008783918172050e1b']")  
   })  
   private WebElement selfld_Category;  
   //@FindBy(xpath = "//*textarea[starts-with(@id,'IO:')][3]")  
   @FindBy(xpath = "//*[@id='IO:bd6db91b0f3b310040a7945f62050e0c']")  
   private WebElement txtarea_DescribeIssue;  
   @FindBy(xpath = "/html/body/center/div/img")  
   private WebElement img_GreenChecMark;  
   //instance variables  
   private TypeOfIssue typeOfIssue;  
   private enum TypeOfIssue {  
     HARDWARE(1, 12),  
     SOFTWARE(2, 16),  
     SOS(3, 7);  
     private int index;  
     private int categorySize;  
     private static final List<TypeOfIssue> VALUES =  
         Collections.unmodifiableList(Arrays.asList(values()));  
     private static final int SIZE = VALUES.size();  
     private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();  
     TypeOfIssue(int index, int categorySize) {  
       this.index = index;  
       this.categorySize = categorySize;  
     }  
     int getIndex() {  
       return index;  
     }  
     int getCategorySize() {  
       return categorySize;  
     }  
     public static TypeOfIssue getRandomValue() {  
       return VALUES.get(RANDOM.nextInt(SIZE));  
     }  
   }  
   public ReportAnIssueModal(WebDriver driver, AbstractPage parentPage) {  
     super(driver, parentPage);  
     super.switchToIFrame(iframe_modaliframe);  
   }  
   @Override  
   protected List<WebElement> registerAnchors() {  
     return Arrays.asList(lbl_ReportAnIssue_Anchor, btn_Submit_Anchor);  
   }  
   @Override  
   public ReportAnIssueModal and() {  
     return this;  
   }  
   @Override  
   public ReportAnIssueModal then() {  
     return this;  
   }  
   public ReportAnIssueModal fillingRequestorInformationForm() {  
     return this;  
   }  
   public ReportAnIssueModal fillInRequestedBy(String text) {  
     super.populateTextField(txtfld_RequestedBy, text);  
     return this;  
   }  
   //private getters and setters  
   private TypeOfIssue getTypeOfIssue() {  
     return typeOfIssue;  
   }  
   private void setTypeOfIssue(TypeOfIssue typeOfIssue) {  
     this.typeOfIssue = typeOfIssue;  
   }  
   public ReportAnIssueModal fillInRequestedFor(String text) {  
     super.populateTextField(txtfld_RequestedFor, text);  
     return this;  
   }  
   public ReportAnIssueModal fillInCallbackNumber(String text) {  
     super.populateTextField(txtfld_CallBackNumber, text);  
     return this;  
   }  
   public ReportAnIssueModal checkUnlistedUser() {  
     super.checkOnCheckBox(chkbox_UnlistedUser);  
     return this;  
   }  
   public ReportAnIssueModal fillInUnlistedContactName(String text) {  
     super.populateTextField(txtfld_UnlistedContactName, text);  
     return this;  
   }  
   public ReportAnIssueModal fillInUnlistedContactEmail(String text) {  
     super.populateTextField(txtfld_UnlistedContactEmail, text);  
     return this;  
   }  
   public ReportAnIssueModal uncheckUnlistedUser() {  
     super.unCheckOnCheckBox(chkbox_UnlistedUser);  
     return this;  
   }  
   public ReportAnIssueModal selectBusinessUrgency(String text) {  
     super.selectOptionByText(selfld_BusinessUrgency, text);  
     return this;  
   }  
   public ReportAnIssueModal selectAnyBusinessUrgency() {  
     //super.selectOptionByIndex(selfld_BusinessUrgency, 3);  
     super.selectOptionByRandomValue(selfld_BusinessUrgency);  
     return this;  
   }  
   public ReportAnIssueModal selectBusinessImpact(String text) {  
     super.selectOptionByText(selfld_BusinessImpact, text);  
     return this;  
   }  
   public ReportAnIssueModal selectAnyBusinessImpact() {  
     //super.selectOptionByIndex(selfld_BusinessImpact, 3);  
     super.selectOptionByRandomValue(selfld_BusinessImpact);  
     return this;  
   }  
   public ReportAnIssueModal selectTypeOfIssue(String text) {  
     super.selectOptionByText(selfld_TypeOfIssue, text);  
     return this;  
   }  
   public ReportAnIssueModal selectAnyTypeOfIssue() {  
 /*    TypeOfIssue typeOfIssue = TypeOfIssue.getRandomValue();  
     this.setTypeOfIssue(typeOfIssue);  
     //Type of issue has index as value unlike other elements  
     super.selectOptionByRandomIndex(selfld_TypeOfIssue, typeOfIssue.getIndex());*/  
     super.selectOptionByRandomValue(selfld_TypeOfIssue);  
     return this;  
   }  
   public ReportAnIssueModal selectCategory(String text) {  
     super.selectOptionByText(selfld_Category, text);  
     return this;  
   }  
   public ReportAnIssueModal selectAnyCategory() {  
    /* super.selectOptionByRandomIndex(selfld_Category,  
         this.getTypeOfIssue().getCategorySize());*/  
     super.selectOptionByRandomValue(selfld_Category);  
     return this;  
   }  
   public ReportAnIssueModal fillInPleaseDescribeYourIssue(String text) {  
     super.populateTextField(txtarea_DescribeIssue, text); //Category has index as value unlike other elements  
     return this;  
   }  
   public ReportAnIssueModal clickOnSubmitButton() {  
     super.clickOnButton(btn_Submit_Anchor);  
     return this;  
   }  
   public HomePage clickOnCloseButton() {  
     super.clickOnButton(img_GreenChecMark);  
     return (HomePage) super.getParentPage();  
   }  
 } 

AbstractModal

package com.mridul.framework.selenium.modals;  
 import com.mridul.framework.selenium.interfaces.AbstractContainer;  
 import com.mridul.framework.selenium.pages.AbstractPage;  
 import org.openqa.selenium.WebDriver;  
 /**  
  * Created by Mridul on 3/11/2016.  
  */  
 public abstract class AbstractModal extends AbstractContainer {  
   //parents  
   private AbstractPage parentPage;  
   public AbstractModal(WebDriver driver, AbstractPage parentPage){  
     super(driver);  
     this.parentPage=parentPage;  
   }  
   protected AbstractPage getParentPage(){  
       return parentPage;  
   }  
 }  

Package Structure


ApplicationConfig

package com.mridul.framework.selenium.pages;  
 import com.mridul.framework.selenium.interfaces.AbstractContainer;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.support.ui.ExpectedCondition;  
 /**  
  * Created by Mridul on 3/10/2016.  
  */  
 public abstract class AbstractPage extends AbstractContainer {  
   public AbstractPage(WebDriver driver){  
     super(driver);  
   }  
   protected void getURL(String url){  
     driver.manage().window().maximize();  
     driver.get(url);  
     ////TODO-format into separate code sometime  
     wait.until(new ExpectedCondition<Boolean>() {  
       public Boolean apply(WebDriver webDriver) {  
         return ((JavascriptExecutor) driver).executeScript(  
             "return document.readyState"  
         ).equals("complete");  
       }  
     });  
     driver.switchTo().defaultContent();  
     //invoking validate anchors  
     validateAnchors();  
   }  
   public String getCurrentURL(){  
     return driver.getCurrentUrl();  
   }  
   public void closePage(){  
     driver.quit();  
   }  
 }  

AbstractContainer

package com.mridul.framework.selenium.interfaces;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.interactions.Actions;  
 import org.openqa.selenium.support.PageFactory;  
 import org.openqa.selenium.support.ui.ExpectedCondition;  
 import org.openqa.selenium.support.ui.ExpectedConditions;  
 import org.openqa.selenium.support.ui.Select;  
 import org.openqa.selenium.support.ui.WebDriverWait;  
 import org.springframework.context.ApplicationContext;  
 import java.util.Collections;  
 import java.util.List;  
 import java.util.NoSuchElementException;  
 import java.util.concurrent.ThreadLocalRandom;  
 import java.util.concurrent.TimeUnit;  
 /**  
  * Created by Mridul on 3/11/2016.  
  */  
 public abstract class AbstractContainer {  
   private ApplicationContext context;  
   protected WebDriver driver;  
   protected WebDriverWait wait;  
   private Actions actions;  
   private String containerId;  
   public AbstractContainer(WebDriver driver) {  
     ////TODO-Fix spring injection  
     //driver=(WebDriver)context.getBean("chrome");  
     this.driver = driver;  
     PageFactory.initElements(driver, this);  
     wait = new WebDriverWait(driver, 10);  
     actions=new Actions(driver);  
     this.containerId = driver.getWindowHandle();  
     driver.switchTo().window(containerId);  
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
   }  
   protected Actions getActionsDriver(){  
     return actions;  
   }  
   protected String getWindowHandle() {  
     return containerId;  
   }  
   private WebElement waitUntilElementIsVisible(WebElement element) {  
     element = wait.until(ExpectedConditions.elementToBeClickable(element));  
     //highLightElement(element);  
     if (element == null) {  
       throw new RuntimeException("Element: " + element + " is not visible!");  
     }  
     return element;  
   }  
   private void highLightElement(WebElement element) {  
       JavascriptExecutor js = (JavascriptExecutor) driver;  
       js.executeScript(  
           //"arguments[0].setAttribute('style', 'border: 3px solid red;');",  
           "arguments[0].setAttribute('style', 'background: red;');",  
           element);  
   }  
   protected void hoverOverElementsAndClick(WebElement... elements){  
     for(WebElement element: elements) {  
       wait.until(ExpectedConditions.visibilityOf(element));  
        actions=actions.moveToElement(element);  
     }  
     actions.click().build().perform();  
   }  
   protected void switchToIFrame(WebElement element) {  
     element = waitUntilElementIsVisible(element);  
     driver.switchTo().frame(element);  
   }  
   protected void populateTextField(WebElement textField, String text) {  
     textField = waitUntilElementIsVisible(textField);  
     textField.click();  
     textField.clear();  
     textField.sendKeys(text);  
   }  
   protected void checkOnCheckBox(WebElement chkbox) {  
     chkbox = waitUntilElementIsVisible(chkbox);  
     if (!chkbox.isSelected())  
       chkbox.click();  
   }  
   protected void unCheckOnCheckBox(WebElement chkbox) {  
     chkbox = waitUntilElementIsVisible(chkbox);  
     if (chkbox.isSelected())  
       chkbox.click();  
   }  
   protected void clickOnButton(WebElement button) {  
     clickOnElement(button);  
   }  
   protected void clickOnWebElement(WebElement element) {  
     clickOnElement(element);  
   }  
   private void clickOnElement(WebElement element) {  
     element = waitUntilElementIsVisible(element);  
     element.click();  
   }  
   protected void selectOptionByText(WebElement selectField, String text) {  
     Select dropdown = wrapAsSelect(selectField);  
 /*    dropdown.getOptions().forEach(option -> {if(option.getText().equalsIgnoreCase(text)){  
       option.click();  
     }});*/  
     dropdown.selectByVisibleText(text.trim());  
   }  
   protected void selectOptionByIndex(WebElement selectField, int index) {  
     Select dropdown = wrapAsSelect(selectField);  
     dropdown.selectByIndex(index);  
   }  
   protected void selectOptionByRandomIndex(WebElement selectField, int maxOptions) {  
     selectOptionByRandomIndex(selectField, 1, maxOptions);  
   }  
   protected int selectOptionByRandomIndex(WebElement selectField, int startIndex, int maxOptions) {  
     Select dropdown = wrapAsSelect(selectField);  
     //int outerBound = maxOptions + 1;  
     int index;  
     do {  
       index = ThreadLocalRandom.current().nextInt(startIndex, maxOptions);  
       if(dropdown.getFirstSelectedOption().getText().contains("None") ||  
           dropdown.getFirstSelectedOption().getText().contains("Other")){  
         continue;  
       }  
     } while (index == 0 || index == maxOptions);  
     dropdown.selectByIndex(index);  
     return index;  
   }  
   ////TODO-Not fully implemented  
   protected void selectOptionByRandomValue(WebElement selectField) {  
     Select dropdown = wrapAsSelect(selectField);  
     WebElement firstOption=dropdown.getFirstSelectedOption();  
     List<WebElement> dropdownOptions=dropdown.getOptions();  
     dropdownOptions.remove(firstOption);//remove the first element  
     Collections.shuffle(dropdownOptions); //shuffles the data for randomness  
     for(WebElement option: dropdownOptions){  
       String text=option.getAttribute("value").trim();  
       if (option.equals(firstOption) || text.equalsIgnoreCase("Other")){  
         continue;  
       }else {  
         dropdown.selectByVisibleText(option.getText());  
         break;  
       }  
     }  
   }  
   private Select wrapAsSelect(WebElement element) {  
     element = waitUntilElementIsVisible(element);  
     Select dropdown = new Select(element);  
     if (dropdown.getOptions().size() == 0) {  
       throw new RuntimeException("Dropdown: " + dropdown + " has no options to select!");  
     }  
     return dropdown;  
   }  
   // template method implemented in child classes  
   protected abstract List<WebElement> registerAnchors();  
   protected final boolean validateAnchors() {  
     List<WebElement> anchors = registerAnchors();  
     Boolean anchorFlag = Boolean.TRUE;  
     if (anchors == null) {  
       throw new NoSuchElementException("Page Anchors are not set or could not be identified! ");  
     } else {  
       for (WebElement elem : anchors) {  
         anchorFlag = anchorFlag && wait.until(new ExpectedCondition<Boolean>() {  
           @Override  
           public Boolean apply(WebDriver d) {  
             return elem.isDisplayed();  
           }  
         });  
       }  
     }  
     return anchorFlag;  
   }  
   //Fluent wrappers  
   public abstract <T extends AbstractContainer> T and();  
   public abstract <T extends AbstractContainer> T then();  
   public void sleep(double seconds)  
   {  
     try {  
       Thread.sleep((long)seconds * 1000);  
     } catch (InterruptedException e) {  
     }  
   }  
 }