├── demo.xlsx ├── drivers ├── chromedriver ├── chromedriver.exe └── geckodriver ├── log4j.properties ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── hybridFramework │ │ ├── PageObject │ │ ├── HomePage.java │ │ ├── LoginPage.java │ │ ├── MyAccountPage.java │ │ ├── ProductCategoryPage.java │ │ ├── RegistrationPage.java │ │ └── ShoppinCartSummaryPage.java │ │ ├── config │ │ ├── config.properties │ │ └── or.properties │ │ ├── data │ │ └── TestData.xlsx │ │ ├── database │ │ └── DataBase.java │ │ ├── excelReader │ │ └── Excel_reader.java │ │ ├── excelTutorial │ │ ├── A.java │ │ ├── ColorAnyCellInRangeWhoseValueIsBetweenAconfiguredRange.java │ │ ├── FormatDuplicates.java │ │ ├── ReadDataFromExcelSheet.java │ │ ├── UpdateTestResultInExcel.java │ │ ├── WriteFormulaInExcelSheet.java │ │ └── WriteToExcel.java │ │ ├── helper │ │ ├── Alert │ │ │ └── AlertHelper.java │ │ ├── Browser │ │ │ └── BrowserHelper.java │ │ ├── DropDown │ │ │ └── DropDownHelper.java │ │ ├── Javascript │ │ │ └── JavaScriptHelper.java │ │ ├── Logger │ │ │ └── LoggerHelper.java │ │ ├── Wait │ │ │ └── WaitHelper.java │ │ ├── assertionHelper │ │ │ └── VerificationHelper.java │ │ └── genericHelper │ │ │ └── GenericHelper.java │ │ ├── properties │ │ └── homepage.properties │ │ ├── testBase │ │ ├── Config.java │ │ └── TestBase.java │ │ └── utility │ │ ├── DateTimeHelper.java │ │ └── ResourceHelper.java └── resources │ └── log4j.properties └── test └── java └── com └── hybridFramework ├── homepage ├── A.java ├── DBTest.java ├── TestDaataDrivenScript1.java └── TestDataDriverScript.java ├── loginPage └── LoginTest.java ├── productDetailsPage ├── VerifyColorFilter.java ├── VerifyInformationLinkText.java ├── VerifyLowestFirstPriceFilter.java └── VerifyProductCounts.java └── registration └── Registration.java /demo.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/demo.xlsx -------------------------------------------------------------------------------- /drivers/chromedriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/drivers/chromedriver -------------------------------------------------------------------------------- /drivers/chromedriver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/drivers/chromedriver.exe -------------------------------------------------------------------------------- /drivers/geckodriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/drivers/geckodriver -------------------------------------------------------------------------------- /log4j.properties: -------------------------------------------------------------------------------- 1 | # Define the root logger with appender file 2 | log4j.rootLogger = INFO, FILE,stdout 3 | 4 | # Define the file appender 5 | log4j.appender.FILE=org.apache.log4j.FileAppender 6 | log4j.appender.FILE.File=automation.out 7 | log4j.appender.FILE.Append=true 8 | log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 10 | log4j.appender.file.MaxFileSize=4MB 11 | log4j.appender.file.MaxBackupIndex=9 12 | 13 | # Define the layout for file appender 14 | #log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 15 | #log4j.appender.FILE.layout.conversionPattern=%m%n 16 | 17 | # Direct log messages to stdout 18 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 19 | log4j.appender.stdout.Target=System.out 20 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com 7 | hybridFramework 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | hybridFramework 12 | http://maven.apache.org 13 | 14 | 15 | UTF-8 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.seleniumhq.selenium 23 | selenium-java 24 | 3.141.59 25 | 26 | 27 | 28 | org.testng 29 | testng 30 | 6.10 31 | 32 | 33 | 34 | org.apache.poi 35 | poi 36 | 3.9 37 | 38 | 39 | 40 | org.apache.poi 41 | poi-ooxml 42 | 3.9 43 | 44 | 45 | 46 | 47 | log4j 48 | log4j 49 | 1.2.17 50 | 51 | 52 | 53 | com.relevantcodes 54 | extentreports 55 | 2.40.2 56 | 57 | 58 | 59 | xml-apis 60 | xml-apis 61 | 1.4.01 62 | 63 | 64 | 65 | mysql 66 | mysql-connector-java 67 | 6.0.5 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/HomePage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.PageFactory; 10 | 11 | import com.hybridFramework.helper.Logger.LoggerHelper; 12 | import com.hybridFramework.helper.Wait.WaitHelper; 13 | import com.hybridFramework.testBase.Config; 14 | import com.hybridFramework.testBase.TestBase; 15 | 16 | /** 17 | * 18 | * @author Bhanu Pratap 19 | * https://www.youtube.com/user/MrBhanupratap29/playlists 20 | */ 21 | public class HomePage { 22 | 23 | WebDriver driver; 24 | private final Logger log = LoggerHelper.getLogger(HomePage.class); 25 | WaitHelper waitHelper; 26 | 27 | String Tshirts = "T-shirts"; 28 | String Blouses = "Blouses"; 29 | String CasualDresses = "Casual Dresses"; 30 | 31 | 32 | @FindBy(xpath="//*[@id='block_top_menu']/ul/li[1]/a") 33 | public WebElement womenMenu; 34 | 35 | @FindBy(xpath="//*[@id='block_top_menu']/ul/li[2]/a") 36 | public WebElement dressesMenu; 37 | 38 | 39 | @FindBy(xpath="//*[@id='block_top_menu']/ul/li[3]/a") 40 | public WebElement tshirtsMenu; 41 | 42 | 43 | public HomePage(WebDriver driver) { 44 | this.driver = driver; 45 | PageFactory.initElements(driver, this); 46 | waitHelper = new WaitHelper(driver); 47 | TestBase testBase = new TestBase(); 48 | waitHelper.waitForElement(driver, womenMenu,new Config(TestBase.OR).getExplicitWait()); 49 | } 50 | 51 | public void mouseOver(String data){ 52 | log.info("doing mouse over on :"+data); 53 | Actions action = new Actions(driver); 54 | action.moveToElement(driver.findElement(By.xpath("//*[contains(text(),'"+data+"')]"))).build().perform(); 55 | } 56 | 57 | public ProductCategoryPage clickOnIntem(String data){ 58 | log.info("clickin on :"+data); 59 | driver.findElement(By.xpath("//*[contains(text(),'"+data+"')]")).click(); 60 | return new ProductCategoryPage(driver); 61 | } 62 | 63 | public ProductCategoryPage clickOnMenu(WebElement element){ 64 | log.info("clickin on : "+element.getText()); 65 | element.click(); 66 | return new ProductCategoryPage(driver); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.PageFactory; 8 | 9 | import com.hybridFramework.helper.Javascript.JavaScriptHelper; 10 | import com.hybridFramework.helper.Logger.LoggerHelper; 11 | import com.hybridFramework.helper.Wait.WaitHelper; 12 | import com.hybridFramework.helper.genericHelper.GenericHelper; 13 | import com.hybridFramework.testBase.Config; 14 | import com.hybridFramework.testBase.TestBase; 15 | 16 | /** 17 | * 18 | * @author Bhanu Pratap 19 | * https://www.youtube.com/user/MrBhanupratap29/playlists 20 | */ 21 | public class LoginPage{ 22 | 23 | WebDriver driver; 24 | private final Logger log = LoggerHelper.getLogger(LoginPage.class); 25 | WaitHelper waitHelper; 26 | 27 | @FindBy(xpath="//*[@id='header']/div[2]/div/div/nav/div[1]/a") 28 | WebElement signin; 29 | 30 | @FindBy(xpath="//*[@id='email']") 31 | WebElement emailAddress; 32 | 33 | @FindBy(xpath="//*[@id='passwd']") 34 | WebElement password; 35 | 36 | @FindBy(xpath="//*[@id='SubmitLogin']") 37 | WebElement submitLogin; 38 | 39 | @FindBy(xpath="//*[@id='center_column']/p") 40 | WebElement successMsgObject; 41 | 42 | @FindBy(xpath="//*[@id='email_create']") 43 | WebElement registration; 44 | 45 | @FindBy(xpath="//*[@id='SubmitCreate']") 46 | WebElement createAnAccount; 47 | 48 | 49 | public LoginPage(WebDriver driver) { 50 | this.driver = driver; 51 | PageFactory.initElements(driver, this); 52 | waitHelper = new WaitHelper(driver); 53 | waitHelper.waitForElement(driver, signin,new Config(TestBase.OR).getExplicitWait()); 54 | } 55 | 56 | public void clickOnSignInLink(){ 57 | log.info("clicked on sign in link..."); 58 | signin.click(); 59 | } 60 | 61 | public void enterEmailAddress(String emailAddress){ 62 | log.info("entering email address...."+emailAddress); 63 | this.emailAddress.sendKeys(emailAddress); 64 | } 65 | 66 | public void enterPassword(String password){ 67 | log.info("entering password...."+password); 68 | this.password.sendKeys(password); 69 | } 70 | 71 | public HomePage clickOnSubmitButton(){ 72 | log.info("clicking on submit button..."); 73 | new JavaScriptHelper(driver).scrollDownVertically(); 74 | submitLogin.click(); 75 | return new HomePage(driver); 76 | } 77 | 78 | public boolean verifySuccessLoginMsg(){ 79 | return new GenericHelper().isDisplayed(successMsgObject); 80 | } 81 | 82 | public void enterRegistrationEmail(){ 83 | String email = System.currentTimeMillis()+"@gmail.com"; 84 | log.info("entering registration email.."+email); 85 | registration.sendKeys(email); 86 | } 87 | 88 | public RegistrationPage clickOnCreateAnAccount(){ 89 | createAnAccount.click(); 90 | return new RegistrationPage(driver); 91 | } 92 | 93 | public void loginToApplication(String emailAddress, String password){ 94 | clickOnSignInLink(); 95 | enterEmailAddress(emailAddress); 96 | enterPassword(password); 97 | clickOnSubmitButton(); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/MyAccountPage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.PageFactory; 8 | 9 | import com.hybridFramework.helper.Logger.LoggerHelper; 10 | import com.hybridFramework.helper.Wait.WaitHelper; 11 | import com.hybridFramework.helper.assertionHelper.VerificationHelper; 12 | import com.hybridFramework.testBase.Config; 13 | import com.hybridFramework.testBase.TestBase; 14 | /** 15 | * 16 | * @author Bhanu Pratap 17 | * https://www.youtube.com/user/MrBhanupratap29/playlists 18 | */ 19 | public class MyAccountPage { 20 | 21 | WebDriver driver; 22 | private final Logger log = LoggerHelper.getLogger(MyAccountPage.class); 23 | WaitHelper waitHelper; 24 | 25 | @FindBy(xpath="//*[contains(text(),'Welcome to your account. Here you can manage all of your personal information and orders.')]") 26 | WebElement successRegistrationMsg; 27 | 28 | @FindBy(xpath="//*[contains(text(),'Order history and details')]") 29 | WebElement OrderHistoryAndDetails; 30 | 31 | @FindBy(xpath="//*[contains(text(),'My personal information')]") 32 | WebElement MyPersonalInformation; 33 | 34 | public MyAccountPage(WebDriver driver) { 35 | this.driver = driver; 36 | PageFactory.initElements(driver, this); 37 | waitHelper = new WaitHelper(driver); 38 | waitHelper.waitForElement(driver, OrderHistoryAndDetails,new Config(TestBase.OR).getExplicitWait()); 39 | } 40 | 41 | public boolean verifySuccessRegistrationMsg(){ 42 | return VerificationHelper.verifyElementPresent(successRegistrationMsg); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/ProductCategoryPage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.log4j.Logger; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.interactions.Actions; 10 | import org.openqa.selenium.support.FindBy; 11 | import org.openqa.selenium.support.PageFactory; 12 | 13 | import com.hybridFramework.helper.DropDown.DropDownHelper; 14 | import com.hybridFramework.helper.Javascript.JavaScriptHelper; 15 | import com.hybridFramework.helper.Logger.LoggerHelper; 16 | import com.hybridFramework.helper.Wait.WaitHelper; 17 | import com.hybridFramework.helper.assertionHelper.VerificationHelper; 18 | import com.hybridFramework.testBase.Config; 19 | import com.hybridFramework.testBase.TestBase; 20 | /** 21 | * 22 | * @author Bhanu Pratap 23 | * https://www.youtube.com/user/MrBhanupratap29/playlists 24 | */ 25 | public class ProductCategoryPage { 26 | 27 | WebDriver driver; 28 | private final Logger log = LoggerHelper.getLogger(ProductCategoryPage.class); 29 | WaitHelper waitHelper; 30 | 31 | public String Black = "Black"; 32 | public String Orange = "Orange"; 33 | public String Yellow = "Yellow"; 34 | 35 | @FindBy(xpath="//*[@id='layered_block_left']/p") 36 | WebElement catalogTextObj; 37 | 38 | @FindBy(xpath="//*[@id='layer_cart']/div[1]/div[1]/h2") 39 | WebElement productAddedSucessfully; 40 | 41 | @FindBy(xpath="//*[@id='center_column']/ul/li[4]/div/div[2]/div[2]/a[1]/span") 42 | WebElement addToCart; 43 | 44 | @FindBy(xpath="//*[@id='layer_cart']/div[1]/div[2]/div[4]/a/span") 45 | WebElement proceedToCheckOut; 46 | 47 | @FindBy(xpath="//*[@id='center_column']/ul/li") 48 | List totalProducts; 49 | 50 | @FindBy(xpath="//*[@id='selectProductSort']") 51 | public WebElement sortBy; 52 | 53 | @FindBy(xpath="//*[@id='center_column']/ul/li/div/div[2]/div/span[1]") 54 | List allpriceElements; 55 | 56 | 57 | public ProductCategoryPage(WebDriver driver) { 58 | this.driver = driver; 59 | PageFactory.initElements(driver, this); 60 | waitHelper = new WaitHelper(driver); 61 | waitHelper.waitForElement(driver, catalogTextObj,new Config(TestBase.OR).getExplicitWait()); 62 | } 63 | 64 | public void mouseOverOnProduct(int number){ 65 | String fPart = "//*[@id='center_column']/ul/li["; 66 | String sPart = "]/div/div[2]/h5/a"; 67 | Actions action = new Actions(driver); 68 | log.info("doing mouse over on: "+number+"..product"); 69 | action.moveToElement(driver.findElement(By.xpath(fPart+number+sPart))).build().perform(); 70 | } 71 | 72 | public void clickOnAddToCart(){ 73 | log.info("clickin on add to cart"); 74 | addToCart.click(); 75 | } 76 | 77 | public boolean verifyPoductAddedSuccesfully(){ 78 | return VerificationHelper.verifyElementPresent(productAddedSucessfully); 79 | } 80 | 81 | public void clickOnProceedTocheckOut(){ 82 | log.info("clickin on :"+proceedToCheckOut.getText()); 83 | proceedToCheckOut.click(); 84 | } 85 | 86 | public void selectColor(String data){ 87 | new JavaScriptHelper(driver).scrollIntoView(driver.findElement(By.xpath("//a[contains(text(),'"+data+"')]/parent::*/preceding-sibling::input[1]"))); 88 | driver.findElement(By.xpath("//a[contains(text(),'"+data+"')]/parent::*/preceding-sibling::input[1]")).click(); 89 | try { 90 | Thread.sleep(7000); 91 | } catch (InterruptedException e) { 92 | e.printStackTrace(); 93 | } 94 | } 95 | 96 | public void selectSmallSize() { 97 | log.info("selecting small size.."); 98 | driver.findElement(By.xpath("//*[@id='layered_id_attribute_group_1']")).click(); 99 | } 100 | 101 | public void selectMediumSize() { 102 | log.info("selecting Medium size.."); 103 | try { 104 | boolean selected = driver.findElement(By.xpath("//*[@id='layered_id_attribute_group_2']']")).isSelected(); 105 | if (!selected) { 106 | driver.findElement(By.xpath("//*[@id='layered_id_attribute_group_2']']")).click(); 107 | log.info("checkbox is checked.."); 108 | } 109 | } catch (Exception e) { 110 | log.info("checkbox was already checked.."); 111 | } 112 | } 113 | 114 | public void selectLSize() { 115 | log.info("selecting Large size.."); 116 | try { 117 | boolean selected = driver.findElement(By.xpath("//*[@id='layered_id_attribute_group_3']")).isSelected(); 118 | if (!selected) { 119 | driver.findElement(By.xpath("//*[@id='layered_id_attribute_group_3']")).click(); 120 | log.info("checkbox is checked.."); 121 | } 122 | } catch (Exception e) { 123 | log.info("checkbox was already checked.."); 124 | } 125 | } 126 | 127 | public void selectFirstProduct() { 128 | Actions obj = new Actions(driver); 129 | log.info("performning mouse over on first product of page.."); 130 | obj.moveToElement(driver.findElements(By.xpath(".//*[@id='center_column']/ul/li")).get(0)).build().perform(); 131 | log.info("clicking on add to basket.."); 132 | driver.findElement(By.xpath(".//*[@id='center_column']/ul/li[1]/div/div[2]/div[2]/a[1]/span")).click(); 133 | } 134 | 135 | public int getTotalProducts(){ 136 | return totalProducts.size(); 137 | } 138 | 139 | public List getAllProductsPrice(){ 140 | return allpriceElements; 141 | } 142 | 143 | public void selectSortByFilter(String dataToSelect){ 144 | DropDownHelper dropdown = new DropDownHelper(driver); 145 | dropdown.SelectUsingVisibleText(sortBy, dataToSelect); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/RegistrationPage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | import org.apache.log4j.Logger; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.FindBy; 11 | import org.openqa.selenium.support.PageFactory; 12 | import org.openqa.selenium.support.ui.Select; 13 | 14 | import com.hybridFramework.helper.Logger.LoggerHelper; 15 | import com.hybridFramework.helper.Wait.WaitHelper; 16 | import com.hybridFramework.testBase.Config; 17 | import com.hybridFramework.testBase.TestBase; 18 | /** 19 | * 20 | * @author Bhanu Pratap 21 | * https://www.youtube.com/user/MrBhanupratap29/playlists 22 | */ 23 | public class RegistrationPage { 24 | 25 | WebDriver driver; 26 | private final Logger log = LoggerHelper.getLogger(RegistrationPage.class); 27 | WaitHelper waitHelper; 28 | 29 | @FindBy(xpath = "//*[@id='id_gender1']") 30 | public WebElement mrRadioButton; 31 | 32 | @FindBy(xpath = ".//*[@id='id_gender2']") 33 | WebElement mrsRadioButton; 34 | 35 | @FindBy(xpath = "//*[@id='customer_firstname']") 36 | WebElement firstName; 37 | 38 | @FindBy(xpath = "//*[@id='customer_lastname']") 39 | WebElement lastname; 40 | 41 | @FindBy(xpath = "//*[@id='email']") 42 | WebElement emailAddress; 43 | 44 | @FindBy(xpath = "//*[@id='passwd']") 45 | WebElement password; 46 | 47 | @FindBy(xpath = "//*[@id='days']") 48 | WebElement days; 49 | 50 | @FindBy(xpath = "//*[@id='months']") 51 | WebElement month; 52 | 53 | @FindBy(xpath = "//*[@id='years']") 54 | WebElement year; 55 | 56 | @FindBy(xpath = "//*[@id='firstname']") 57 | WebElement yourAddressFirstName; 58 | 59 | @FindBy(xpath = "//*[@id='lastname']") 60 | WebElement yourAddressLastName; 61 | 62 | @FindBy(xpath = "//*[@id='company']") 63 | WebElement yourAddressCompany; 64 | 65 | @FindBy(xpath = "//*[@id='address1']") 66 | WebElement address; 67 | 68 | @FindBy(xpath = "//*[@id='address2']") 69 | WebElement address2; 70 | 71 | @FindBy(xpath = "//*[@id='city']") 72 | WebElement yourAddressCity; 73 | 74 | @FindBy(xpath = "//*[@id='id_state']") 75 | WebElement yourAddressState; 76 | 77 | @FindBy(xpath = "//*[@id='postcode']") 78 | WebElement yourAddressPostCode; 79 | 80 | @FindBy(xpath = "//*[@id='id_country']") 81 | WebElement additionalInformation; 82 | 83 | @FindBy(xpath = "//*[@id='phone']") 84 | WebElement homePhone; 85 | 86 | @FindBy(xpath = "//*[@id='phone_mobile']") 87 | WebElement mobilePhone; 88 | 89 | @FindBy(xpath = "//*[@id='alias']") 90 | WebElement addressAlias; 91 | 92 | @FindBy(xpath = "//*[@id='submitAccount']") 93 | WebElement registration; 94 | 95 | public RegistrationPage(WebDriver driver) { 96 | this.driver = driver; 97 | PageFactory.initElements(driver, this); 98 | waitHelper = new WaitHelper(driver); 99 | waitHelper.waitForElement(driver, mrRadioButton,new Config(TestBase.OR).getExplicitWait()); 100 | } 101 | 102 | public void setMrRadioButton() { 103 | log.info("selecting mr checkbox.."); 104 | this.mrRadioButton.click(); 105 | } 106 | 107 | public void setMrsRadioButton() { 108 | log.info("selecting mrs checkbox.."); 109 | this.mrsRadioButton.click(); 110 | } 111 | 112 | public void setFirstName(String firstName) { 113 | log.info("entering firstName.." + firstName); 114 | this.firstName.sendKeys(firstName); 115 | } 116 | 117 | public void setLastname(String lastname) { 118 | log.info("entering lastname.." + lastname); 119 | this.lastname.sendKeys(lastname); 120 | } 121 | 122 | public void setEmailAddress(String emailAddress) { 123 | log.info("entering emailAddress.." + emailAddress); 124 | this.emailAddress.sendKeys(emailAddress); 125 | } 126 | 127 | public void setPassword(String password) { 128 | log.info("entering password.." + password); 129 | this.password.sendKeys(password); 130 | } 131 | 132 | public void setDay(String day) { 133 | List days = driver.findElements(By.xpath("//*[@id='days']/option")); 134 | Iterator itr = days.iterator(); 135 | while (itr.hasNext()) { 136 | WebElement c = itr.next(); 137 | String text = c.getText().trim().toString(); 138 | if (text.equals(day)) { 139 | System.out.println(day); 140 | c.click(); 141 | break; 142 | } 143 | } 144 | } 145 | 146 | public void setMonth(String month) { 147 | 148 | List days = driver.findElements(By.xpath("//*[@id='months']/option")); 149 | Iterator itr = days.iterator(); 150 | while (itr.hasNext()) { 151 | WebElement click = itr.next(); 152 | String text = click.getText().trim(); 153 | if (text.equals(month)) { 154 | click.click(); 155 | break; 156 | } 157 | } 158 | } 159 | 160 | public void setYear(String year) { 161 | 162 | List days = driver.findElements(By.xpath("//*[@id='years']/option")); 163 | Iterator itr = days.iterator(); 164 | while (itr.hasNext()) { 165 | WebElement click = itr.next(); 166 | String text = click.getText().trim(); 167 | if (text.equals(year)) { 168 | click.click(); 169 | break; 170 | } 171 | } 172 | 173 | } 174 | 175 | public void setYourAddressFirstName(String yourAddressFirstName) { 176 | log.info("entering yourAddressFirstName.." + yourAddressFirstName); 177 | this.yourAddressFirstName.sendKeys(yourAddressFirstName); 178 | } 179 | 180 | public void setYourAddressLastName(String yourAddressLastName) { 181 | log.info("entering yourAddressLastName.." + yourAddressLastName); 182 | this.yourAddressLastName.sendKeys(yourAddressLastName); 183 | } 184 | 185 | public void setYourAddressCompany(String yourAddressCompany) { 186 | log.info("entering yourAddressCompany.." + yourAddressCompany); 187 | this.yourAddressCompany.sendKeys(yourAddressCompany); 188 | } 189 | 190 | public void setAddress(String address) { 191 | log.info("entering address.." + address); 192 | this.address.sendKeys(address); 193 | } 194 | 195 | public void setAddress2(String address2) { 196 | log.info("entering address2.." + address2); 197 | this.address2.sendKeys(address2); 198 | } 199 | 200 | public void setYourAddressCity(String yourAddressCity) { 201 | log.info("entering yourAddressCity.." + yourAddressCity); 202 | this.yourAddressCity.sendKeys(yourAddressCity); 203 | } 204 | 205 | public void setYourAddressState(String yourAddressState) { 206 | log.info("entering yourAddressState.." + yourAddressState); 207 | new Select(this.yourAddressState).selectByVisibleText(yourAddressState); 208 | } 209 | 210 | public void setYourAddressPostCode(String yourAddressPostCode) { 211 | log.info("entering yourAddressPostCode.." + yourAddressPostCode); 212 | this.yourAddressPostCode.sendKeys(yourAddressPostCode); 213 | } 214 | 215 | public void setAdditionalInformation(String additionalInformation) { 216 | log.info("entering additionalInformation.." + additionalInformation); 217 | this.additionalInformation.sendKeys(additionalInformation); 218 | } 219 | 220 | public void setHomePhone(String homePhone) { 221 | log.info("entering homePhone.." + homePhone); 222 | this.homePhone.sendKeys(homePhone); 223 | } 224 | 225 | public void setMobilePhone(String mobilePhone) { 226 | log.info("entering mobilePhone.." + mobilePhone); 227 | this.mobilePhone.sendKeys(mobilePhone); 228 | } 229 | 230 | public void setAddressAlias(String addressAlias) { 231 | log.info("entering addressAlias.." + addressAlias); 232 | this.addressAlias.sendKeys(addressAlias); 233 | } 234 | 235 | public void clickRegistration() { 236 | log.info("clicked on registration.." + registration); 237 | this.registration.click(); 238 | } 239 | 240 | } 241 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/PageObject/ShoppinCartSummaryPage.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.PageObject; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | import org.apache.log4j.Logger; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.FindBy; 11 | import org.openqa.selenium.support.PageFactory; 12 | 13 | import com.hybridFramework.helper.Logger.LoggerHelper; 14 | import com.hybridFramework.helper.Wait.WaitHelper; 15 | import com.hybridFramework.helper.assertionHelper.VerificationHelper; 16 | import com.hybridFramework.testBase.Config; 17 | import com.hybridFramework.testBase.TestBase; 18 | /** 19 | * 20 | * @author Bhanu Pratap 21 | * https://www.youtube.com/user/MrBhanupratap29/playlists 22 | */ 23 | public class ShoppinCartSummaryPage { 24 | 25 | WebDriver driver; 26 | private final Logger log = LoggerHelper.getLogger(ShoppinCartSummaryPage.class); 27 | WaitHelper waitHelper; 28 | 29 | @FindBy(xpath="//*[@id='columns']/div[1]/span[2]") 30 | WebElement yourShoppingCart; 31 | 32 | @FindBy(xpath="//*[@id='columns']/div[1]/span[2]") 33 | List quantity_delete; 34 | 35 | @FindBy(xpath="//*[contains(text(),'Your shopping cart is empty')]") 36 | WebElement emptyShoppingCartMsg; 37 | 38 | public ShoppinCartSummaryPage(WebDriver driver) { 39 | this.driver = driver; 40 | PageFactory.initElements(driver, this); 41 | waitHelper = new WaitHelper(driver); 42 | waitHelper.waitForElement(driver, yourShoppingCart,new Config(TestBase.OR).getExplicitWait()); 43 | } 44 | 45 | public boolean verifyProduct(String prod){ 46 | log.info("selecting product.."+prod); 47 | WebElement product = driver.findElement(By.xpath("//*[contains(text(),'"+prod+"')]")); 48 | return VerificationHelper.verifyElementPresent(product); 49 | } 50 | 51 | public void delectProductFromShoppingCart() throws InterruptedException { 52 | // Delete all items from cart 53 | log.info("Deleting all products from cart.."); 54 | List deletes = quantity_delete; 55 | Iterator itr = deletes.iterator(); 56 | while (itr.hasNext()) { 57 | itr.next().click(); 58 | Thread.sleep(2000); 59 | } 60 | } 61 | 62 | public boolean verifyEmptyShoppingCartMesssage(){ 63 | try { 64 | log.info("verifying deleted Shopping Cart Messsage.."); 65 | emptyShoppingCartMsg.isDisplayed(); 66 | return true; 67 | } catch (Exception e) { 68 | return false; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/config/config.properties: -------------------------------------------------------------------------------- 1 | Username=learnbybhanu@gmail.com 2 | Password=welcome 3 | Browser=Chrome 4 | Website=http://automationpractice.com/index.php? 5 | PageLoadTimeOut=240 6 | ImplcitWait=20 7 | ExplicitWait=60 8 | Logger.Level=INFO 9 | DataBase.Type= 10 | DtaBase.ConnectionStr= -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/config/or.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/src/main/java/com/hybridFramework/config/or.properties -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/data/TestData.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/seleniumHybridFramework/f3a178bd54ffd16739fd7387dfc1d9c775f18210/src/main/java/com/hybridFramework/data/TestData.xlsx -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/database/DataBase.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.database; 2 | 3 | 4 | import java.sql.Connection; 5 | import java.sql.DriverManager; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | 10 | /** 11 | * @author Bhanu Pratap 12 | * https://www.youtube.com/user/MrBhanupratap29/playlists 13 | */ 14 | public class DataBase { 15 | public Connection con; 16 | public Statement stmt; 17 | 18 | public Statement getStatement() throws ClassNotFoundException, SQLException{ 19 | try { 20 | String driver = "com.mysql.cj.jdbc.Driver"; 21 | String connection = "jdbc:mysql://localhost:3306/customer"; 22 | String userName = "root"; 23 | String password = "password"; 24 | Class.forName(driver); 25 | con = DriverManager.getConnection(connection, userName, password); 26 | stmt = con.createStatement(); 27 | return stmt; 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | return stmt; 32 | } 33 | 34 | public void insertData(String query) throws ClassNotFoundException, SQLException{ 35 | Statement sta = getStatement(); 36 | sta.executeUpdate(query); 37 | } 38 | 39 | public ResultSet getData(String query) throws ClassNotFoundException, SQLException{ 40 | ResultSet data = getStatement().executeQuery(query); 41 | return data; 42 | } 43 | 44 | public void updateData(String query) throws ClassNotFoundException, SQLException{ 45 | getStatement().executeUpdate(query); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelReader/Excel_reader.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelReader; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.util.Iterator; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.apache.poi.ss.usermodel.Cell; 9 | import org.apache.poi.ss.usermodel.Row; 10 | import org.apache.poi.xssf.usermodel.XSSFSheet; 11 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 12 | 13 | public class Excel_reader { 14 | 15 | public static final Logger logger = Logger.getLogger(Excel_reader.class.getName()); 16 | 17 | public String[][] getExcelData(String excellocation, String sheetName) { 18 | try { 19 | logger.info("Creating excel object:-"+excellocation); 20 | String dataSets[][] = null; 21 | 22 | FileInputStream file = new FileInputStream(new File(excellocation)); 23 | 24 | // Create Workbook instance holding reference to .xlsx file 25 | XSSFWorkbook workbook = new XSSFWorkbook(file); 26 | 27 | // Get first/desired sheet from the workbook 28 | XSSFSheet sheet = workbook.getSheet(sheetName); 29 | // count number of active tows 30 | int totalRow = sheet.getLastRowNum() + 1; 31 | // count number of active columns in row 32 | int totalColumn = sheet.getRow(0).getLastCellNum(); 33 | // Create array of rows and column 34 | dataSets = new String[totalRow-1][totalColumn]; 35 | // Iterate through each rows one by one 36 | Iterator rowIterator = sheet.iterator(); 37 | 38 | int i = 0; 39 | int t = 0; 40 | 41 | while (rowIterator.hasNext()) { 42 | Row row = rowIterator.next(); 43 | if (i++ != 0) { 44 | int k = t; 45 | t++; 46 | // For each row, iterate through all the columns 47 | Iterator cellIterator = row.cellIterator(); 48 | int j = 0; 49 | while (cellIterator.hasNext()) { 50 | 51 | Cell cell = cellIterator.next(); 52 | // Check the cell type and format accordingly 53 | switch (cell.getCellType()) { 54 | case Cell.CELL_TYPE_NUMERIC: 55 | System.out.print(k+","); 56 | System.out.print(j+","); 57 | dataSets[k][j++] = cell.getStringCellValue(); 58 | System.out.println(cell.getNumericCellValue()); 59 | break; 60 | case Cell.CELL_TYPE_STRING: 61 | System.out.print(k+","); 62 | System.out.print(j+","); 63 | dataSets[k][j++] = cell.getStringCellValue(); 64 | System.out.println(cell.getStringCellValue()); 65 | break; 66 | case Cell.CELL_TYPE_BOOLEAN: 67 | System.out.print(k+","); 68 | System.out.print(j+","); 69 | dataSets[k][j++] = cell.getStringCellValue(); 70 | System.out.println(cell.getStringCellValue()); 71 | break; 72 | case Cell.CELL_TYPE_FORMULA: 73 | System.out.print(k+","); 74 | System.out.print(j+","); 75 | dataSets[k][j++] = cell.getStringCellValue(); 76 | System.out.println(cell.getStringCellValue()); 77 | break; 78 | } 79 | } 80 | System.out.println(""); 81 | } 82 | } 83 | 84 | file.close(); 85 | return dataSets; 86 | } catch (Exception e) { 87 | e.printStackTrace(); 88 | } 89 | return null; 90 | } 91 | 92 | public static void main(String[] args) { 93 | String excellocation = "/Users/bsingh5/git/seleniumHybridFramework/hybridFramework/src/main/java/com/hybridFramework/data/TestData.xlsx"; 94 | String sheetName = "LoginTestData"; 95 | Excel_reader excel = new Excel_reader(); 96 | excel.getExcelData(excellocation, sheetName); 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/A.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.IOException; 4 | 5 | public class A { 6 | 7 | public static void main(String[] args) throws IOException { 8 | String excellocation = System.getProperty("user.dir") + "/demo.xlsx"; 9 | UpdateTestResultInExcel.updateResult(excellocation, "TestReport", "Registration", "Pass"); 10 | UpdateTestResultInExcel.updateResult(excellocation, "TestReport", "Payment", "Fail"); 11 | UpdateTestResultInExcel.updateResult(excellocation, "TestReport", "CancelTest", "Pass"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/ColorAnyCellInRangeWhoseValueIsBetweenAconfiguredRange.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | 9 | import org.apache.poi.ss.usermodel.ComparisonOperator; 10 | import org.apache.poi.ss.usermodel.ConditionalFormattingRule; 11 | import org.apache.poi.ss.usermodel.FormulaEvaluator; 12 | import org.apache.poi.ss.usermodel.IndexedColors; 13 | import org.apache.poi.ss.usermodel.PatternFormatting; 14 | import org.apache.poi.ss.usermodel.SheetConditionalFormatting; 15 | import org.apache.poi.ss.util.CellRangeAddress; 16 | import org.apache.poi.xssf.usermodel.XSSFSheet; 17 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 18 | 19 | public class ColorAnyCellInRangeWhoseValueIsBetweenAconfiguredRange { 20 | 21 | public static void main(String[] args) throws IOException { 22 | 23 | FileInputStream file = new FileInputStream(new File("Demoformula.xlsx")); 24 | 25 | // Create Workbook instance holding reference to .xlsx file 26 | XSSFWorkbook workbook = new XSSFWorkbook(file); 27 | 28 | // Get first/desired sheet from the workbook 29 | XSSFSheet sheet = workbook.getSheetAt(0); 30 | 31 | // Creating some random values 32 | sheet.createRow(0).createCell(0).setCellValue(84); 33 | sheet.createRow(1).createCell(0).setCellValue(74); 34 | sheet.createRow(2).createCell(0).setCellValue(50); 35 | sheet.createRow(3).createCell(0).setCellValue(51); 36 | sheet.createRow(4).createCell(0).setCellValue(49); 37 | sheet.createRow(5).createCell(0).setCellValue(41); 38 | 39 | SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); 40 | 41 | // Condition 1: Cell Value Is greater than 70 (Blue Fill) 42 | ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.GT, "70"); 43 | PatternFormatting fill1 = rule1.createPatternFormatting(); 44 | fill1.setFillBackgroundColor(IndexedColors.BLUE.index); 45 | fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); 46 | 47 | // Condition 2: Cell Value Is less than 50 (Green Fill) 48 | ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.LT, "50"); 49 | PatternFormatting fill2 = rule2.createPatternFormatting(); 50 | fill2.setFillBackgroundColor(IndexedColors.GREEN.index); 51 | fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND); 52 | 53 | CellRangeAddress[] regions = { CellRangeAddress.valueOf("A1:A6") }; 54 | 55 | sheetCF.addConditionalFormatting(regions, rule1, rule2); 56 | 57 | 58 | try { 59 | FileOutputStream out = new FileOutputStream(new File("Demoformula.xlsx")); 60 | workbook.write(out); 61 | out.close(); 62 | System.out.println("Excel with foumula cells written successfully"); 63 | 64 | } catch (FileNotFoundException e) { 65 | e.printStackTrace(); 66 | } catch (IOException e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/FormatDuplicates.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | 9 | import org.apache.poi.ss.usermodel.ConditionalFormattingRule; 10 | import org.apache.poi.ss.usermodel.FontFormatting; 11 | import org.apache.poi.ss.usermodel.IndexedColors; 12 | import org.apache.poi.ss.usermodel.SheetConditionalFormatting; 13 | import org.apache.poi.ss.util.CellRangeAddress; 14 | import org.apache.poi.xssf.usermodel.XSSFSheet; 15 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 16 | 17 | /** 18 | * @author Bhanu Pratap 19 | * https://www.youtube.com/user/MrBhanupratap29/playlists 20 | */ 21 | public class FormatDuplicates { 22 | 23 | public static void main(String[] args) throws IOException { 24 | FileInputStream file = new FileInputStream(new File("Demoformula.xlsx")); 25 | 26 | // Create Workbook instance holding reference to .xlsx file 27 | XSSFWorkbook workbook = new XSSFWorkbook(file); 28 | 29 | // Get first/desired sheet from the workbook 30 | XSSFSheet sheet = workbook.getSheetAt(0); 31 | sheet.createRow(0).createCell(0).setCellValue("Code"); 32 | sheet.createRow(1).createCell(0).setCellValue(4); 33 | sheet.createRow(2).createCell(0).setCellValue(3); 34 | sheet.createRow(3).createCell(0).setCellValue(6); 35 | sheet.createRow(4).createCell(0).setCellValue(3); 36 | sheet.createRow(5).createCell(0).setCellValue(5); 37 | sheet.createRow(6).createCell(0).setCellValue(8); 38 | sheet.createRow(7).createCell(0).setCellValue(0); 39 | sheet.createRow(8).createCell(0).setCellValue(2); 40 | sheet.createRow(9).createCell(0).setCellValue(8); 41 | sheet.createRow(10).createCell(0).setCellValue(6); 42 | 43 | SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); 44 | 45 | // Condition 1: Formula Is =A2=A1 (White Font) 46 | ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("COUNTIF($A$2:$A$11,A2)>1"); 47 | FontFormatting font = rule1.createFontFormatting(); 48 | font.setFontStyle(false, true); 49 | font.setFontColorIndex(IndexedColors.BLUE.index); 50 | 51 | CellRangeAddress[] regions = { 52 | CellRangeAddress.valueOf("A2:A11") 53 | }; 54 | 55 | sheetCF.addConditionalFormatting(regions, rule1); 56 | 57 | sheet.getRow(2).createCell(1).setCellValue("<== Duplicates numbers in the column are highlighted. " + 58 | "Condition: Formula Is =COUNTIF($A$2:$A$11,A2)>1 (Blue Font)"); 59 | 60 | try { 61 | FileOutputStream out = new FileOutputStream(new File("Demoformula.xlsx")); 62 | workbook.write(out); 63 | out.close(); 64 | System.out.println("Excel with foumula cells written successfully"); 65 | 66 | } catch (FileNotFoundException e) { 67 | e.printStackTrace(); 68 | } catch (IOException e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/ReadDataFromExcelSheet.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.util.Iterator; 6 | 7 | import org.apache.poi.ss.usermodel.Cell; 8 | import org.apache.poi.ss.usermodel.Row; 9 | import org.apache.poi.xssf.usermodel.XSSFSheet; 10 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 11 | 12 | /** 13 | * @author Bhanu Pratap 14 | * https://www.youtube.com/user/MrBhanupratap29/playlists 15 | */ 16 | public class ReadDataFromExcelSheet { 17 | 18 | 19 | public static void main(String[] args) 20 | { 21 | try 22 | { 23 | FileInputStream file = new FileInputStream(new File("demo.xlsx")); 24 | 25 | //Create Workbook instance holding reference to .xlsx file 26 | XSSFWorkbook workbook = new XSSFWorkbook(file); 27 | 28 | //Get first/desired sheet from the workbook 29 | XSSFSheet sheet = workbook.getSheetAt(1); 30 | 31 | //Iterate through each rows one by one 32 | Iterator rowIterator = sheet.iterator(); 33 | while (rowIterator.hasNext()) 34 | { 35 | Row row = rowIterator.next(); 36 | //For each row, iterate through all the columns 37 | Iterator cellIterator = row.cellIterator(); 38 | 39 | while (cellIterator.hasNext()) 40 | { 41 | Cell cell = cellIterator.next(); 42 | //Check the cell type and format accordingly 43 | switch (cell.getCellType()) 44 | { 45 | case Cell.CELL_TYPE_NUMERIC: 46 | System.out.print(cell.getNumericCellValue() + " "); 47 | break; 48 | case Cell.CELL_TYPE_STRING: 49 | System.out.print(cell.getStringCellValue() + " "); 50 | break; 51 | } 52 | } 53 | System.out.println(""); 54 | } 55 | file.close(); 56 | } 57 | catch (Exception e) 58 | { 59 | e.printStackTrace(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/UpdateTestResultInExcel.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import org.apache.poi.xssf.usermodel.XSSFRow; 8 | import org.apache.poi.xssf.usermodel.XSSFSheet; 9 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 10 | 11 | /** 12 | * @author Bhanu Pratap 13 | * https://www.youtube.com/user/MrBhanupratap29/playlists 14 | */ 15 | public class UpdateTestResultInExcel { 16 | 17 | public static void updateResult(String excellocation, String sheetName, String testCaseName, String testStatus) 18 | throws IOException { 19 | 20 | FileInputStream file = new FileInputStream(new File(excellocation)); 21 | 22 | // Create Workbook instance holding reference to .xlsx file 23 | XSSFWorkbook workbook = new XSSFWorkbook(file); 24 | 25 | // Get first/desired sheet from the workbook 26 | XSSFSheet sheet = workbook.getSheet(sheetName); 27 | // count number of active tows 28 | int totalRow = sheet.getLastRowNum() + 1; 29 | // count number of active columns in row 30 | for (int i = 1; i < totalRow; i++) { 31 | XSSFRow r = sheet.getRow(i); 32 | String ce = r.getCell(1).getStringCellValue(); 33 | if (ce.contains(testCaseName)) { 34 | 35 | r.createCell(2).setCellValue(testStatus); 36 | file.close(); 37 | 38 | System.out.println("done"); 39 | FileOutputStream outFile = new FileOutputStream(new File(excellocation)); 40 | workbook.write(outFile); 41 | outFile.close(); 42 | break; 43 | } 44 | 45 | } 46 | } 47 | 48 | public static void main(String[] args) throws IOException { 49 | String excellocation = System.getProperty("user.dir") + "/demo.xlsx"; 50 | updateResult(excellocation, "TestReport", "Registration", "Pass"); 51 | updateResult(excellocation, "TestReport", "Payment", "Fail"); 52 | updateResult(excellocation, "TestReport", "CancelTest", "Pass"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/WriteFormulaInExcelSheet.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | 8 | import org.apache.poi.ss.usermodel.Row; 9 | import org.apache.poi.xssf.usermodel.XSSFSheet; 10 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 11 | 12 | public class WriteFormulaInExcelSheet { 13 | 14 | public static void main(String[] args) 15 | { 16 | XSSFWorkbook workbook = new XSSFWorkbook(); 17 | XSSFSheet sheet = workbook.createSheet("Calculate Simple Interest"); 18 | 19 | Row header = sheet.createRow(0); 20 | header.createCell(0).setCellValue("Pricipal"); 21 | header.createCell(1).setCellValue("RoI"); 22 | header.createCell(2).setCellValue("T"); 23 | header.createCell(3).setCellValue("Interest (P r t)"); 24 | 25 | Row dataRow = sheet.createRow(1); 26 | dataRow.createCell(0).setCellValue(14500); 27 | dataRow.createCell(1).setCellValue(9.25); 28 | dataRow.createCell(2).setCellValue(3); 29 | dataRow.createCell(3).setCellFormula("A2*B2*C2"); 30 | 31 | try { 32 | FileOutputStream out = new FileOutputStream(new File("Demoformula.xlsx")); 33 | workbook.write(out); 34 | out.close(); 35 | System.out.println("Excel with foumula cells written successfully"); 36 | 37 | } catch (FileNotFoundException e) { 38 | e.printStackTrace(); 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/excelTutorial/WriteToExcel.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.excelTutorial; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.util.Map; 6 | import java.util.Set; 7 | import java.util.TreeMap; 8 | 9 | import org.apache.poi.ss.usermodel.Cell; 10 | import org.apache.poi.ss.usermodel.Row; 11 | import org.apache.poi.xssf.usermodel.XSSFSheet; 12 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 13 | 14 | /** 15 | * @author Bhanu Pratap 16 | * https://www.youtube.com/user/MrBhanupratap29/playlists 17 | */ 18 | public class WriteToExcel { 19 | public static void main(String[] args) 20 | { 21 | //Blank workbook 22 | XSSFWorkbook workbook = new XSSFWorkbook(); 23 | 24 | //Create a blank sheet 25 | XSSFSheet sheet = workbook.createSheet("Test Data"); 26 | 27 | //This data needs to be written (Object[]) 28 | Map data = new TreeMap(); 29 | data.put("1", new Object[] {"ID", "NAME", "LASTNAME"}); 30 | data.put("2", new Object[] {1, "Bhanu", "Pratap"}); 31 | data.put("3", new Object[] {2, "Bhanu1", "Pratap1"}); 32 | data.put("4", new Object[] {3, "Bhanu2", "Pratap2"}); 33 | data.put("5", new Object[] {4, "Bhanu3", "Pratap3"}); 34 | 35 | //Iterate over data and write to sheet 36 | Set keyset = data.keySet(); 37 | int rownum = 0; 38 | for (String key : keyset) 39 | { 40 | Row row = sheet.createRow(rownum++); 41 | Object[] objArr = data.get(key); 42 | int cellnum = 0; 43 | for (Object obj : objArr) 44 | { 45 | Cell cell = row.createCell(cellnum++); 46 | if(obj instanceof String) 47 | cell.setCellValue((String)obj); 48 | else if(obj instanceof Integer) 49 | cell.setCellValue((Integer)obj); 50 | } 51 | } 52 | try 53 | { 54 | //Write the workbook in file system 55 | FileOutputStream out = new FileOutputStream(new File("demo.xlsx")); 56 | workbook.write(out); 57 | out.close(); 58 | System.out.println("demo.xlsx written successfully on disk."); 59 | } 60 | catch (Exception e) 61 | { 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/Alert/AlertHelper.java: -------------------------------------------------------------------------------- 1 | 2 | package com.hybridFramework.helper.Alert; 3 | 4 | import org.apache.log4j.Logger; 5 | import org.openqa.selenium.Alert; 6 | import org.openqa.selenium.NoAlertPresentException; 7 | import org.openqa.selenium.WebDriver; 8 | 9 | import com.hybridFramework.helper.Logger.LoggerHelper; 10 | 11 | /** 12 | * @author Bhanu Pratap 13 | * https://www.youtube.com/user/MrBhanupratap29/playlists 14 | */ 15 | public class AlertHelper{ 16 | 17 | private WebDriver driver; 18 | private Logger oLog = LoggerHelper.getLogger(AlertHelper.class); 19 | 20 | public AlertHelper(WebDriver driver) { 21 | this.driver = driver; 22 | oLog.debug("AlertHelper : " + this.driver.hashCode()); 23 | } 24 | 25 | public Alert getAlert() { 26 | oLog.debug(""); 27 | return driver.switchTo().alert(); 28 | } 29 | 30 | public void AcceptAlert() { 31 | oLog.info(""); 32 | getAlert().accept(); 33 | } 34 | 35 | public void DismissAlert() { 36 | oLog.info(""); 37 | getAlert().dismiss(); 38 | } 39 | 40 | public String getAlertText() { 41 | String text = getAlert().getText(); 42 | oLog.info(text); 43 | return text; 44 | } 45 | 46 | public boolean isAlertPresent() { 47 | try { 48 | driver.switchTo().alert(); 49 | oLog.info("true"); 50 | return true; 51 | } catch (NoAlertPresentException e) { 52 | // Ignore 53 | oLog.info("false"); 54 | return false; 55 | } 56 | } 57 | 58 | public void AcceptAlertIfPresent() { 59 | if (!isAlertPresent()) 60 | return; 61 | AcceptAlert(); 62 | oLog.info(""); 63 | } 64 | 65 | public void DismissAlertIfPresent() { 66 | 67 | if (!isAlertPresent()) 68 | return; 69 | DismissAlert(); 70 | oLog.info(""); 71 | } 72 | 73 | public void AcceptPrompt(String text) { 74 | 75 | if (!isAlertPresent()) 76 | return; 77 | 78 | Alert alert = getAlert(); 79 | alert.sendKeys(text); 80 | alert.accept(); 81 | oLog.info(text); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/Browser/BrowserHelper.java: -------------------------------------------------------------------------------- 1 | 2 | package com.hybridFramework.helper.Browser; 3 | 4 | import java.util.LinkedList; 5 | import java.util.Set; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.WebDriver; 10 | 11 | import com.hybridFramework.helper.Logger.LoggerHelper; 12 | import com.hybridFramework.testBase.TestBase; 13 | 14 | /** 15 | * @author Bhanu Pratap 16 | * https://www.youtube.com/user/MrBhanupratap29/playlists 17 | */ 18 | public class BrowserHelper{ 19 | 20 | private WebDriver driver; 21 | private Logger Log = LoggerHelper.getLogger(BrowserHelper.class); 22 | 23 | public BrowserHelper(WebDriver driver) { 24 | this.driver = driver; 25 | Log.debug("BrowserHelper : " + this.driver.hashCode()); 26 | } 27 | 28 | public void goBack() { 29 | driver.navigate().back(); 30 | Log.info(""); 31 | } 32 | 33 | public void goForward() { 34 | driver.navigate().forward(); 35 | Log.info(""); 36 | } 37 | 38 | public void refresh() { 39 | driver.navigate().refresh(); 40 | Log.info(""); 41 | } 42 | 43 | public Set getWindowHandlens() { 44 | Log.info(""); 45 | return driver.getWindowHandles(); 46 | } 47 | 48 | public void SwitchToWindow(int index) { 49 | 50 | LinkedList windowsId = new LinkedList(getWindowHandlens()); 51 | 52 | if (index < 0 || index > windowsId.size()){ 53 | throw new IllegalArgumentException("Invalid Index : " + index); 54 | } 55 | driver.switchTo().window(windowsId.get(index)); 56 | Log.info(index); 57 | } 58 | 59 | public void switchToParentWindow() { 60 | LinkedList windowsId = new LinkedList(getWindowHandlens()); 61 | driver.switchTo().window(windowsId.get(0)); 62 | Log.info(""); 63 | } 64 | 65 | public void switchToParentWithChildClose() { 66 | LinkedList windowsId = new LinkedList(getWindowHandlens()); 67 | 68 | for (int i = 1; i < windowsId.size(); i++) { 69 | Log.info(windowsId.get(i)); 70 | driver.switchTo().window(windowsId.get(i)); 71 | driver.close(); 72 | } 73 | 74 | switchToParentWindow(); 75 | } 76 | 77 | 78 | 79 | public void switchToFrame(String nameOrId) { 80 | driver.switchTo().frame(nameOrId); 81 | Log.info(nameOrId); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/DropDown/DropDownHelper.java: -------------------------------------------------------------------------------- 1 | 2 | package com.hybridFramework.helper.DropDown; 3 | 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.ui.Select; 11 | 12 | import com.hybridFramework.helper.Logger.LoggerHelper; 13 | 14 | /** 15 | * @author Bhanu Pratap 16 | * https://www.youtube.com/user/MrBhanupratap29/playlists 17 | */ 18 | public class DropDownHelper { 19 | 20 | private WebDriver driver; 21 | private Logger Log = LoggerHelper.getLogger(DropDownHelper.class); 22 | 23 | public DropDownHelper(WebDriver driver) { 24 | this.driver = driver; 25 | Log.debug("DropDownHelper : " + this.driver.hashCode()); 26 | } 27 | 28 | 29 | public void SelectUsingVisibleValue(WebElement element,String visibleValue) { 30 | Select select = new Select(element); 31 | select.selectByVisibleText(visibleValue); 32 | Log.info("Locator : " + element + " Value : " + visibleValue); 33 | } 34 | 35 | public String getSelectedValue(WebElement element) { 36 | String value = new Select(element).getFirstSelectedOption().getText(); 37 | Log.info("WebELement : " + element + " Value : "+ value); 38 | return value; 39 | } 40 | 41 | public void SelectUsingIndex(WebElement element,int index) { 42 | Select select = new Select(element); 43 | select.selectByIndex(index); 44 | Log.info("Locator : " + element + " Value : " + index); 45 | } 46 | 47 | public void SelectUsingVisibleText(WebElement element,String text) { 48 | Select select = new Select(element); 49 | select.selectByVisibleText(text); 50 | Log.info("Locator : " + element + " Value : " + text); 51 | } 52 | 53 | 54 | public List getAllDropDownValues(WebElement locator) { 55 | Select select = new Select(locator); 56 | List elementList = select.getOptions(); 57 | List valueList = new LinkedList(); 58 | 59 | for (WebElement element : elementList) { 60 | Log.info(element.getText()); 61 | valueList.add(element.getText()); 62 | } 63 | return valueList; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/Javascript/JavaScriptHelper.java: -------------------------------------------------------------------------------- 1 | 2 | package com.hybridFramework.helper.Javascript; 3 | 4 | import org.apache.log4j.Logger; 5 | import org.openqa.selenium.JavascriptExecutor; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | 9 | import com.hybridFramework.helper.Logger.LoggerHelper; 10 | 11 | /** 12 | * @author Bhanu Pratap 13 | * https://www.youtube.com/user/MrBhanupratap29/playlists 14 | */ 15 | public class JavaScriptHelper { 16 | 17 | private WebDriver driver; 18 | private Logger Log = LoggerHelper.getLogger(JavaScriptHelper.class); 19 | 20 | public JavaScriptHelper(WebDriver driver) { 21 | this.driver = driver; 22 | Log.debug("JavaScriptHelper : " + this.driver.hashCode()); 23 | } 24 | 25 | public Object executeScript(String script) { 26 | JavascriptExecutor exe = (JavascriptExecutor) driver; 27 | Log.info(script); 28 | return exe.executeScript(script); 29 | } 30 | 31 | public Object executeScript(String script, Object... args) { 32 | JavascriptExecutor exe = (JavascriptExecutor) driver; 33 | Log.info(script); 34 | return exe.executeScript(script, args); 35 | } 36 | 37 | public void scrollToElemet(WebElement element) { 38 | executeScript("window.scrollTo(arguments[0],arguments[1])", element.getLocation().x, element.getLocation().y); 39 | Log.info(element); 40 | } 41 | 42 | public void scrollToElemetAndClick(WebElement element) { 43 | scrollToElemet(element); 44 | element.click(); 45 | Log.info(element); 46 | } 47 | 48 | public void scrollIntoView(WebElement element) { 49 | executeScript("arguments[0].scrollIntoView()", element); 50 | Log.info(element); 51 | } 52 | 53 | public void scrollIntoViewAndClick(WebElement element) { 54 | scrollIntoView(element); 55 | element.click(); 56 | Log.info(element); 57 | } 58 | 59 | public void scrollDownVertically() { 60 | executeScript("window.scrollTo(0, document.body.scrollHeight)"); 61 | } 62 | 63 | public void scrollUpVertically() { 64 | executeScript("window.scrollTo(0, -document.body.scrollHeight)"); 65 | } 66 | 67 | public void scrollDownByPixel() { 68 | executeScript("window.scrollBy(0,1500)"); 69 | } 70 | 71 | public void scrollUpByPixel() { 72 | executeScript("window.scrollBy(0,-1500)"); 73 | } 74 | 75 | public void ZoomInBypercentage() { 76 | executeScript("document.body.style.zoom='40%'"); 77 | } 78 | 79 | public void ZoomBy100percentage() { 80 | executeScript("document.body.style.zoom='100%'"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/Logger/LoggerHelper.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.helper.Logger; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.apache.log4j.PropertyConfigurator; 5 | 6 | import com.hybridFramework.utility.ResourceHelper; 7 | 8 | /** 9 | * @author Bhanu Pratap 10 | * https://www.youtube.com/user/MrBhanupratap29/playlists 11 | */ 12 | @SuppressWarnings("rawtypes") 13 | public class LoggerHelper { 14 | 15 | private static boolean root = false; 16 | 17 | public static Logger getLogger(Class clas){ 18 | if (root) { 19 | return Logger.getLogger(clas); 20 | } 21 | //String log4jLOcation = System.getProperty("user.dir")+"/src/main/resources/log4j.properties"; 22 | PropertyConfigurator.configure(ResourceHelper.getResourcePath("/src/main/resources/log4j.properties")); 23 | root = true; 24 | return Logger.getLogger(clas); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/Wait/WaitHelper.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.helper.Wait; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.apache.log4j.Logger; 6 | import org.openqa.selenium.ElementNotVisibleException; 7 | import org.openqa.selenium.NoSuchElementException; 8 | import org.openqa.selenium.NoSuchFrameException; 9 | import org.openqa.selenium.StaleElementReferenceException; 10 | import org.openqa.selenium.WebDriver; 11 | import org.openqa.selenium.WebElement; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | 15 | import com.hybridFramework.helper.Logger.LoggerHelper; 16 | 17 | /** 18 | * @author Bhanu Pratap 19 | * https://www.youtube.com/user/MrBhanupratap29/playlists 20 | */ 21 | public class WaitHelper { 22 | 23 | private WebDriver driver; 24 | private Logger Log = LoggerHelper.getLogger(WaitHelper.class); 25 | 26 | 27 | public WaitHelper(WebDriver driver) { 28 | this.driver = driver; 29 | Log.debug("WaitHelper : " + this.driver.hashCode()); 30 | } 31 | 32 | public void setImplicitWait(long timeout, TimeUnit unit) { 33 | Log.info(timeout); 34 | driver.manage().timeouts().implicitlyWait(timeout, unit == null ? TimeUnit.SECONDS : unit); 35 | } 36 | 37 | public void setPageLoadTimeout(long timeout, TimeUnit unit) { 38 | Log.info(timeout); 39 | driver.manage().timeouts().pageLoadTimeout(timeout, unit == null ? TimeUnit.SECONDS : unit); 40 | } 41 | 42 | private WebDriverWait getWait(int timeOutInSeconds, int pollingEveryInMiliSec) { 43 | Log.debug(""); 44 | WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); 45 | wait.pollingEvery(pollingEveryInMiliSec, TimeUnit.MILLISECONDS); 46 | wait.ignoring(NoSuchElementException.class); 47 | wait.ignoring(ElementNotVisibleException.class); 48 | wait.ignoring(StaleElementReferenceException.class); 49 | wait.ignoring(NoSuchFrameException.class); 50 | return wait; 51 | } 52 | 53 | public void waitForElementVisible(WebElement locator, int timeOutInSeconds, int pollingEveryInMiliSec) { 54 | Log.info(locator); 55 | WebDriverWait wait = getWait(timeOutInSeconds, pollingEveryInMiliSec); 56 | wait.until(ExpectedConditions.visibilityOf(locator)); 57 | } 58 | 59 | public void waitForElement(WebDriver driver, WebElement element, long timeout) { 60 | WebDriverWait wait = new WebDriverWait(driver, timeout); 61 | wait.until(ExpectedConditions.visibilityOf(element)); 62 | Log.info("element found..."+element.getText()); 63 | } 64 | 65 | public WebElement waitForElement(WebDriver driver,long time,WebElement element){ 66 | WebDriverWait wait = new WebDriverWait(driver, time); 67 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/assertionHelper/VerificationHelper.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.helper.assertionHelper; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebElement; 6 | 7 | import com.hybridFramework.helper.Logger.LoggerHelper; 8 | 9 | /** 10 | * @author Bhanu Pratap 11 | * https://www.youtube.com/user/MrBhanupratap29/playlists 12 | */ 13 | public class VerificationHelper{ 14 | 15 | private static final Logger log = LoggerHelper.getLogger(VerificationHelper.class); 16 | 17 | public static synchronized boolean verifyElementPresent( WebElement element) { 18 | boolean isDispalyed = false; 19 | try { 20 | isDispalyed= element.isDisplayed(); 21 | log.info(element.getText()+" is dispalyed"); 22 | } 23 | catch(Exception ex) { 24 | log.error("Element not found " + ex); 25 | } 26 | 27 | return isDispalyed; 28 | } 29 | 30 | public static synchronized boolean verifyElementNotPresent( WebElement element) { 31 | boolean isDispalyed = false; 32 | try { 33 | element.isDisplayed(); 34 | log.info(element.getText()+" is dispalyed"); 35 | } 36 | catch(Exception ex) { 37 | log.error("Element not found " + ex); 38 | isDispalyed = true; 39 | } 40 | 41 | return isDispalyed; 42 | } 43 | 44 | public static synchronized boolean verifyTextEquals( WebElement element,String expectedText) { 45 | boolean flag = false; 46 | try { 47 | String actualText=element.getText(); 48 | if(actualText.equals(expectedText)) { 49 | log.info("actualText is :"+actualText+" expected text is: "+expectedText); 50 | return flag=true; 51 | } 52 | else { 53 | log.error("actualText is :"+actualText+" expected text is: "+expectedText); 54 | return flag; 55 | } 56 | } 57 | catch(Exception ex) { 58 | log.error("actualText is :"+element.getText()+" expected text is: "+expectedText); 59 | log.info("text not matching" + ex); 60 | return flag; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/helper/genericHelper/GenericHelper.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.helper.genericHelper; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.openqa.selenium.WebElement; 5 | import org.testng.Reporter; 6 | 7 | import com.hybridFramework.helper.Logger.LoggerHelper; 8 | 9 | /** 10 | * @author Bhanu Pratap 11 | * https://www.youtube.com/user/MrBhanupratap29/playlists 12 | */ 13 | public class GenericHelper{ 14 | 15 | private static final Logger log = LoggerHelper.getLogger(GenericHelper.class); 16 | 17 | public String readValueFromElement(WebElement element) { 18 | 19 | if (null == element){ 20 | log.info("weblement is null"); 21 | return null; 22 | } 23 | 24 | boolean displayed = false; 25 | try { 26 | displayed = isDisplayed(element); 27 | } catch (Exception e) { 28 | log.error(e); 29 | Reporter.log(e.fillInStackTrace().toString()); 30 | return null; 31 | } 32 | 33 | if (!displayed){ 34 | return null; 35 | } 36 | String text = element.getText(); 37 | log.info("weblement valus is.."+text); 38 | return text; 39 | } 40 | 41 | 42 | public String readValueFromInput(WebElement element) { 43 | if (null == element){ 44 | return null; 45 | } 46 | if (!isDisplayed(element)){ 47 | return null; 48 | } 49 | String value = element.getAttribute("value"); 50 | log.info("weblement valus is.."+value); 51 | return value; 52 | } 53 | 54 | public boolean isDisplayed(WebElement element) { 55 | try { 56 | element.isDisplayed(); 57 | log.info("element is displayed.."+element); 58 | return true; 59 | } catch (Exception e) { 60 | log.info(e); 61 | Reporter.log(e.fillInStackTrace().toString()); 62 | return false; 63 | } 64 | } 65 | 66 | protected boolean isNotDisplayed(WebElement element) { 67 | try { 68 | element.isDisplayed(); 69 | log.info("element is displayed.."+element); 70 | return false; 71 | } catch (Exception e) { 72 | log.error(e); 73 | Reporter.log(e.fillInStackTrace().toString()); 74 | return true; 75 | } 76 | } 77 | 78 | protected String getDisplayText(WebElement element) { 79 | if (null == element){ 80 | return null; 81 | } 82 | if (!isDisplayed(element)){ 83 | return null; 84 | } 85 | return element.getText(); 86 | } 87 | 88 | 89 | public static synchronized String getElementText( WebElement element) { 90 | if (null == element) { 91 | log.info("weblement is null"); 92 | return null; 93 | } 94 | String elementText = null; 95 | try { 96 | elementText = element.getText(); 97 | } catch (Exception ex) { 98 | log.info("Element not found " + ex); 99 | Reporter.log(ex.fillInStackTrace().toString()); 100 | } 101 | return elementText; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/properties/homepage.properties: -------------------------------------------------------------------------------- 1 | username = xpath://*[@id='userName'] 2 | password=id:userName 3 | submitbutton=classname:userName -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/testBase/Config.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.testBase; 2 | 3 | import java.util.Properties; 4 | 5 | public class Config extends TestBase{ 6 | 7 | private Properties OR; 8 | 9 | public Config(Properties OR){ 10 | this.OR = OR; 11 | } 12 | public String getUserName() { 13 | return OR.getProperty("Username"); 14 | } 15 | 16 | public String getPassword() { 17 | return OR.getProperty("Password"); 18 | } 19 | 20 | public String getWebsite() { 21 | return OR.getProperty("Website"); 22 | } 23 | 24 | public int getPageLoadTimeOut() { 25 | return Integer.parseInt(OR.getProperty("PageLoadTimeOut")); 26 | } 27 | 28 | public int getImplicitWait() { 29 | return Integer.parseInt(OR.getProperty("ImplcitWait")); 30 | } 31 | 32 | public int getExplicitWait() { 33 | return Integer.parseInt(OR.getProperty("ExplicitWait")); 34 | } 35 | 36 | public String getDbType() { 37 | return OR.getProperty("DataBase.Type"); 38 | } 39 | 40 | public String getDbConnStr() { 41 | return OR.getProperty("DtaBase.ConnectionStr"); 42 | } 43 | public String getBrowser() { 44 | return OR.getProperty("Browser"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/testBase/TestBase.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.testBase; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.lang.reflect.Method; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Calendar; 11 | import java.util.GregorianCalendar; 12 | import java.util.List; 13 | import java.util.NoSuchElementException; 14 | import java.util.Properties; 15 | import java.util.concurrent.TimeUnit; 16 | import org.apache.log4j.Logger; 17 | import org.apache.log4j.PropertyConfigurator; 18 | import org.apache.poi.openxml4j.opc.internal.FileHelper; 19 | import org.openqa.selenium.By; 20 | import org.openqa.selenium.OutputType; 21 | import org.openqa.selenium.TakesScreenshot; 22 | import org.openqa.selenium.WebDriver; 23 | import org.openqa.selenium.WebElement; 24 | import org.openqa.selenium.chrome.ChromeDriver; 25 | import org.openqa.selenium.firefox.FirefoxDriver; 26 | import org.openqa.selenium.support.ui.ExpectedConditions; 27 | import org.openqa.selenium.support.ui.WebDriverWait; 28 | import org.testng.ITestResult; 29 | import org.testng.annotations.AfterClass; 30 | import org.testng.annotations.AfterMethod; 31 | import org.testng.annotations.BeforeMethod; 32 | import org.testng.annotations.BeforeTest; 33 | 34 | import com.hybridFramework.excelReader.Excel_reader; 35 | import com.hybridFramework.helper.Wait.WaitHelper; 36 | import com.relevantcodes.extentreports.ExtentReports; 37 | import com.relevantcodes.extentreports.ExtentTest; 38 | import com.relevantcodes.extentreports.LogStatus; 39 | 40 | 41 | public class TestBase { 42 | 43 | public static final Logger logger = Logger.getLogger(TestBase.class.getName()); 44 | public WebDriver driver; 45 | public static Properties OR; 46 | public File f1; 47 | public FileInputStream file; 48 | 49 | public static ExtentReports extent; 50 | public static ExtentTest test; 51 | public Excel_reader excelreader; 52 | public ITestResult result; 53 | 54 | static { 55 | Calendar calendar = Calendar.getInstance(); 56 | SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss"); 57 | extent = new ExtentReports(System.getProperty("user.dir") + "/src/main/java/com/hybridFramework/report/test" + formater.format(calendar.getTime()) + ".html", false); 58 | } 59 | 60 | @BeforeTest 61 | public void launchBrowser(){ 62 | try { 63 | loadPropertiesFile(); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | Config config = new Config(OR); 68 | getBrowser(config.getBrowser()); 69 | WaitHelper waitHelper = new WaitHelper(driver); 70 | waitHelper.setImplicitWait(config.getImplicitWait(), TimeUnit.SECONDS); 71 | waitHelper.setPageLoadTimeout(config.getPageLoadTimeOut(), TimeUnit.SECONDS); 72 | } 73 | 74 | //3.0.1 75 | //FF:-47.0.2 76 | //0.15 77 | public void getBrowser(String browser){ 78 | if(System.getProperty("os.name").contains("Window")){ 79 | if(browser.equalsIgnoreCase("firefox")){ 80 | //https://github.com/mozilla/geckodriver/releases 81 | System.out.println(System.getProperty("user.dir")); 82 | System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/drivers/geckodriver.exe"); 83 | driver = new FirefoxDriver(); 84 | } 85 | else if(browser.equalsIgnoreCase("chrome")){ 86 | //https://chromedriver.storage.googleapis.com/index.html 87 | System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/drivers/chromedriver.exe"); 88 | driver = new ChromeDriver(); 89 | } 90 | } 91 | else if(System.getProperty("os.name").contains("Mac")){ 92 | System.out.println(System.getProperty("os.name")); 93 | if(browser.equalsIgnoreCase("firefox")){ 94 | System.out.println(System.getProperty("user.dir")); 95 | System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/drivers/geckodriver"); 96 | driver = new FirefoxDriver(); 97 | } 98 | else if(browser.equalsIgnoreCase("chrome")){ 99 | System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/drivers/chromedriver"); 100 | driver = new ChromeDriver(); 101 | } 102 | } 103 | } 104 | 105 | public void loadPropertiesFile() throws IOException{ 106 | 107 | String log4jConfPath = "log4j.properties"; 108 | PropertyConfigurator.configure(log4jConfPath); 109 | OR = new Properties(); 110 | f1 = new File(System.getProperty("user.dir")+"/src/main/java/com/hybridFramework/config/config.properties"); 111 | file = new FileInputStream(f1); 112 | OR.load(file); 113 | logger.info("loading config.properties"); 114 | 115 | f1 = new File(System.getProperty("user.dir")+"/src/main/java/com/hybridFramework/config/or.properties"); 116 | file = new FileInputStream(f1); 117 | OR.load(file); 118 | logger.info("loading or.properties"); 119 | 120 | f1 = new File(System.getProperty("user.dir")+"/src/main/java/com/hybridFramework/properties/homepage.properties"); 121 | file = new FileInputStream(f1); 122 | OR.load(file); 123 | logger.info("loading homepage.properties"); 124 | } 125 | 126 | public String getScreenShot(String imageName) throws IOException{ 127 | 128 | if(imageName.equals("")){ 129 | imageName = "blank"; 130 | } 131 | File image = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 132 | String imagelocation = System.getProperty("user.dir")+"/src/main/java/com/hybridFramework/screenshot/"; 133 | Calendar calendar = Calendar.getInstance(); 134 | SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss"); 135 | String actualImageName = imagelocation+imageName+"_"+formater.format(calendar.getTime())+".png"; 136 | File destFile = new File(actualImageName); 137 | FileHelper.copyFile(image, destFile); 138 | return actualImageName; 139 | } 140 | 141 | public WebElement waitForElement(WebDriver driver,long time,WebElement element){ 142 | WebDriverWait wait = new WebDriverWait(driver, time); 143 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 144 | } 145 | 146 | public WebElement waitForElementWithPollingInterval(WebDriver driver,long time,WebElement element){ 147 | WebDriverWait wait = new WebDriverWait(driver, time); 148 | wait.pollingEvery(5, TimeUnit.SECONDS); 149 | wait.ignoring(NoSuchElementException.class); 150 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 151 | } 152 | 153 | public void impliciteWait(long time){ 154 | driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS); 155 | } 156 | 157 | public void getresult(ITestResult result) throws IOException { 158 | if (result.getStatus() == ITestResult.SUCCESS) { 159 | 160 | test.log(LogStatus.PASS, result.getName() + " test is pass"); 161 | } else if (result.getStatus() == ITestResult.SKIP) { 162 | test.log(LogStatus.SKIP, result.getName() + " test is skipped and skip reason is:-" + result.getThrowable()); 163 | } else if (result.getStatus() == ITestResult.FAILURE) { 164 | test.log(LogStatus.FAIL, result.getName() + " test is failed" + result.getThrowable()); 165 | String screen = getScreenShot(""); 166 | test.log(LogStatus.FAIL, test.addScreenCapture(screen)); 167 | } else if (result.getStatus() == ITestResult.STARTED) { 168 | test.log(LogStatus.INFO, result.getName() + " test is started"); 169 | } 170 | } 171 | 172 | @AfterMethod() 173 | public void afterMethod(ITestResult result) throws IOException { 174 | getresult(result); 175 | } 176 | 177 | @BeforeMethod() 178 | public void beforeMethod(Method result) { 179 | test = extent.startTest(result.getName()); 180 | test.log(LogStatus.INFO, result.getName() + " test Started"); 181 | } 182 | 183 | @AfterClass(alwaysRun = true) 184 | public void endTest() { 185 | //driver.quit(); 186 | extent.endTest(test); 187 | extent.flush(); 188 | } 189 | 190 | public WebElement getLocator(String locator) throws Exception { 191 | //System.out.println(locator); 192 | String[] split = locator.split(":"); 193 | String locatorType = split[0]; 194 | String locatorValue = split[1]; 195 | //System.out.println("locatorType:-"+locatorType); 196 | //System.out.println("locatorValue:-"+locatorValue); 197 | if (locatorType.toLowerCase().equals("id")) 198 | return driver.findElement(By.id(locatorValue)); 199 | else if (locatorType.toLowerCase().equals("name")) 200 | return driver.findElement(By.name(locatorValue)); 201 | else if ((locatorType.toLowerCase().equals("classname"))|| (locatorType.toLowerCase().equals("class"))) 202 | return driver.findElement(By.className(locatorValue)); 203 | else if ((locatorType.toLowerCase().equals("tagname")) 204 | || (locatorType.toLowerCase().equals("tag"))) 205 | return driver.findElement(By.className(locatorValue)); 206 | else if ((locatorType.toLowerCase().equals("linktext")) 207 | || (locatorType.toLowerCase().equals("link"))) 208 | return driver.findElement(By.linkText(locatorValue)); 209 | else if (locatorType.toLowerCase().equals("partiallinktext")) 210 | return driver.findElement(By.partialLinkText(locatorValue)); 211 | else if ((locatorType.toLowerCase().equals("cssselector")) 212 | || (locatorType.toLowerCase().equals("css"))) 213 | return driver.findElement(By.cssSelector(locatorValue)); 214 | else if (locatorType.toLowerCase().equals("xpath")) 215 | return driver.findElement(By.xpath(locatorValue)); 216 | else 217 | throw new Exception("Unknown locator type '" + locatorType + "'"); 218 | } 219 | 220 | public List getLocators(String locator) throws Exception { 221 | String[] split = locator.split(":"); 222 | String locatorType = split[0]; 223 | String locatorValue = split[1]; 224 | System.out.println("locatorType:-"+locatorType); 225 | System.out.println("locatorValue:-"+locatorValue); 226 | 227 | if (locatorType.toLowerCase().equals("id")) 228 | return driver.findElements(By.id(locatorValue)); 229 | else if (locatorType.toLowerCase().equals("name")) 230 | return driver.findElements(By.name(locatorValue)); 231 | else if ((locatorType.toLowerCase().equals("classname")) 232 | || (locatorType.toLowerCase().equals("class"))) 233 | return driver.findElements(By.className(locatorValue)); 234 | else if ((locatorType.toLowerCase().equals("tagname")) 235 | || (locatorType.toLowerCase().equals("tag"))) 236 | return driver.findElements(By.className(locatorValue)); 237 | else if ((locatorType.toLowerCase().equals("linktext")) 238 | || (locatorType.toLowerCase().equals("link"))) 239 | return driver.findElements(By.linkText(locatorValue)); 240 | else if (locatorType.toLowerCase().equals("partiallinktext")) 241 | return driver.findElements(By.partialLinkText(locatorValue)); 242 | else if ((locatorType.toLowerCase().equals("cssselector")) 243 | || (locatorType.toLowerCase().equals("css"))) 244 | return driver.findElements(By.cssSelector(locatorValue)); 245 | else if (locatorType.toLowerCase().equals("xpath")) 246 | return driver.findElements(By.xpath(locatorValue)); 247 | else 248 | throw new Exception("Unknown locator type '" + locatorType + "'"); 249 | } 250 | 251 | public WebElement getWebElement(String locator) throws Exception{ 252 | return getLocator(OR.getProperty(locator)); 253 | } 254 | 255 | public List getWebElements(String locator) throws Exception{ 256 | return getLocators(OR.getProperty(locator)); 257 | } 258 | 259 | public String[][] getData(String excelName, String sheetName){ 260 | System.out.println(System.getProperty("user.dir")); 261 | String excellocation = System.getProperty("user.dir")+"/src/main/java/com/hybridFramework/data/"+excelName; 262 | System.out.println(excellocation); 263 | excelreader = new Excel_reader(); 264 | return excelreader.getExcelData(excellocation, sheetName); 265 | } 266 | 267 | public static void updateResultupdateResult(int indexSI, String screenShotLocation,String response) throws IOException { 268 | String startDateTime = new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime()); 269 | System.out.println("startDateTime---"+startDateTime); 270 | String userDirector = System.getProperty("user.dir"); 271 | 272 | String resultFile = userDirector + "/src/main/java/com/hybridFramework/screenshot/TestReport.html"; 273 | 274 | File file = new File(resultFile); 275 | System.out.println(file.exists()); 276 | 277 | if (!file.exists()) { 278 | FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); 279 | BufferedWriter bw = new BufferedWriter(fw); 280 | bw.write("" + "\n"); 281 | bw.write("" + "Test execution report" + "" + "\n"); 282 | bw.write("" + "\n"); 283 | bw.write(""); 284 | bw.write("" + "\n"); 285 | bw.write("

