├── .gitignore ├── README.md ├── src ├── main │ └── java │ │ ├── enums │ │ ├── Context.java │ │ ├── EnvironmentType.java │ │ └── DriverType.java │ │ ├── testDataTypes │ │ └── Customer.java │ │ ├── pageObjects │ │ ├── HomePage.java │ │ ├── CartPage.java │ │ ├── ConfirmationPage.java │ │ ├── ProductListingPage.java │ │ └── CheckoutPage.java │ │ ├── cucumber │ │ ├── ScenarioContext.java │ │ └── TestContext.java │ │ ├── managers │ │ ├── FileReaderManager.java │ │ ├── PageObjectManager.java │ │ └── WebDriverManager.java │ │ ├── dataProviders │ │ ├── JsonDataReader.java │ │ └── ConfigFileReader.java │ │ └── selenium │ │ └── Wait.java └── test │ ├── java │ ├── stepDefinitions │ │ ├── CartPageSteps.java │ │ ├── HomePageSteps.java │ │ ├── ProductPageSteps.java │ │ ├── ConfirmationPageSteps.java │ │ ├── CheckoutPageSteps.java │ │ └── Hooks.java │ └── runners │ │ └── TestRunner.java │ └── resources │ ├── functionalTests │ └── End2End_Tests.feature │ └── testDataResources │ └── Customer.json ├── .settings ├── org.eclipse.m2e.core.prefs ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── configs ├── Configuration.properties └── extent-config.xml ├── .project ├── .classpath └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CucumberFramework -------------------------------------------------------------------------------- /src/main/java/enums/Context.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | public enum Context { 4 | PRODUCT_NAME; 5 | } -------------------------------------------------------------------------------- /src/main/java/enums/EnvironmentType.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | public enum EnvironmentType { 4 | LOCAL, 5 | REMOTE, 6 | } 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /src/main/java/enums/DriverType.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | public enum DriverType { 4 | FIREFOX, 5 | CHROME, 6 | INTERNETEXPLORER 7 | } 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding//src/test/resources=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /configs/Configuration.properties: -------------------------------------------------------------------------------- 1 | environment=local 2 | browser=chrome 3 | windowMaximize=true 4 | driverPath=C:/ToolsQA/Libs/Drivers/chromedriver.exe 5 | implicitlyWait=20 6 | url=http://www.shop.demoqa.com 7 | testDataResourcePath=src/test/resources/testDataResources/ 8 | reportConfigPath=C:/ToolsQA/CucumberFramework/configs/extent-config.xml -------------------------------------------------------------------------------- /src/main/java/testDataTypes/Customer.java: -------------------------------------------------------------------------------- 1 | package testDataTypes; 2 | 3 | public class Customer { 4 | public String firstName; 5 | public String lastName; 6 | public int age; 7 | public String emailAddress; 8 | public Address address; 9 | public PhoneNumber phoneNumber; 10 | 11 | public class Address { 12 | public String streetAddress; 13 | public String city; 14 | public String postCode; 15 | public String state; 16 | public String country; 17 | public String county; 18 | } 19 | 20 | public class PhoneNumber { 21 | public String home; 22 | public String mob; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CucumberFramework 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/CartPageSteps.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import cucumber.TestContext; 4 | import cucumber.api.java.en.When; 5 | import pageObjects.CartPage; 6 | 7 | public class CartPageSteps { 8 | 9 | TestContext testContext; 10 | CartPage cartPage; 11 | 12 | public CartPageSteps(TestContext context) { 13 | testContext = context; 14 | cartPage = testContext.getPageObjectManager().getCartPage(); 15 | } 16 | 17 | @When("^moves to checkout from mini cart$") 18 | public void moves_to_checkout_from_mini_cart(){ 19 | cartPage.clickOn_Cart(); 20 | cartPage.clickOn_ContinueToCheckout(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/functionalTests/End2End_Tests.feature: -------------------------------------------------------------------------------- 1 | Feature: Automated End2End Tests 2 | Description: The purpose of this feature is to test End 2 End integration. 3 | 4 | Scenario Outline: Customer place an order by purchasing an item from search 5 | Given user is on Home Page 6 | When he search for "dress" 7 | And choose to buy the first item 8 | And moves to checkout from mini cart 9 | And enter "" personal details on checkout page 10 | And select same delivery address 11 | And select payment method as "check" payment 12 | And place the order 13 | Then verify the order details 14 | Examples: 15 | |customer| 16 | |Lakshay| -------------------------------------------------------------------------------- /src/main/java/pageObjects/HomePage.java: -------------------------------------------------------------------------------- 1 | package pageObjects; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.support.PageFactory; 5 | 6 | import managers.FileReaderManager; 7 | 8 | public class HomePage { 9 | WebDriver driver; 10 | 11 | public HomePage(WebDriver driver){ 12 | this.driver = driver; 13 | PageFactory.initElements(driver, this); 14 | } 15 | 16 | public void perform_Search(String search) { 17 | driver.navigate().to(FileReaderManager.getInstance().getConfigReader().getApplicationUrl() + "/?s=" + search + "&post_type=product"); 18 | } 19 | 20 | public void navigateTo_HomePage() { 21 | driver.get(FileReaderManager.getInstance().getConfigReader().getApplicationUrl()); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/main/java/cucumber/ScenarioContext.java: -------------------------------------------------------------------------------- 1 | package cucumber; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import enums.Context; 6 | 7 | public class ScenarioContext { 8 | 9 | private Map scenarioContext; 10 | 11 | public ScenarioContext(){ 12 | scenarioContext = new HashMap<>(); 13 | } 14 | 15 | public void setContext(Context key, Object value) { 16 | scenarioContext.put(key.toString(), value); 17 | } 18 | 19 | public Object getContext(Context key){ 20 | return scenarioContext.get(key.toString()); 21 | } 22 | 23 | public Boolean isContains(Context key){ 24 | return scenarioContext.containsKey(key.toString()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/HomePageSteps.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import cucumber.TestContext; 4 | import cucumber.api.java.en.Given; 5 | import cucumber.api.java.en.When; 6 | import pageObjects.HomePage; 7 | 8 | public class HomePageSteps { 9 | 10 | TestContext testContext; 11 | HomePage homePage; 12 | 13 | public HomePageSteps(TestContext context) { 14 | testContext = context; 15 | homePage = testContext.getPageObjectManager().getHomePage(); 16 | } 17 | 18 | @Given("^user is on Home Page$") 19 | public void user_is_on_Home_Page(){ 20 | homePage.navigateTo_HomePage(); 21 | } 22 | 23 | @When("^he search for \"([^\"]*)\"$") 24 | public void he_search_for(String product) { 25 | homePage.perform_Search(product); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/cucumber/TestContext.java: -------------------------------------------------------------------------------- 1 | package cucumber; 2 | 3 | import managers.PageObjectManager; 4 | import managers.WebDriverManager; 5 | 6 | public class TestContext { 7 | private WebDriverManager webDriverManager; 8 | private PageObjectManager pageObjectManager; 9 | private ScenarioContext scenarioContext; 10 | 11 | public TestContext(){ 12 | webDriverManager = new WebDriverManager(); 13 | pageObjectManager = new PageObjectManager(webDriverManager.getDriver()); 14 | scenarioContext = new ScenarioContext(); 15 | } 16 | 17 | public WebDriverManager getWebDriverManager() { 18 | return webDriverManager; 19 | } 20 | 21 | public PageObjectManager getPageObjectManager() { 22 | return pageObjectManager; 23 | } 24 | 25 | public ScenarioContext getScenarioContext() { 26 | return scenarioContext; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/managers/FileReaderManager.java: -------------------------------------------------------------------------------- 1 | package managers; 2 | 3 | import dataProviders.ConfigFileReader; 4 | import dataProviders.JsonDataReader; 5 | 6 | public class FileReaderManager { 7 | 8 | private static FileReaderManager fileReaderManager = new FileReaderManager(); 9 | private static ConfigFileReader configFileReader; 10 | private static JsonDataReader jsonDataReader; 11 | 12 | private FileReaderManager() { 13 | } 14 | 15 | public static FileReaderManager getInstance( ) { 16 | return fileReaderManager; 17 | } 18 | 19 | public ConfigFileReader getConfigReader() { 20 | return (configFileReader == null) ? configFileReader = new ConfigFileReader() : configFileReader; 21 | } 22 | 23 | public JsonDataReader getJsonReader(){ 24 | return (jsonDataReader == null) ? jsonDataReader = new JsonDataReader() : jsonDataReader; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/ProductPageSteps.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import cucumber.TestContext; 4 | import cucumber.api.java.en.When; 5 | import enums.Context; 6 | import pageObjects.ProductListingPage; 7 | 8 | public class ProductPageSteps { 9 | 10 | TestContext testContext; 11 | ProductListingPage productListingPage; 12 | 13 | public ProductPageSteps(TestContext context) { 14 | testContext = context; 15 | productListingPage = testContext.getPageObjectManager().getProductListingPage(); 16 | } 17 | 18 | @When("^choose to buy the first item$") 19 | public void choose_to_buy_the_first_item() { 20 | String productName = productListingPage.getProductName(0); 21 | testContext.getScenarioContext().setContext(Context.PRODUCT_NAME, productName); 22 | 23 | productListingPage.select_Product(0); 24 | productListingPage.clickOn_AddToCart(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/ConfirmationPageSteps.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import org.junit.Assert; 4 | 5 | import cucumber.TestContext; 6 | import cucumber.api.java.en.Then; 7 | import enums.Context; 8 | import pageObjects.ConfirmationPage; 9 | 10 | public class ConfirmationPageSteps { 11 | TestContext testContext; 12 | ConfirmationPage confirmationPage; 13 | 14 | public ConfirmationPageSteps(TestContext context) { 15 | testContext = context; 16 | confirmationPage = testContext.getPageObjectManager().getConfirmationPage(); 17 | } 18 | 19 | @Then("^verify the order details$") 20 | public void verify_the_order_details(){ 21 | String productName = (String)testContext.getScenarioContext().getContext(Context.PRODUCT_NAME); 22 | Assert.assertTrue(confirmationPage.getProductNames().stream().filter(x -> x.contains(productName)).findFirst().get().length() > 0); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/resources/testDataResources/Customer.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "firstName": "Lakshay", 4 | "lastName": "Sharma", 5 | "age": 35, 6 | "emailAddress": "Lakshay@Gmail.com", 7 | "address": { 8 | "streetAddress": "Shalimar Bagh", 9 | "city": "Delhi", 10 | "postCode": "110088", 11 | "state": "Delhi", 12 | "country": "India", 13 | "county": "Delhi" 14 | }, 15 | "phoneNumber": { 16 | "home": "012345678", 17 | "mob": "0987654321" 18 | } 19 | }, 20 | { 21 | "firstName": "Virender", 22 | "lastName": "Singh", 23 | "age": 35, 24 | "emailAddress": "Virender@Gmail.com", 25 | "address": { 26 | "streetAddress": "Palam Vihar", 27 | "city": "Gurgaon", 28 | "postCode": "122345", 29 | "state": "Haryana", 30 | "country": "India", 31 | "county": "Delhi" 32 | }, 33 | "phoneNumber": { 34 | "home": "012345678", 35 | "mob": "0987654321" 36 | } 37 | } 38 | ] -------------------------------------------------------------------------------- /src/main/java/pageObjects/CartPage.java: -------------------------------------------------------------------------------- 1 | package pageObjects; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.How; 7 | import org.openqa.selenium.support.PageFactory; 8 | 9 | import selenium.Wait; 10 | 11 | public class CartPage { 12 | WebDriver driver; 13 | 14 | public CartPage(WebDriver driver) { 15 | this.driver = driver; 16 | PageFactory.initElements(driver, this); 17 | } 18 | 19 | @FindBy(how = How.CSS, using = ".cart-button") 20 | private WebElement btn_Cart; 21 | 22 | @FindBy(how = How.CSS, using = ".checkout-button.alt") 23 | private WebElement btn_ContinueToCheckout; 24 | 25 | 26 | public void clickOn_Cart() { 27 | btn_Cart.click(); 28 | } 29 | 30 | public void clickOn_ContinueToCheckout(){ 31 | btn_ContinueToCheckout.click(); 32 | Wait.untilPageLoadComplete(driver); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/pageObjects/ConfirmationPage.java: -------------------------------------------------------------------------------- 1 | package pageObjects; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.support.FindAll; 10 | import org.openqa.selenium.support.FindBy; 11 | import org.openqa.selenium.support.How; 12 | import org.openqa.selenium.support.PageFactory; 13 | 14 | public class ConfirmationPage { 15 | WebDriver driver; 16 | 17 | public ConfirmationPage(WebDriver driver) { 18 | this.driver = driver; 19 | PageFactory.initElements(driver, this); 20 | } 21 | 22 | @FindAll(@FindBy(how = How.CSS, using = ".order_item")) 23 | private List prd_List; 24 | 25 | public List getProductNames() { 26 | List productNames = new ArrayList<>(); 27 | for(WebElement element : prd_List) { 28 | productNames.add(element.findElement(By.cssSelector(".product-name")).getText()); 29 | } 30 | return productNames; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/runners/TestRunner.java: -------------------------------------------------------------------------------- 1 | package runners; 2 | 3 | import java.io.*; 4 | import org.junit.AfterClass; 5 | import org.junit.runner.RunWith; 6 | import com.cucumber.listener.Reporter; 7 | import cucumber.api.CucumberOptions; 8 | import cucumber.api.junit.Cucumber; 9 | import managers.FileReaderManager; 10 | 11 | @RunWith(Cucumber.class) 12 | @CucumberOptions( 13 | features = "src/test/resources/functionalTests", 14 | glue= {"stepDefinitions"}, 15 | plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}, 16 | monochrome = true 17 | ) 18 | 19 | 20 | public class TestRunner { 21 | 22 | @AfterClass 23 | public static void writeExtentReport() { 24 | Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath())); 25 | Reporter.setSystemInfo("User Name", System.getProperty("user.name")); 26 | Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone")); 27 | Reporter.setSystemInfo("Machine", "Windows 10" + "64 Bit"); 28 | Reporter.setSystemInfo("Selenium", "3.7.0"); 29 | Reporter.setSystemInfo("Maven", "3.5.2"); 30 | Reporter.setSystemInfo("Java Version", "1.8.0_151"); 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /configs/extent-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | standard 6 | 7 | 8 | UTF-8 9 | 10 | 11 | https 12 | 13 | 14 | ToolsQA - Cucumber Framework 15 | 16 | 17 | ToolsQA - Cucumber Report 18 | 19 | 20 | yyyy-MM-dd 21 | 22 | 23 | HH:mm:ss 24 | 25 | 26 | 27 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/pageObjects/ProductListingPage.java: -------------------------------------------------------------------------------- 1 | package pageObjects; 2 | 3 | import java.util.List; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.FindAll; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.How; 10 | import org.openqa.selenium.support.PageFactory; 11 | import selenium.Wait; 12 | 13 | public class ProductListingPage { 14 | WebDriver driver; 15 | 16 | public ProductListingPage(WebDriver driver) { 17 | this.driver = driver; 18 | PageFactory.initElements(driver, this); 19 | } 20 | 21 | @FindBy(how = How.CSS, using = "button.single_add_to_cart_button") 22 | private WebElement btn_AddToCart; 23 | 24 | @FindAll(@FindBy(how = How.CSS, using = ".noo-product-inner")) 25 | private List prd_List; 26 | 27 | public void clickOn_AddToCart() { 28 | btn_AddToCart.click(); 29 | Wait.untilJqueryIsDone(driver); 30 | } 31 | 32 | public void select_Product(int productNumber) { 33 | prd_List.get(productNumber).click(); 34 | } 35 | 36 | public String getProductName(int productNumber) { 37 | return prd_List.get(productNumber).findElement(By.cssSelector("h3")).getText(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/CheckoutPageSteps.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import cucumber.TestContext; 4 | import cucumber.api.java.en.When; 5 | import managers.FileReaderManager; 6 | import pageObjects.CheckoutPage; 7 | import testDataTypes.Customer; 8 | 9 | public class CheckoutPageSteps { 10 | TestContext testContext; 11 | CheckoutPage checkoutPage; 12 | 13 | public CheckoutPageSteps(TestContext context) { 14 | testContext = context; 15 | checkoutPage = testContext.getPageObjectManager().getCheckoutPage(); 16 | } 17 | 18 | @When("^enter \\\"(.*)\\\" personal details on checkout page$") 19 | public void enter_personal_details_on_checkout_page(String customerName){ 20 | Customer customer = FileReaderManager.getInstance().getJsonReader().getCustomerByName(customerName); 21 | checkoutPage.fill_PersonalDetails(customer); 22 | } 23 | 24 | @When("^select same delivery address$") 25 | public void select_same_delivery_address(){ 26 | checkoutPage.check_ShipToDifferentAddress(false); 27 | } 28 | 29 | @When("^select payment method as \"([^\"]*)\" payment$") 30 | public void select_payment_method_as_payment(String arg1){ 31 | checkoutPage.select_PaymentMethod("CheckPayment"); 32 | } 33 | 34 | @When("^place the order$") 35 | public void place_the_order() { 36 | checkoutPage.check_TermsAndCondition(true); 37 | checkoutPage.clickOn_PlaceOrder(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/managers/PageObjectManager.java: -------------------------------------------------------------------------------- 1 | package managers; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import pageObjects.CartPage; 5 | import pageObjects.CheckoutPage; 6 | import pageObjects.ConfirmationPage; 7 | import pageObjects.HomePage; 8 | import pageObjects.ProductListingPage; 9 | 10 | public class PageObjectManager { 11 | private WebDriver driver; 12 | private ProductListingPage productListingPage; 13 | private CartPage cartPage; 14 | private HomePage homePage; 15 | private CheckoutPage checkoutPage; 16 | private ConfirmationPage confirmationPage; 17 | 18 | public PageObjectManager(WebDriver driver) { 19 | this.driver = driver; 20 | } 21 | 22 | public HomePage getHomePage(){ 23 | return (homePage == null) ? homePage = new HomePage(driver) : homePage; 24 | } 25 | 26 | public ProductListingPage getProductListingPage() { 27 | return (productListingPage == null) ? productListingPage = new ProductListingPage(driver) : productListingPage; 28 | } 29 | 30 | public CartPage getCartPage() { 31 | return (cartPage == null) ? cartPage = new CartPage(driver) : cartPage; 32 | } 33 | 34 | public CheckoutPage getCheckoutPage() { 35 | return (checkoutPage == null) ? checkoutPage = new CheckoutPage(driver) : checkoutPage; 36 | } 37 | 38 | public ConfirmationPage getConfirmationPage() { 39 | return (confirmationPage == null) ? confirmationPage = new ConfirmationPage(driver) : confirmationPage; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/dataProviders/JsonDataReader.java: -------------------------------------------------------------------------------- 1 | package dataProviders; 2 | import java.io.BufferedReader; 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import com.google.gson.Gson; 9 | import managers.FileReaderManager; 10 | import testDataTypes.Customer; 11 | 12 | public class JsonDataReader { 13 | 14 | private final String customerFilePath = FileReaderManager.getInstance().getConfigReader().getTestDataResourcePath() + "Customer.json"; 15 | private List customerList; 16 | 17 | public JsonDataReader(){ 18 | customerList = getCustomerData(); 19 | } 20 | 21 | 22 | private List getCustomerData() { 23 | Gson gson = new Gson(); 24 | BufferedReader bufferReader = null; 25 | try { 26 | bufferReader = new BufferedReader(new FileReader(customerFilePath)); 27 | Customer[] customers = gson.fromJson(bufferReader, Customer[].class); 28 | return Arrays.asList(customers); 29 | }catch(FileNotFoundException e) { 30 | throw new RuntimeException("Json file not found at path : " + customerFilePath); 31 | }finally { 32 | try { if(bufferReader != null) bufferReader.close();} 33 | catch (IOException ignore) {} 34 | } 35 | } 36 | 37 | public final Customer getCustomerByName(String customerName){ 38 | return customerList.stream().filter(x -> x.firstName.equalsIgnoreCase(customerName)).findAny().get(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/stepDefinitions/Hooks.java: -------------------------------------------------------------------------------- 1 | package stepDefinitions; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import org.openqa.selenium.OutputType; 6 | import org.openqa.selenium.TakesScreenshot; 7 | import com.cucumber.listener.Reporter; 8 | import com.google.common.io.Files; 9 | import cucumber.TestContext; 10 | import cucumber.api.Scenario; 11 | import cucumber.api.java.After; 12 | import cucumber.api.java.Before; 13 | 14 | public class Hooks { 15 | 16 | TestContext testContext; 17 | 18 | public Hooks(TestContext context) { 19 | testContext = context; 20 | } 21 | 22 | @Before 23 | public void beforeScenario(Scenario scenario) { 24 | Reporter.assignAuthor("ToolsQA - Lakshay Sharma"); 25 | } 26 | 27 | @After(order = 1) 28 | public void afterScenario(Scenario scenario) { 29 | if (scenario.isFailed()) { 30 | String screenshotName = scenario.getName().replaceAll(" ", "_"); 31 | try { 32 | File sourcePath = ((TakesScreenshot) testContext.getWebDriverManager().getDriver()).getScreenshotAs(OutputType.FILE); 33 | File destinationPath = new File(System.getProperty("user.dir") + "/target/cucumber-reports/screenshots/" + screenshotName + ".png"); 34 | Files.copy(sourcePath, destinationPath); 35 | Reporter.addScreenCaptureFromPath(destinationPath.toString()); 36 | } catch (IOException e) { 37 | } 38 | } 39 | } 40 | 41 | 42 | @After(order = 0) 43 | public void AfterSteps() { 44 | testContext.getWebDriverManager().quitDriver(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/selenium/Wait.java: -------------------------------------------------------------------------------- 1 | package selenium; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.function.Function; 5 | import org.openqa.selenium.JavascriptExecutor; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.support.ui.WebDriverWait; 8 | import managers.FileReaderManager; 9 | 10 | 11 | public class Wait { 12 | 13 | public static void untilJqueryIsDone(WebDriver driver){ 14 | untilJqueryIsDone(driver, FileReaderManager.getInstance().getConfigReader().getImplicitlyWait()); 15 | } 16 | 17 | public static void untilJqueryIsDone(WebDriver driver, Long timeoutInSeconds){ 18 | until(driver, (d) -> 19 | { 20 | Boolean isJqueryCallDone = (Boolean)((JavascriptExecutor) driver).executeScript("return jQuery.active==0"); 21 | if (!isJqueryCallDone) System.out.println("JQuery call is in Progress"); 22 | return isJqueryCallDone; 23 | }, timeoutInSeconds); 24 | } 25 | 26 | public static void untilPageLoadComplete(WebDriver driver) { 27 | untilPageLoadComplete(driver, FileReaderManager.getInstance().getConfigReader().getImplicitlyWait()); 28 | } 29 | 30 | public static void untilPageLoadComplete(WebDriver driver, Long timeoutInSeconds){ 31 | until(driver, (d) -> 32 | { 33 | Boolean isPageLoaded = (Boolean)((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); 34 | if (!isPageLoaded) System.out.println("Document is loading"); 35 | return isPageLoaded; 36 | }, timeoutInSeconds); 37 | } 38 | 39 | public static void until(WebDriver driver, Function waitCondition){ 40 | until(driver, waitCondition, FileReaderManager.getInstance().getConfigReader().getImplicitlyWait()); 41 | } 42 | 43 | 44 | private static void until(WebDriver driver, Function waitCondition, Long timeoutInSeconds){ 45 | WebDriverWait webDriverWait = new WebDriverWait(driver, timeoutInSeconds); 46 | webDriverWait.withTimeout(timeoutInSeconds, TimeUnit.SECONDS); 47 | try{ 48 | webDriverWait.until(waitCondition); 49 | }catch (Exception e){ 50 | System.out.println(e.getMessage()); 51 | } 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/managers/WebDriverManager.java: -------------------------------------------------------------------------------- 1 | package managers; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | import org.openqa.selenium.firefox.FirefoxDriver; 7 | import org.openqa.selenium.ie.InternetExplorerDriver; 8 | import enums.DriverType; 9 | import enums.EnvironmentType; 10 | 11 | public class WebDriverManager { 12 | private WebDriver driver; 13 | private static DriverType driverType; 14 | private static EnvironmentType environmentType; 15 | private static final String CHROME_DRIVER_PROPERTY = "webdriver.chrome.driver"; 16 | 17 | public WebDriverManager() { 18 | driverType = FileReaderManager.getInstance().getConfigReader().getBrowser(); 19 | environmentType = FileReaderManager.getInstance().getConfigReader().getEnvironment(); 20 | } 21 | 22 | public WebDriver getDriver() { 23 | if(driver == null) driver = createDriver(); 24 | return driver; 25 | } 26 | 27 | private WebDriver createDriver() { 28 | switch (environmentType) { 29 | case LOCAL : driver = createLocalDriver(); 30 | break; 31 | case REMOTE : driver = createRemoteDriver(); 32 | break; 33 | } 34 | return driver; 35 | } 36 | 37 | private WebDriver createRemoteDriver() { 38 | throw new RuntimeException("RemoteWebDriver is not yet implemented"); 39 | } 40 | 41 | private WebDriver createLocalDriver() { 42 | switch (driverType) { 43 | case FIREFOX : driver = new FirefoxDriver(); 44 | break; 45 | case CHROME : 46 | System.setProperty(CHROME_DRIVER_PROPERTY, FileReaderManager.getInstance().getConfigReader().getDriverPath()); 47 | driver = new ChromeDriver(); 48 | break; 49 | case INTERNETEXPLORER : driver = new InternetExplorerDriver(); 50 | break; 51 | } 52 | 53 | if(FileReaderManager.getInstance().getConfigReader().getBrowserWindowSize()) driver.manage().window().maximize(); 54 | driver.manage().timeouts().implicitlyWait(FileReaderManager.getInstance().getConfigReader().getImplicitlyWait(), TimeUnit.SECONDS); 55 | return driver; 56 | } 57 | 58 | public void quitDriver() { 59 | driver.close(); 60 | driver.quit(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | ToolsQA 6 | CucumberFramework 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | CucumberFramework 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.12 22 | test 23 | 24 | 25 | org.seleniumhq.selenium 26 | selenium-java 27 | 3.7.0 28 | 29 | 30 | info.cukes 31 | cucumber-java 32 | 1.2.5 33 | 34 | 35 | info.cukes 36 | cucumber-jvm-deps 37 | 1.0.5 38 | provided 39 | 40 | 41 | info.cukes 42 | cucumber-junit 43 | 1.2.5 44 | test 45 | 46 | 47 | info.cukes 48 | cucumber-picocontainer 49 | 1.2.5 50 | test 51 | 52 | 53 | com.aventstack 54 | extentreports 55 | 3.1.2 56 | 57 | 58 | com.vimalselvam 59 | cucumber-extentsreport 60 | 3.0.2 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-compiler-plugin 69 | 3.7.0 70 | 71 | 1.8 72 | 1.8 73 | UTF-8 74 | 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-surefire-plugin 79 | 2.20.1 80 | 81 | 82 | integration-test 83 | 84 | test 85 | 86 | test 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/java/dataProviders/ConfigFileReader.java: -------------------------------------------------------------------------------- 1 | package dataProviders; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.Properties; 8 | 9 | import enums.DriverType; 10 | import enums.EnvironmentType; 11 | 12 | public class ConfigFileReader { 13 | private Properties properties; 14 | private final String propertyFilePath= "configs//Configuration.properties"; 15 | 16 | public ConfigFileReader(){ 17 | BufferedReader reader = null; 18 | try { 19 | reader = new BufferedReader(new FileReader(propertyFilePath)); 20 | properties = new Properties(); 21 | try { properties.load(reader); } 22 | catch (IOException e) { e.printStackTrace(); } 23 | } catch (FileNotFoundException e) { 24 | throw new RuntimeException("Properties file not found at path : " + propertyFilePath); 25 | }finally { 26 | try { if(reader != null) reader.close(); } 27 | catch (IOException ignore) {} 28 | } 29 | } 30 | 31 | public String getDriverPath(){ 32 | String driverPath = properties.getProperty("driverPath"); 33 | if(driverPath!= null) return driverPath; 34 | else throw new RuntimeException("Driver Path not specified in the Configuration.properties file for the Key:driverPath"); 35 | } 36 | 37 | public long getImplicitlyWait() { 38 | String implicitlyWait = properties.getProperty("implicitlyWait"); 39 | if(implicitlyWait != null) { 40 | try{ 41 | return Long.parseLong(implicitlyWait); 42 | }catch(NumberFormatException e) { 43 | throw new RuntimeException("Not able to parse value : " + implicitlyWait + " in to Long"); 44 | } 45 | } 46 | return 30; 47 | } 48 | 49 | public String getApplicationUrl() { 50 | String url = properties.getProperty("url"); 51 | if(url != null) return url; 52 | else throw new RuntimeException("Application Url not specified in the Configuration.properties file for the Key:url"); 53 | } 54 | 55 | public DriverType getBrowser() { 56 | String browserName = properties.getProperty("browser"); 57 | if(browserName == null || browserName.equals("chrome")) return DriverType.CHROME; 58 | else if(browserName.equalsIgnoreCase("firefox")) return DriverType.FIREFOX; 59 | else if(browserName.equals("iexplorer")) return DriverType.INTERNETEXPLORER; 60 | else throw new RuntimeException("Browser Name Key value in Configuration.properties is not matched : " + browserName); 61 | } 62 | 63 | public EnvironmentType getEnvironment() { 64 | String environmentName = properties.getProperty("environment"); 65 | if(environmentName == null || environmentName.equalsIgnoreCase("local")) return EnvironmentType.LOCAL; 66 | else if(environmentName.equals("remote")) return EnvironmentType.REMOTE; 67 | else throw new RuntimeException("Environment Type Key value in Configuration.properties is not matched : " + environmentName); 68 | } 69 | 70 | public Boolean getBrowserWindowSize() { 71 | String windowSize = properties.getProperty("windowMaximize"); 72 | if(windowSize != null) return Boolean.valueOf(windowSize); 73 | return true; 74 | } 75 | 76 | public String getTestDataResourcePath(){ 77 | String testDataResourcePath = properties.getProperty("testDataResourcePath"); 78 | if(testDataResourcePath!= null) return testDataResourcePath; 79 | else throw new RuntimeException("Test Data Resource Path not specified in the Configuration.properties file for the Key:testDataResourcePath"); 80 | } 81 | 82 | public String getReportConfigPath(){ 83 | String reportConfigPath = properties.getProperty("reportConfigPath"); 84 | if(reportConfigPath!= null) return reportConfigPath; 85 | else throw new RuntimeException("Report Config Path not specified in the Configuration.properties file for the Key:reportConfigPath"); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/pageObjects/CheckoutPage.java: -------------------------------------------------------------------------------- 1 | package pageObjects; 2 | 3 | import java.util.List; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindAll; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.How; 9 | import org.openqa.selenium.support.PageFactory; 10 | 11 | import selenium.Wait; 12 | import testDataTypes.Customer; 13 | 14 | public class CheckoutPage { 15 | WebDriver driver; 16 | 17 | public CheckoutPage(WebDriver driver) { 18 | this.driver = driver; 19 | PageFactory.initElements(driver, this); 20 | } 21 | 22 | @FindBy(how = How.CSS, using = "#billing_first_name") 23 | private WebElement txtbx_FirstName; 24 | 25 | @FindBy(how = How.CSS, using = "#billing_last_name") 26 | private WebElement txtbx_LastName; 27 | 28 | @FindBy(how = How.CSS, using = "#billing_email") 29 | private WebElement txtbx_Email; 30 | 31 | @FindBy(how = How.CSS, using = "#billing_phone") 32 | private WebElement txtbx_Phone; 33 | 34 | @FindBy(how = How.CSS, using = "#billing_country_field .select2-arrow") 35 | private WebElement drpdwn_CountryDropDownArrow; 36 | 37 | @FindBy(how = How.CSS, using = "#billing_state_field .select2-arrow") 38 | private WebElement drpdwn_CountyDropDownArrow; 39 | 40 | @FindAll(@FindBy(how = How.CSS, using = "#select2-drop ul li")) 41 | private List country_List; 42 | 43 | @FindBy(how = How.CSS, using = "#billing_city") 44 | private WebElement txtbx_City; 45 | 46 | @FindBy(how = How.CSS, using = "#billing_address_1") 47 | private WebElement txtbx_Address; 48 | 49 | @FindBy(how = How.CSS, using = "#billing_postcode") 50 | private WebElement txtbx_PostCode; 51 | 52 | @FindBy(how = How.CSS, using = "#ship-to-different-address-checkbox") 53 | private WebElement chkbx_ShipToDifferetAddress; 54 | 55 | @FindAll(@FindBy(how = How.CSS, using = "ul.wc_payment_methods li")) 56 | private List paymentMethod_List; 57 | 58 | @FindBy(how = How.CSS, using = "#terms.input-checkbox") 59 | private WebElement chkbx_AcceptTermsAndCondition; 60 | 61 | @FindBy(how = How.CSS, using = "#place_order") 62 | private WebElement btn_PlaceOrder; 63 | 64 | 65 | public void enter_Name(String name) { 66 | txtbx_FirstName.sendKeys(name); 67 | } 68 | 69 | public void enter_LastName(String lastName) { 70 | txtbx_LastName.sendKeys(lastName); 71 | } 72 | 73 | public void enter_Email(String email) { 74 | txtbx_Email.sendKeys(email); 75 | } 76 | 77 | public void enter_Phone(String phone) { 78 | txtbx_Phone.sendKeys(phone); 79 | } 80 | 81 | public void enter_City(String city) { 82 | txtbx_City.sendKeys(city); 83 | } 84 | 85 | public void enter_Address(String address) { 86 | txtbx_Address.sendKeys(address); 87 | } 88 | 89 | public void enter_PostCode(String postCode) { 90 | txtbx_PostCode.sendKeys(postCode); 91 | } 92 | 93 | public void check_ShipToDifferentAddress(boolean value) { 94 | if(!value) chkbx_ShipToDifferetAddress.click(); 95 | Wait.untilJqueryIsDone(driver); 96 | } 97 | 98 | public void select_Country(String countryName) { 99 | drpdwn_CountryDropDownArrow.click(); 100 | Wait.untilJqueryIsDone(driver); 101 | 102 | for(WebElement country : country_List){ 103 | if(country.getText().equals(countryName)) { 104 | country.click(); 105 | Wait.untilJqueryIsDone(driver); 106 | break; 107 | } 108 | } 109 | 110 | } 111 | 112 | public void select_County(String countyName) { 113 | drpdwn_CountyDropDownArrow.click(); 114 | Wait.untilJqueryIsDone(driver); 115 | for(WebElement county : country_List){ 116 | if(county.getText().equals(countyName)) { 117 | county.click(); 118 | //Wait.untilJqueryIsDone(driver); 119 | break; 120 | } 121 | } 122 | } 123 | 124 | public void select_PaymentMethod(String paymentMethod) { 125 | if(paymentMethod.equals("CheckPayment")) { 126 | paymentMethod_List.get(0).click(); 127 | }else if(paymentMethod.equals("Cash")) { 128 | paymentMethod_List.get(1).click(); 129 | }else { 130 | new Exception("Payment Method not recognised : " + paymentMethod); 131 | } 132 | Wait.untilJqueryIsDone(driver); 133 | 134 | } 135 | 136 | public void check_TermsAndCondition(boolean value) { 137 | if(value) chkbx_AcceptTermsAndCondition.click(); 138 | } 139 | 140 | public void clickOn_PlaceOrder() { 141 | btn_PlaceOrder.submit(); 142 | Wait.untilJqueryIsDone(driver); 143 | Wait.untilPageLoadComplete(driver); 144 | } 145 | 146 | 147 | public void fill_PersonalDetails(Customer customer) { 148 | enter_Name(customer.firstName); 149 | enter_LastName(customer.lastName); 150 | enter_Phone(customer.phoneNumber.mob); 151 | enter_Email(customer.emailAddress); 152 | enter_City(customer.address.city); 153 | enter_Address(customer.address.streetAddress); 154 | enter_PostCode(customer.address.postCode); 155 | select_Country(customer.address.country); 156 | select_County(customer.address.county); 157 | } 158 | 159 | } 160 | --------------------------------------------------------------------------------