" + "Test execution report" + "

" + "\n"); 286 | bw.flush(); 287 | bw.close(); 288 | } 289 | BufferedWriter bw1 = new BufferedWriter(new FileWriter(file, true)); 290 | if (indexSI == 1) { 291 | 292 | bw1.write(""); 293 | bw1.write(""); 294 | bw1.write("
"); 295 | bw1.write(""); 296 | bw1.write(""); 297 | bw1.write(""); 298 | bw1.write(""); 299 | bw1.write(""); 300 | bw1.write(""); 301 | bw1.write(""); 302 | bw1.write(""); 303 | bw1.write(""); 304 | } 305 | 306 | bw1.write("" + "\n"); 307 | bw1.write("" + "\n"); 308 | bw1.write("" + "\n"); 309 | bw1.write("" + "\n"); 310 | bw1.write("" + "\n"); 311 | bw1.write("" + "\n"); 312 | bw1.write(""); 313 | bw1.flush(); 314 | bw1.close(); 315 | } 316 | 317 | public static void main(String[] args) throws Exception { 318 | TestBase test = new TestBase(); 319 | test.loadPropertiesFile(); 320 | test.getBrowser("firefox"); 321 | System.out.println(test.OR.getProperty("username")); 322 | 323 | 324 | //test.getWebElement("submitbutton"); 325 | //test.getWebElements("submitbutton"); 326 | 327 | //test.getLocator(test.OR.getProperty("username")); 328 | 329 | } 330 | 331 | } 332 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/utility/DateTimeHelper.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.utility; 2 | 3 | import java.text.DateFormat; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | 7 | /** 8 | * 9 | * @author bsingh5 10 | * 11 | */ 12 | public class DateTimeHelper { 13 | 14 | public static String getCurrentDateTime() { 15 | 16 | DateFormat dateFormat = new SimpleDateFormat("_yyyy-MM-dd_HH-mm-ss"); 17 | Calendar cal = Calendar.getInstance(); 18 | String time = "" + dateFormat.format(cal.getTime()); 19 | return time; 20 | } 21 | 22 | public static String getCurrentDate() { 23 | return getCurrentDateTime().substring(0, 11); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hybridFramework/utility/ResourceHelper.java: -------------------------------------------------------------------------------- 1 | 2 | package com.hybridFramework.utility; 3 | 4 | 5 | import java.io.FileInputStream; 6 | import java.io.FileNotFoundException; 7 | import java.io.InputStream; 8 | 9 | /** 10 | * 11 | * @author bsingh5 12 | * 13 | */ 14 | public class ResourceHelper { 15 | 16 | public static String getResourcePath(String resource) { 17 | String path = getBaseResourcePath() + resource; 18 | return path; 19 | } 20 | 21 | public static String getBaseResourcePath() { 22 | String path = System.getProperty("user.dir"); 23 | System.out.println(path); 24 | return path; 25 | } 26 | 27 | public static InputStream getResourcePathInputStream(String path) throws FileNotFoundException{ 28 | return new FileInputStream(ResourceHelper.getResourcePath(path)); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Define the root logger with appender file 2 | log4j.rootLogger = INFO, FILE,stdout 3 | 4 | # Define the file appender 5 | log4j.appender.FILE=org.apache.log4j.FileAppender 6 | log4j.appender.FILE.File=automation.out 7 | log4j.appender.FILE.Append=false 8 | log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 10 | log4j.appender.file.MaxFileSize=4MB 11 | log4j.appender.file.MaxBackupIndex=9 12 | 13 | # Define the layout for file appender 14 | #log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 15 | #log4j.appender.FILE.layout.conversionPattern=%m%n 16 | 17 | # Direct log messages to stdout 18 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 19 | log4j.appender.stdout.Target=System.out 20 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/homepage/A.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.homepage; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.firefox.FirefoxDriver; 7 | 8 | public class A { 9 | 10 | static WebDriver driver; 11 | 12 | public static void getDriver() 13 | 14 | { 15 | System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "/drivers/geckodriver"); 16 | driver = new FirefoxDriver(); 17 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 18 | driver.get("https://www.facebook.com"); 19 | } 20 | 21 | public static void closeBrowser() { 22 | 23 | driver.close(); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/homepage/DBTest.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.homepage; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebDriver; 8 | import org.testng.annotations.Test; 9 | 10 | import com.hybridFramework.database.DataBase; 11 | 12 | 13 | 14 | public class DBTest{ 15 | WebDriver driver; 16 | 17 | @Test 18 | public void selectDBdata() throws ClassNotFoundException, SQLException{ 19 | String textData = driver.findElement(By.xpath("")).getText(); 20 | String query = "SELECT * FROM registration"; 21 | String query1 = "SELECT name FROM registration where id=1"; 22 | DataBase dataBase = new DataBase(); 23 | ResultSet data = dataBase.getData(query); 24 | System.out.println(data); 25 | while(data.next()){ 26 | System.out.println(data.getString(1)+" "+data.getString(2)+" "+data.getString(3)); 27 | } 28 | /* 29 | if(textData.contains(data.getString(1))){ 30 | 31 | } 32 | */ 33 | } 34 | 35 | @Test 36 | public void insertDBdata() throws ClassNotFoundException, SQLException{ 37 | String query = "insert into registration values('2','bhnau12','testing123')"; 38 | DataBase dataBase = new DataBase(); 39 | dataBase.insertData(query); 40 | } 41 | 42 | @Test 43 | public void updateDBdata() throws ClassNotFoundException, SQLException{ 44 | String query = "update registration set name='56777' where profession='testing123'"; 45 | DataBase dataBase = new DataBase(); 46 | dataBase.updateData(query); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/homepage/TestDaataDrivenScript1.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.homepage; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | import com.hybridFramework.testBase.TestBase; 7 | 8 | public class TestDaataDrivenScript1 extends TestBase{ 9 | 10 | 11 | @DataProvider(name="testData") 12 | public Object[][] dataSource(){ 13 | return getData("TestData.xlsx", "Registration"); 14 | } 15 | 16 | @Test(dataProvider="testData") 17 | public void testLogin(String variable1, String variable2, String variable3,String variable4,String variable5,String variable6){ 18 | System.out.println("variable1:-"+variable1); 19 | System.out.println("variable2:-"+variable2); 20 | System.out.println("variable3:-"+variable3); 21 | System.out.println("variable4:-"+variable4); 22 | System.out.println("variable5:-"+variable5); 23 | System.out.println("variable5:-"+variable6); 24 | 25 | //driver.findElement(By.xpath("")).sendKeys(userName); 26 | //driver.findElement(By.xpath("")).sendKeys(password); 27 | //driver.findElement(By.xpath("")).sendKeys(runmode); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/homepage/TestDataDriverScript.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.homepage; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | import com.hybridFramework.testBase.TestBase; 7 | 8 | public class TestDataDriverScript extends TestBase{ 9 | 10 | @DataProvider(name="testData") 11 | public Object[][] dataSource(){ 12 | return getData("TestData.xlsx", "LoginTestData"); 13 | } 14 | 15 | @Test(dataProvider="testData") 16 | public void testLogin(String userName, String password, String runmode){ 17 | System.out.println("userName:-"+userName); 18 | System.out.println("password:-"+password); 19 | System.out.println("runmode:-"+runmode); 20 | //driver.findElement(By.xpath("")).sendKeys(userName); 21 | //driver.findElement(By.xpath("")).sendKeys(password); 22 | //driver.findElement(By.xpath("")).sendKeys(runmode); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/loginPage/LoginTest.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.loginPage; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.testng.Assert; 5 | import org.testng.annotations.Test; 6 | 7 | import com.hybridFramework.PageObject.LoginPage; 8 | import com.hybridFramework.helper.Logger.LoggerHelper; 9 | import com.hybridFramework.testBase.Config; 10 | import com.hybridFramework.testBase.TestBase; 11 | 12 | /** 13 | * 14 | * @author Bhanu Pratap 15 | * https://www.youtube.com/user/MrBhanupratap29/playlists 16 | */ 17 | public class LoginTest extends TestBase{ 18 | private final Logger log = LoggerHelper.getLogger(LoginTest.class); 19 | 20 | @Test 21 | public void testLoginToApplication(){ 22 | log.info(LoginTest.class.getName()+" started"); 23 | Config config = new Config(OR); 24 | driver.get(config.getWebsite()); 25 | 26 | LoginPage loginPage = new LoginPage(driver); 27 | 28 | loginPage.loginToApplication(config.getUserName(), config.getPassword()); 29 | boolean status = loginPage.verifySuccessLoginMsg(); 30 | if(status){ 31 | log.info("login is sucessful"); 32 | } 33 | else{ 34 | Assert.assertTrue(false, "login is not sucessful"); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/productDetailsPage/VerifyColorFilter.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.productDetailsPage; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.hybridFramework.helper.Logger.LoggerHelper; 6 | import com.hybridFramework.testBase.Config; 7 | import com.hybridFramework.testBase.TestBase; 8 | 9 | /** 10 | * @author Bhanu Pratap 11 | * https://www.youtube.com/user/MrBhanupratap29/playlists 12 | */ 13 | public class VerifyColorFilter extends TestBase{ 14 | private final Logger log = LoggerHelper.getLogger(VerifyColorFilter.class); 15 | 16 | public void testVerifyColorFilter(){ 17 | log.info(VerifyColorFilter.class.getName()+" started"); 18 | 19 | Config config = new Config(OR); 20 | driver.get(config.getWebsite()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/productDetailsPage/VerifyInformationLinkText.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.productDetailsPage; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.hybridFramework.helper.Logger.LoggerHelper; 6 | import com.hybridFramework.testBase.Config; 7 | import com.hybridFramework.testBase.TestBase; 8 | 9 | /** 10 | * @author Bhanu Pratap 11 | * https://www.youtube.com/user/MrBhanupratap29/playlists 12 | */ 13 | public class VerifyInformationLinkText extends TestBase{ 14 | private final Logger log = LoggerHelper.getLogger(VerifyInformationLinkText.class); 15 | 16 | public void testVerifyInformationLinkText(){ 17 | log.info(VerifyInformationLinkText.class.getName()+" started"); 18 | 19 | Config config = new Config(OR); 20 | driver.get(config.getWebsite()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/productDetailsPage/VerifyLowestFirstPriceFilter.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.productDetailsPage; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.openqa.selenium.WebElement; 9 | import org.testng.Assert; 10 | import org.testng.annotations.Test; 11 | 12 | import com.hybridFramework.PageObject.HomePage; 13 | import com.hybridFramework.PageObject.ProductCategoryPage; 14 | import com.hybridFramework.helper.Logger.LoggerHelper; 15 | import com.hybridFramework.testBase.Config; 16 | import com.hybridFramework.testBase.TestBase; 17 | 18 | /** 19 | * @author Bhanu Pratap 20 | * https://www.youtube.com/user/MrBhanupratap29/playlists 21 | */ 22 | public class VerifyLowestFirstPriceFilter extends TestBase{ 23 | private final Logger log = LoggerHelper.getLogger(VerifyLowestFirstPriceFilter.class); 24 | 25 | @Test 26 | public void verifyLowestFirstPriceListInProduct_deatilsPage() throws InterruptedException { 27 | log.info(VerifyLowestFirstPriceFilter.class.getName()+" started"); 28 | 29 | Config config = new Config(OR); 30 | driver.get(config.getWebsite()); 31 | HomePage homepage = new HomePage(driver); 32 | 33 | ProductCategoryPage pcategoryPage = homepage.clickOnMenu(homepage.womenMenu); 34 | // select price filter 35 | pcategoryPage.selectSortByFilter("Price: Lowest first"); 36 | 37 | // wait for some time to make sure price is sorted. 38 | Thread.sleep(8000); 39 | 40 | List price = pcategoryPage.getAllProductsPrice(); 41 | 42 | ArrayList array = new ArrayList(); 43 | 44 | Iterator itr = price.iterator(); 45 | 46 | //price comes in "$16.40" format 47 | // remove $ from beginning and change to int for sorting order verification 48 | // Store it in array list 49 | while (itr.hasNext()) { 50 | String p = itr.next().getText(); 51 | //System.out.println(p); 52 | if (p.contains("$")) { 53 | String actualData = p.substring(1); 54 | System.out.println(actualData); 55 | double p1 = Double.parseDouble(actualData); 56 | int productPrice = (int) (p1); 57 | array.add(productPrice); 58 | } 59 | } 60 | System.out.println(array); 61 | //[16, 16, 26, 27, 28, 30, 50] 62 | for (int i = 0; i < array.size() - 1; i++) { 63 | // this condition will check all next price should be smaller than previous one. 64 | // next price can be grater and equal 65 | if (array.get(i) <= array.get(i + 1)) { 66 | System.out.println("obj.get(i):-" + array.get(i)); 67 | System.out.println("obj.get(i+1):-" + array.get(i + 1)); 68 | } else { 69 | Assert.assertTrue(false,"price filter is not working"); 70 | } 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/productDetailsPage/VerifyProductCounts.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.productDetailsPage; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.testng.Assert; 5 | import org.testng.annotations.Test; 6 | 7 | import com.hybridFramework.PageObject.HomePage; 8 | import com.hybridFramework.PageObject.LoginPage; 9 | import com.hybridFramework.PageObject.ProductCategoryPage; 10 | import com.hybridFramework.helper.Logger.LoggerHelper; 11 | import com.hybridFramework.testBase.Config; 12 | import com.hybridFramework.testBase.TestBase; 13 | 14 | /** 15 | * @author Bhanu Pratap 16 | * https://www.youtube.com/user/MrBhanupratap29/playlists 17 | */ 18 | public class VerifyProductCounts extends TestBase{ 19 | private final Logger log = LoggerHelper.getLogger(VerifyProductCounts.class); 20 | LoginPage loginPage; 21 | HomePage homePage; 22 | 23 | @Test 24 | public void testVerifyProductCounts(){ 25 | log.info(VerifyProductCounts.class.getName()+" started"); 26 | 27 | Config config = new Config(OR); 28 | driver.get(config.getWebsite()); 29 | 30 | homePage = new HomePage(driver); 31 | ProductCategoryPage pCate = homePage.clickOnMenu(homePage.womenMenu); 32 | pCate.selectColor(pCate.Orange); 33 | int count = pCate.getTotalProducts(); 34 | 35 | if(count==3){ 36 | log.info("product count is matching"); 37 | } 38 | else{ 39 | Assert.assertTrue(false,"product count is not matching"); 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/hybridFramework/registration/Registration.java: -------------------------------------------------------------------------------- 1 | package com.hybridFramework.registration; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.testng.Assert; 5 | import org.testng.annotations.Test; 6 | 7 | import com.hybridFramework.PageObject.LoginPage; 8 | import com.hybridFramework.PageObject.MyAccountPage; 9 | import com.hybridFramework.PageObject.RegistrationPage; 10 | import com.hybridFramework.helper.Logger.LoggerHelper; 11 | import com.hybridFramework.testBase.Config; 12 | import com.hybridFramework.testBase.TestBase; 13 | 14 | /** 15 | * @author Bhanu Pratap 16 | * https://www.youtube.com/user/MrBhanupratap29/playlists 17 | */ 18 | public class Registration extends TestBase{ 19 | 20 | private final Logger log = LoggerHelper.getLogger(Registration.class); 21 | LoginPage loginPage; 22 | RegistrationPage register; 23 | MyAccountPage myAccountPage; 24 | 25 | @Test 26 | public void testLoginToApplication(){ 27 | log.info(Registration.class.getName()+" started"); 28 | 29 | Config config = new Config(OR); 30 | driver.get(config.getWebsite()); 31 | 32 | loginPage = new LoginPage(driver); 33 | loginPage.clickOnSignInLink(); 34 | loginPage.enterRegistrationEmail(); 35 | loginPage.clickOnCreateAnAccount(); 36 | 37 | register = new RegistrationPage(driver); 38 | register.setMrRadioButton(); 39 | register.setFirstName("firstName"); 40 | register.setLastname("lastname"); 41 | register.setPassword("password"); 42 | register.setAddress("address"); 43 | register.setDay("5"); 44 | register.setMonth("June"); 45 | register.setYear("2017"); 46 | register.setYourAddressFirstName("yourAddressFirstName"); 47 | register.setYourAddressLastName("yourAddressLastName"); 48 | register.setYourAddressCompany("yourAddressCompany"); 49 | register.setYourAddressCity("yourAddressCity"); 50 | register.setYourAddressState("Alaska"); 51 | register.setYourAddressPostCode("99501"); 52 | register.setMobilePhone("9999999999"); 53 | register.setAddressAlias("addressAlias"); 54 | register.clickRegistration(); 55 | 56 | myAccountPage = new MyAccountPage(driver); 57 | 58 | if(myAccountPage.verifySuccessRegistrationMsg()){ 59 | log.info("Registration is sucessful"); 60 | } 61 | else{ 62 | Assert.assertTrue(false, "Registration is not sucessful"); 63 | } 64 | } 65 | } 66 | --------------------------------------------------------------------------------
ScriptName :   Resiliency Test Start Time : " + startDateTime + "
S.NoScreen ShotResponse
" + indexSI + "" + "Smiley face" + "" + response + "