├── CucumberReports.zip ├── README.md ├── pom.xml └── src └── test ├── java └── awesomecucumber │ ├── apis │ ├── ApiRequest.java │ ├── CartApi.java │ └── SpecBuilder.java │ ├── constants │ └── FrameworkConstants.java │ ├── context │ └── TestContext.java │ ├── customtype │ ├── CustomDataTableType.java │ └── CustomParameterType.java │ ├── domainobjects │ ├── BillingDetails.java │ ├── Cookies.java │ ├── Product.java │ └── ProductList.java │ ├── enums │ ├── EndPoint.java │ ├── EnvType.java │ └── WaitStrategy.java │ ├── factory │ ├── DriverFactory.java │ └── PageFactoryManager.java │ ├── hooks │ └── MyHooks.java │ ├── java_Mail_API │ ├── EmailAttachmentsSender.java │ └── EmailConfig.java │ ├── pages │ ├── BasePage.java │ ├── CartPage.java │ ├── CheckoutPage.java │ ├── ProductPage.java │ └── StorePage.java │ ├── runners │ ├── MyJUnitRunnerTest.java │ └── MyTestNGRunnerTest.java │ ├── stepdefinitions │ ├── CartStepDefinitions.java │ ├── CheckoutStepDefinitions.java │ ├── CustomerStepDefinitions.java │ ├── MyStepDefinitions.java │ ├── ProductStepDefinitions.java │ └── StoreStepDefinitions.java │ └── utils │ ├── ConfigLoader.java │ ├── CookieUtils.java │ ├── EmailSendUtils.java │ ├── JacksonUtils.java │ ├── PropertyUtils.java │ └── ZipUtils.java └── resources ├── config ├── int_config.properties ├── prod_config.properties ├── qa_config.properties └── stg_config.properties ├── cucumber.properties ├── features ├── add_to_cart.feature └── guest_place_an_order.feature └── products.json /CucumberReports.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajatt95/MasterSeleniumFramework_BDD/589321ec878281ab7bb487986eb934cd7d93ccf2/CucumberReports.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MasterSeleniumFramework_BDD 2 | With further updates - This project is designed and developed with the help of - 3 | 1. Udemy course (OmPrakash Chavan - Cucumber BDD Masterclass with Selenium WebDriver & Java) - 4 | [Learnings From Course.pdf](https://github.com/rajatt95/MasterSeleniumFramework_BDD/files/7998307/Learnings.From.Course.pdf) 5 | ![image](https://user-images.githubusercontent.com/26399692/152515639-83ff0b6e-3148-4c4c-821b-491c4d1f415e.png) 6 | ![image](https://user-images.githubusercontent.com/26399692/152515700-e7f086cf-4ed9-469c-b65c-51aeb841e783.png) 7 | ![image](https://user-images.githubusercontent.com/26399692/152515746-35b19cb5-9fcc-4304-9abd-1e9b872bf18f.png) 8 | 9 | ![image](https://user-images.githubusercontent.com/26399692/152515304-c933c4e0-f085-4b60-be3d-144caf9d9054.png) 10 | ![image](https://user-images.githubusercontent.com/26399692/152515549-abcc6a1e-4d54-4eba-b741-8b1910aee102.png) 11 | 12 | Screenshot by Snip My at 04-Feb-2022 at 2_41_05 AM 13 | 14 | ------------------------------------------------------------ 15 | **Framework features:** 16 | 1. Uses Domain objects 17 | 2. Support multiple Runners - TestNG, JUnit, CLI 18 | 3. Uses Dependency Injection Framework 19 | 4. Supports parallel execution 20 | 5. Uses API to setup the Application state 21 | 6. Captures screenshot on Scenario Failure 22 | 7. Supports command line execution using Maven 23 | 8. Supports CI/CD integration 24 | ------------------------------------------------------------ 25 | It has a concept of Atomic tests (Achieved by Selenium WebDriver API and RestAssured API) 26 | ------------------------------------------------------------ 27 | # Atomic Tests: 28 | ![image](https://user-images.githubusercontent.com/26399692/138962929-70094e77-ff3c-405e-95f8-c91c4e0912a6.png) 29 | ------------------------------------------------------------ 30 | Updations done: 31 | ------------------------------------------------------------ 32 | **Reports (me.jvt.cucumber -> reporting-plugin) ** 33 | ![image](https://user-images.githubusercontent.com/26399692/152516617-160ec7de-c330-490e-9cb9-78b7d50cbe5d.png) 34 | ------------------------------------------------------------ 35 | **Screenshot on failure to Reports** 36 | ![image](https://user-images.githubusercontent.com/26399692/152516718-701a6cc9-bf46-475f-824f-406413fa8288.png) 37 | ------------------------------------------------------------ 38 | **Zip reports** 39 | ------------------------------------------------------------ 40 | **Browser instances from pom.xml** 41 | ![image](https://user-images.githubusercontent.com/26399692/152516862-973ca6e9-bf4e-45de-85f5-f7fba24f4927.png) 42 | ------------------------------------------------------------ 43 | **Execution** 44 | 1. mvn clean test (This will execute with default env (Stg) and browser (Edge)) 45 | 2. mvn clean test -Denv=INT -Dbrowser=firefox (his will execute with on Int and Firefox browser) 46 | 3. mvn clean test -Denv=INT -Dbrowser=firefox -Dcucumber.filter.tags@smoke (This will execute with on Int and Firefox browser and scenarios tagged as smoke) 47 | ------------------------------------------------------------ 48 | 49 | [Cucumber_Reports_Local.pdf](https://github.com/rajatt95/MasterSeleniumFramework_BDD/files/7998343/Cucumber_Reports_Local.pdf) 50 | ![image](https://user-images.githubusercontent.com/26399692/152431537-75cab046-67a6-4387-a980-f3dc19031f5c.png) 51 | ------------------------------------------------------------ 52 | [Cucumber_Reports_Cloud.pdf](https://github.com/rajatt95/MasterSeleniumFramework_BDD/files/7998338/Cucumber_Reports_Cloud.pdf) 53 | ![image](https://user-images.githubusercontent.com/26399692/152431482-e010a8c0-25b8-425f-be92-83d0f9a52fb2.png) 54 | 55 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.learning 4 | MasterSeleniumFramework_BDD 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 3.0.0-M5 9 | 10 | 3 11 | 8 12 | 8 13 | 14 | 15 | 7.2.0 16 | 4.1.2 17 | 4.4.3 18 | 4.4.0 19 | 2.13.1 20 | 1.12 21 | 1.6.2 22 | 23 | 24 | 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-surefire-plugin 29 | ${maven.surefire.plugin.version} 30 | 31 | 32 | 33 | 34 | dataproviderthreadcount 35 | 36 | ${dataproviderthreadcount.value} 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | io.cucumber 51 | cucumber-java 52 | ${cucumber.version} 53 | 54 | 55 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | io.cucumber 67 | cucumber-testng 68 | ${cucumber.version} 69 | 70 | 71 | 72 | 73 | io.cucumber 74 | cucumber-picocontainer 75 | ${cucumber.version} 76 | 77 | 78 | 79 | 80 | org.seleniumhq.selenium 81 | selenium-java 82 | ${selenium.version} 83 | 84 | 85 | 86 | 87 | io.github.bonigarcia 88 | webdrivermanager 89 | ${webdrivermanager.version} 90 | 91 | 92 | 93 | 94 | 95 | io.rest-assured 96 | rest-assured 97 | ${rest.assured.version} 98 | 99 | 100 | 101 | 102 | com.fasterxml.jackson.core 103 | jackson-databind 104 | ${jackson.databind.version} 105 | 106 | 107 | 108 | 109 | me.jvt.cucumber 110 | reporting-plugin 111 | ${cucumber.version} 112 | 113 | 114 | 115 | 116 | org.zeroturnaround 117 | zt-zip 118 | ${zt.zp.version} 119 | 120 | 121 | 122 | 123 | com.sun.mail 124 | javax.mail 125 | ${javax.mail.version} 126 | 127 | 128 | 129 | 130 | com.aventstack 131 | extentreports 132 | 5.0.9 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/apis/ApiRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.apis; 14 | 15 | import io.restassured.http.Cookies; 16 | import io.restassured.http.Headers; 17 | import io.restassured.response.Response; 18 | 19 | import java.util.HashMap; 20 | 21 | import static io.restassured.RestAssured.given; 22 | 23 | public class ApiRequest extends SpecBuilder{ 24 | 25 | public static Response post(String endPoint, Headers headers, 26 | HashMap formParams, Cookies cookies){ 27 | return given(getRequestSpec()). 28 | headers(headers). 29 | formParams(formParams). 30 | cookies(cookies). 31 | when(). 32 | post(endPoint). 33 | then(). 34 | spec(getResponseSpec()). 35 | extract(). 36 | response(); 37 | } 38 | 39 | public static Response get(String endPoint, Cookies cookies){ 40 | return given(getRequestSpec()). 41 | cookies(cookies). 42 | when(). 43 | get(endPoint). 44 | then(). 45 | spec(getResponseSpec()). 46 | extract(). 47 | response(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/apis/CartApi.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.apis; 14 | 15 | import java.util.HashMap; 16 | 17 | import awesomecucumber.enums.EndPoint; 18 | import io.restassured.http.Cookies; 19 | import io.restassured.http.Header; 20 | import io.restassured.http.Headers; 21 | import io.restassured.response.Response; 22 | 23 | public class CartApi { 24 | private Cookies cookies; 25 | 26 | public CartApi(Cookies cookies){ 27 | this.cookies = cookies; 28 | } 29 | 30 | public Cookies getCookies(){ 31 | return cookies; 32 | } 33 | 34 | public Response addToCart(int productId, int quantity){ 35 | Header header = new Header("content-type", "application/x-www-form-urlencoded"); 36 | Headers headers = new Headers(header); 37 | 38 | HashMap formParams = new HashMap<>(); 39 | formParams.put("product_sku", ""); 40 | formParams.put("product_id", productId); 41 | formParams.put("quantity", quantity); 42 | 43 | Response response = ApiRequest.post(EndPoint.ADD_TO_CART.url, headers, formParams, cookies); 44 | 45 | if(response.getStatusCode() != 200){ 46 | throw new RuntimeException("Failed to add product" + productId + " to the cart" + 47 | ", HTTP Status Code: " + response.getStatusCode()); 48 | } 49 | this.cookies = response.getDetailedCookies(); 50 | return response; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/apis/SpecBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.apis; 14 | 15 | import awesomecucumber.utils.ConfigLoader; 16 | import io.restassured.builder.RequestSpecBuilder; 17 | import io.restassured.builder.ResponseSpecBuilder; 18 | import io.restassured.filter.log.LogDetail; 19 | import io.restassured.specification.RequestSpecification; 20 | import io.restassured.specification.ResponseSpecification; 21 | 22 | public class SpecBuilder { 23 | public static RequestSpecification getRequestSpec(){ 24 | return new RequestSpecBuilder(). 25 | setBaseUri(ConfigLoader.getInstance().getBaseUrl()). 26 | log(LogDetail.ALL). 27 | build(); 28 | } 29 | 30 | public static ResponseSpecification getResponseSpec(){ 31 | return new ResponseSpecBuilder(). 32 | // log(LogDetail.METHOD). 33 | // log(LogDetail.URI). 34 | // log(LogDetail.PARAMS). 35 | // log(LogDetail.STATUS). 36 | // log(LogDetail.HEADERS). 37 | // log(LogDetail.COOKIES). 38 | log(LogDetail.ALL). 39 | build(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/constants/FrameworkConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.constants; 14 | 15 | public class FrameworkConstants { 16 | 17 | // public static final String STORE = "/store"; 18 | public static final int EXPLICIT_WAIT = 10; 19 | 20 | public static final String YES = "yes"; 21 | public static final String NO = "no"; 22 | 23 | public static final String PROJECT_NAME = "Automation Test Suite Report - Master Selenium Framework - BDD Cucumber"; 24 | 25 | /* PARAMETERS TO BE USED FROM MAVEN COMMAND LINE */ 26 | public static final String PARAMETER_ENV = "env"; 27 | public static final String PARAMETER_BROWSER = "browser"; 28 | 29 | /* SUPPORTED BROWSERS */ 30 | public static final String BROWSER_CHROME = "chrome"; 31 | public static final String BROWSER_FIREFOX = "firefox"; 32 | public static final String BROWSER_SAFARI = "safari"; 33 | public static final String BROWSER_EDGE = "edge"; 34 | public static final String BROWSER_OPERA = "opera"; 35 | 36 | public static final String ATTRIBUTE_VALUE = "value"; 37 | 38 | /* ENVIRONMENT CONFIGURATION FILES */ 39 | public static final String DIRECTORY_ENV_CONFIG = "src/test/resources/config/"; 40 | public static final String ENV_CONFIG_QA = "qa_config.properties"; 41 | public static final String ENV_CONFIG_INT = "int_config.properties"; 42 | public static final String ENV_CONFIG_STG = "stg_config.properties"; 43 | public static final String ENV_CONFIG_PROD = "prod_config.properties"; 44 | 45 | /* CUCUMBER REPORTS */ 46 | public static final String REPORTS_CUCUMBER_LOCATION = "./target/cucumber/"; 47 | public static final String REPORTS_CUCUMBER_LOCAL = REPORTS_CUCUMBER_LOCATION + "cucumber.html"; 48 | public static final String REPORTS_ZIPPED_FILE_NAME = "CucumberReports.zip"; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/context/TestContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.context; 14 | 15 | import java.io.IOException; 16 | 17 | import org.openqa.selenium.WebDriver; 18 | 19 | import awesomecucumber.domainobjects.BillingDetails; 20 | import awesomecucumber.domainobjects.Cookies; 21 | import awesomecucumber.domainobjects.Product; 22 | import awesomecucumber.domainobjects.ProductList; 23 | import awesomecucumber.utils.JacksonUtils; 24 | 25 | public class TestContext { 26 | public WebDriver driver; 27 | public BillingDetails billingDetails; 28 | public Cookies cookies; 29 | public ProductList productList = new ProductList(); 30 | public Product product; 31 | 32 | /** 33 | * Dependency Injection using Pico container 34 | */ 35 | public TestContext() throws IOException { 36 | cookies = new Cookies(); 37 | cookies.setCookies(new io.restassured.http.Cookies()); 38 | productList.addAllProducts(JacksonUtils.deserializeJson("products.json", Product[].class)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/customtype/CustomDataTableType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.customtype; 14 | 15 | import awesomecucumber.domainobjects.BillingDetails; 16 | import io.cucumber.java.DataTableType; 17 | 18 | import java.util.Map; 19 | 20 | public class CustomDataTableType { 21 | 22 | @DataTableType 23 | public BillingDetails billingDetailsEntry(Map entry){ 24 | 25 | /** 26 | * firstname, lastname, address_line1, ........ are coming from feature files 27 | * 28 | */ 29 | return new BillingDetails(entry.get("firstname"), 30 | entry.get("lastname"), 31 | entry.get("address_line1"), 32 | entry.get("city"), 33 | entry.get("state"), 34 | entry.get("zip"), 35 | entry.get("email")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/customtype/CustomParameterType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.customtype; 14 | 15 | import awesomecucumber.domainobjects.Product; 16 | import io.cucumber.java.ParameterType; 17 | 18 | public class CustomParameterType { 19 | 20 | /** 21 | * .* -> means all are allowed 22 | */ 23 | @ParameterType(".*") 24 | public Product product(String name) { 25 | return new Product(name.replace("\"", "")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/domainobjects/BillingDetails.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.domainobjects; 14 | 15 | public class BillingDetails { 16 | 17 | private String billingFirstName; 18 | private String billingLastName; 19 | private String billingAddressOne; 20 | private String billingCity; 21 | private String billingStateName; 22 | private String billingZip; 23 | private String billingEmail; 24 | 25 | public BillingDetails(String billingFirstName, String billingLastName, String billingAddressOne, String billingCity, 26 | String billingStateName, String billingZip, String billingEmail) { 27 | this.billingFirstName = billingFirstName; 28 | this.billingLastName = billingLastName; 29 | this.billingAddressOne = billingAddressOne; 30 | this.billingCity = billingCity; 31 | this.billingStateName = billingStateName; 32 | this.billingZip = billingZip; 33 | this.billingEmail = billingEmail; 34 | } 35 | 36 | public String getBillingFirstName() { 37 | return billingFirstName; 38 | } 39 | 40 | public void setBillingFirstName(String billingFirstName) { 41 | this.billingFirstName = billingFirstName; 42 | } 43 | 44 | public String getBillingLastName() { 45 | return billingLastName; 46 | } 47 | 48 | public void setBillingLastName(String billingLastName) { 49 | this.billingLastName = billingLastName; 50 | } 51 | 52 | public String getBillingAddressOne() { 53 | return billingAddressOne; 54 | } 55 | 56 | public void setBillingAddressOne(String billingAddressOne) { 57 | this.billingAddressOne = billingAddressOne; 58 | } 59 | 60 | public String getBillingCity() { 61 | return billingCity; 62 | } 63 | 64 | public void setBillingCity(String billingCity) { 65 | this.billingCity = billingCity; 66 | } 67 | 68 | public String getBillingStateName() { 69 | return billingStateName; 70 | } 71 | 72 | public void setBillingStateName(String billingStateName) { 73 | this.billingStateName = billingStateName; 74 | } 75 | 76 | public String getBillingZip() { 77 | return billingZip; 78 | } 79 | 80 | public void setBillingZip(String billingZip) { 81 | this.billingZip = billingZip; 82 | } 83 | 84 | public String getBillingEmail() { 85 | return billingEmail; 86 | } 87 | 88 | public void setBillingEmail(String billingEmail) { 89 | this.billingEmail = billingEmail; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/domainobjects/Cookies.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.domainobjects; 14 | 15 | import awesomecucumber.utils.CookieUtils; 16 | import org.openqa.selenium.Cookie; 17 | import org.openqa.selenium.WebDriver; 18 | 19 | import java.util.List; 20 | 21 | public class Cookies { 22 | 23 | private io.restassured.http.Cookies cookies; 24 | 25 | public io.restassured.http.Cookies getCookies() { 26 | return cookies; 27 | } 28 | 29 | public void setCookies(io.restassured.http.Cookies cookies) { 30 | this.cookies = cookies; 31 | } 32 | 33 | public void injectCookiesToBrowser(WebDriver driver) { 34 | List seleniumCookies = new CookieUtils().convertRestAssuredCookiesToSeleniumCookies(cookies); 35 | 36 | int index = 0; 37 | for (Cookie seleniumCookie : seleniumCookies) { 38 | System.out.println("COUNTER " + index + ": " + seleniumCookie.toString()); 39 | driver.manage().addCookie(seleniumCookie); 40 | index++; 41 | } 42 | driver.navigate().refresh(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/domainobjects/Product.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.domainobjects; 14 | 15 | public class Product { 16 | 17 | private int id; 18 | private int quantity; 19 | 20 | public Product() { 21 | } 22 | 23 | public Product(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | private String name; 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public void setQuantity(int quantity) { 46 | this.quantity = quantity; 47 | } 48 | 49 | public int getQuantity() { 50 | return quantity; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/domainobjects/ProductList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.domainobjects; 14 | 15 | public class ProductList { 16 | private Product[] products; 17 | 18 | public void addAllProducts(Product[] products){ 19 | this.products = products; 20 | } 21 | 22 | public Product getProductByName(String name) throws Exception { 23 | for(Product product: products){ 24 | if(product.getName().equals(name)){ 25 | return product; 26 | } 27 | } 28 | throw new Exception("Product with name: " + name + " not found"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/enums/EndPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.enums; 14 | 15 | public enum EndPoint { 16 | STORE("/store"), 17 | ACCOUNT("/account"), 18 | ADD_TO_CART("/?wc-ajax=add_to_cart"), 19 | CHECKOUT("/checkout"); 20 | 21 | public final String url; 22 | 23 | EndPoint(String url) { 24 | this.url = url; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/enums/EnvType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.enums; 14 | 15 | public enum EnvType { 16 | QA, 17 | INT, 18 | STG, 19 | PROD 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/enums/WaitStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.enums; 14 | 15 | public enum WaitStrategy { 16 | CLICKABLE, PRESENCE, VISIBLE, NONE 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/factory/DriverFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.factory; 14 | 15 | import io.github.bonigarcia.wdm.WebDriverManager; 16 | import org.openqa.selenium.WebDriver; 17 | import org.openqa.selenium.chrome.ChromeDriver; 18 | import org.openqa.selenium.edge.EdgeDriver; 19 | import org.openqa.selenium.firefox.FirefoxDriver; 20 | import org.openqa.selenium.opera.OperaDriver; 21 | import org.openqa.selenium.safari.SafariDriver; 22 | 23 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_CHROME; 24 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_FIREFOX; 25 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_SAFARI; 26 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_EDGE; 27 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_OPERA; 28 | 29 | public class DriverFactory { 30 | 31 | public static WebDriver initializeDriver(String browser) { 32 | WebDriver driver; 33 | // switch (browser) { 34 | // case "chrome" -> { 35 | // WebDriverManager.chromedriver().setup(); 36 | // driver = new ChromeDriver(); 37 | // } 38 | // case "firefox" -> { 39 | // WebDriverManager.firefoxdriver().setup(); 40 | // driver = new FirefoxDriver(); 41 | // } 42 | // default -> throw new IllegalStateException("INVALID BROWSER: " + browser); 43 | // } 44 | 45 | switch (browser) { 46 | 47 | case BROWSER_CHROME: { 48 | WebDriverManager.chromedriver().setup(); 49 | driver = new ChromeDriver(); 50 | break; 51 | } 52 | case BROWSER_FIREFOX: { 53 | WebDriverManager.firefoxdriver().setup(); 54 | driver = new FirefoxDriver(); 55 | break; 56 | } 57 | case BROWSER_SAFARI: { 58 | driver = new SafariDriver(); 59 | break; 60 | } 61 | case BROWSER_EDGE: { 62 | WebDriverManager.edgedriver().setup(); 63 | driver = new EdgeDriver(); 64 | break; 65 | } 66 | case BROWSER_OPERA: { 67 | WebDriverManager.operadriver().setup(); 68 | driver = new OperaDriver(); 69 | break; 70 | } 71 | default: 72 | throw new IllegalStateException("INVALID BROWSER: " + browser); 73 | } 74 | driver.manage().window().maximize(); 75 | return driver; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/factory/PageFactoryManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.factory; 14 | 15 | import org.openqa.selenium.WebDriver; 16 | 17 | import awesomecucumber.pages.CartPage; 18 | import awesomecucumber.pages.CheckoutPage; 19 | import awesomecucumber.pages.ProductPage; 20 | import awesomecucumber.pages.StorePage; 21 | 22 | public class PageFactoryManager { 23 | 24 | private static StorePage storePage; 25 | private static CartPage cartPage; 26 | private static CheckoutPage checkoutPage; 27 | private static ProductPage productPage; 28 | 29 | public static StorePage getStorePage(WebDriver driver) { 30 | /** 31 | * Using Ternary Operator: Checking for storePage as null. 32 | * 33 | * If it is null, then, create new object and return 34 | * 35 | * If it is not null, then, return storePage 36 | */ 37 | return storePage == null ? new StorePage(driver) : storePage; 38 | } 39 | 40 | public static CartPage getCartPage(WebDriver driver) { 41 | return cartPage == null ? new CartPage(driver) : cartPage; 42 | } 43 | 44 | public static CheckoutPage getCheckoutPage(WebDriver driver) { 45 | return checkoutPage == null ? new CheckoutPage(driver) : checkoutPage; 46 | } 47 | 48 | public static ProductPage getProductPage(WebDriver driver) { 49 | return productPage == null ? new ProductPage(driver) : productPage; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/hooks/MyHooks.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.hooks; 14 | 15 | import static awesomecucumber.constants.FrameworkConstants.BROWSER_FIREFOX; 16 | import static awesomecucumber.constants.FrameworkConstants.PARAMETER_BROWSER; 17 | 18 | import awesomecucumber.context.TestContext; 19 | import awesomecucumber.factory.DriverFactory; 20 | import awesomecucumber.utils.ZipUtils; 21 | import io.cucumber.java.*; 22 | import org.openqa.selenium.OutputType; 23 | import org.openqa.selenium.TakesScreenshot; 24 | import org.openqa.selenium.WebDriver; 25 | 26 | public class MyHooks { 27 | 28 | private WebDriver driver; 29 | private final TestContext context; 30 | 31 | /** 32 | * Dependency Injection using Pico container 33 | */ 34 | public MyHooks(TestContext context) { 35 | this.context = context; 36 | } 37 | 38 | @Before 39 | public void before(Scenario scenario) { 40 | 41 | // ExtentReport.createTest(scenario.getName()); 42 | 43 | System.out.println( 44 | "BEFORE: THREAD ID : " + Thread.currentThread().getId() + "," + "SCENARIO NAME: " + scenario.getName()); 45 | 46 | /* 47 | * System.getProperty("browser" -> This is for test execution using Maven 48 | * Command Line file 49 | */ 50 | /* 51 | * Setting Edge browser as default 52 | */ 53 | // driver = DriverFactory.initializeDriver(System.getProperty("browser", "edge")); 54 | // driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, 55 | // BROWSER_CHROME)); 56 | driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, BROWSER_FIREFOX)); 57 | // driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, BROWSER_EDGE)); 58 | // driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, 59 | // BROWSER_OPERA)); 60 | // driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, 61 | // BROWSER_SAFARI)); 62 | 63 | context.driver = driver; 64 | } 65 | 66 | @After 67 | public void after(Scenario scenario) { 68 | System.out.println( 69 | "AFTER: THREAD ID : " + Thread.currentThread().getId() + "," + "SCENARIO NAME: " + scenario.getName()); 70 | 71 | /* If Scenario fails */ 72 | /* This is for attaching the screenshot in Cucumber report */ 73 | if (scenario.isFailed()) { 74 | byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); 75 | scenario.attach(screenshot, "image/png", scenario.getName()); 76 | } 77 | 78 | // doExtentReportWork(scenario); 79 | 80 | driver.quit(); 81 | } 82 | 83 | // private void doExtentReportWork(Scenario scenario) { 84 | // 85 | // if (scenario.getStatus().toString().equals("PASSED")) { 86 | // ExtentLogger.pass("" + scenario.getName() + ""); 87 | // ExtentLogger.pass("" + scenario.getStatus().PASSED + ""); 88 | // } 89 | // 90 | // if (scenario.getStatus().toString().equals("SKIPPED")) { 91 | // ExtentLogger.skip("" + scenario.getName() + ""); 92 | // ExtentLogger.skip("" + scenario.getStatus().SKIPPED + ""); 93 | // } 94 | // 95 | // if (scenario.isFailed()) { 96 | // ExtentLogger.fail("" + scenario.getName() + ""); 97 | // ExtentLogger.fail("" + scenario.getStatus().FAILED + ""); 98 | // } 99 | // 100 | // } 101 | 102 | // @BeforeStep 103 | // public static void beforeStep() { 104 | // ExtentLogger.pass("" + "BEFORE STEP" + ""); 105 | // } 106 | 107 | @BeforeAll 108 | public static void beforeAll() { 109 | // ExtentReport.initReports(); 110 | } 111 | 112 | @AfterAll 113 | public static void afterAll() { 114 | // ExtentReport.flushReports(); 115 | ZipUtils.zip(); 116 | // EmailSendUtils.sendEmail(); 117 | 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/java_Mail_API/EmailAttachmentsSender.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.java_Mail_API; 14 | 15 | import java.io.IOException; 16 | import java.util.Date; 17 | import java.util.Properties; 18 | 19 | import javax.mail.Authenticator; 20 | import javax.mail.Message; 21 | import javax.mail.MessagingException; 22 | import javax.mail.Multipart; 23 | import javax.mail.PasswordAuthentication; 24 | import javax.mail.Session; 25 | import javax.mail.Transport; 26 | import javax.mail.internet.AddressException; 27 | import javax.mail.internet.InternetAddress; 28 | import javax.mail.internet.MimeBodyPart; 29 | import javax.mail.internet.MimeMessage; 30 | import javax.mail.internet.MimeMultipart; 31 | 32 | /** 33 | * https://www.codejava.net/java-ee/javamail/send-e-mail-with-attachment-in-java 34 | */ 35 | public class EmailAttachmentsSender { 36 | 37 | /** 38 | * i) Send n no. of Attachments 39 | * 40 | * ii) Format set for TC count 41 | * 42 | * iii) Send mail to n no. of Users 43 | * 44 | */ 45 | public static void sendEmailWithAttachments(String host, String port, final String userName, final String password, 46 | String[] toAddress, String subject, String message, String... attachFiles) 47 | throws AddressException, MessagingException { 48 | // sets SMTP server properties 49 | 50 | Properties properties = new Properties(); 51 | properties.put("mail.smtp.host", host); 52 | properties.put("mail.smtp.port", port); 53 | properties.put("mail.smtp.auth", "true"); 54 | properties.put("mail.smtp.starttls.enable", "true"); 55 | properties.put("mail.user", userName); 56 | properties.put("mail.password", password); 57 | 58 | // creates a new session with an authenticator 59 | Authenticator auth = new Authenticator() { 60 | public PasswordAuthentication getPasswordAuthentication() { 61 | return new PasswordAuthentication(userName, password); 62 | } 63 | }; 64 | Session session = Session.getInstance(properties, auth); 65 | 66 | // creates a new e-mail message 67 | Message msg = new MimeMessage(session); 68 | 69 | msg.setFrom(new InternetAddress(userName)); 70 | 71 | InternetAddress[] addressTo = new InternetAddress[toAddress.length]; 72 | for (int i = 0; i < toAddress.length; i++) 73 | addressTo[i] = new InternetAddress(toAddress[i]); 74 | msg.setRecipients(Message.RecipientType.TO, addressTo); 75 | 76 | /* 77 | * InternetAddress[] toAddresses = { new InternetAddress(toAddress) }; 78 | * msg.setRecipients(Message.RecipientType.TO, toAddresses); 79 | */ msg.setSubject(subject); 80 | msg.setSentDate(new Date()); 81 | 82 | // creates message part 83 | MimeBodyPart messageBodyPart = new MimeBodyPart(); 84 | messageBodyPart.setContent(message, "text/html"); 85 | 86 | // creates multi-part 87 | Multipart multipart = new MimeMultipart(); 88 | multipart.addBodyPart(messageBodyPart); 89 | 90 | // adds attachments 91 | if (attachFiles != null && attachFiles.length > 0) { 92 | for (String filePath : attachFiles) { 93 | MimeBodyPart attachPart = new MimeBodyPart(); 94 | 95 | try { 96 | attachPart.attachFile(filePath); 97 | } catch (IOException ex) { 98 | ex.printStackTrace(); 99 | } 100 | 101 | multipart.addBodyPart(attachPart); 102 | } 103 | } 104 | 105 | // sets the multi-part as e-mail's content 106 | msg.setContent(multipart); 107 | 108 | // sends the e-mail 109 | Transport.send(msg); 110 | 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/java_Mail_API/EmailConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.java_Mail_API; 14 | 15 | import static awesomecucumber.constants.FrameworkConstants.PROJECT_NAME; 16 | 17 | /** 18 | * Data for Sending EMail after execution 19 | */ 20 | public class EmailConfig { 21 | 22 | public static final String SERVER = "smtp.gmail.com"; 23 | public static final String PORT = "587"; 24 | 25 | public static final String FROM = "*****@gmail.com"; 26 | public static final String PASSWORD = "******8"; 27 | 28 | /* "**********@gmail.com", */ 29 | public static final String[] TO = { "****@gmail.com" }; 30 | public static final String SUBJECT = PROJECT_NAME; 31 | } -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/pages/BasePage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.pages; 14 | 15 | import awesomecucumber.utils.ConfigLoader; 16 | import org.openqa.selenium.By; 17 | import org.openqa.selenium.JavascriptExecutor; 18 | import org.openqa.selenium.WebDriver; 19 | import org.openqa.selenium.WebElement; 20 | import org.openqa.selenium.support.PageFactory; 21 | import org.openqa.selenium.support.ui.ExpectedConditions; 22 | import org.openqa.selenium.support.ui.WebDriverWait; 23 | 24 | import static awesomecucumber.constants.FrameworkConstants.ATTRIBUTE_VALUE; 25 | import static awesomecucumber.constants.FrameworkConstants.EXPLICIT_WAIT; 26 | 27 | import java.time.Duration; 28 | import java.util.List; 29 | 30 | public class BasePage { 31 | protected WebDriver driver; 32 | protected WebDriverWait wait; 33 | 34 | public BasePage(WebDriver driver) { 35 | this.driver = driver; 36 | wait = new WebDriverWait(driver, Duration.ofSeconds(EXPLICIT_WAIT)); 37 | PageFactory.initElements(driver, this); 38 | } 39 | 40 | public void load(String endPoint) { 41 | driver.get(ConfigLoader.getInstance().getBaseUrl() + endPoint); 42 | } 43 | 44 | public void waitForOverlaysToDisappear(By overlay) { 45 | List overlays = driver.findElements(overlay); 46 | System.out.println("OVERLAY SIZE" + overlays.size()); 47 | if (overlays.size() > 0) { 48 | wait.until(ExpectedConditions.invisibilityOfAllElements(overlays)); 49 | System.out.println("OVERLAYS INVISIBLE"); 50 | } else { 51 | System.out.println("OVERLAY NOT FOUND"); 52 | } 53 | } 54 | 55 | public void clearAndSendKeys(WebElement element, String value) { 56 | element = waitForElementVisibility(element); 57 | element.clear(); 58 | element.sendKeys(value); 59 | } 60 | 61 | public void click(WebElement element) { 62 | waitForElementToBeClickable(element).click(); 63 | } 64 | 65 | public void click(By by) { 66 | waitForElementToBeClickable(by).click(); 67 | } 68 | 69 | public WebElement waitForElementVisibility(WebElement element) { 70 | return wait.until(ExpectedConditions.visibilityOf(element)); 71 | } 72 | 73 | public WebElement waitForElementToBeClickable(WebElement element) { 74 | return wait.until(ExpectedConditions.elementToBeClickable(element)); 75 | } 76 | 77 | public WebElement waitForElementToBeClickable(By by) { 78 | return wait.until(ExpectedConditions.elementToBeClickable(by)); 79 | } 80 | 81 | public void scrollToElement(WebElement element) { 82 | ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element); 83 | } 84 | 85 | public String getElementText(WebElement element) { 86 | return waitForElementVisibility(element).getText(); 87 | } 88 | 89 | public String getElementElementAttribute_Value(WebElement element) { 90 | return waitForElementVisibility(element).getAttribute(ATTRIBUTE_VALUE); 91 | } 92 | 93 | public String getElementElementCustomAttribute(WebElement element, String customAttribute) { 94 | return waitForElementVisibility(element).getAttribute(customAttribute); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/pages/CartPage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.pages; 14 | 15 | import org.openqa.selenium.WebDriver; 16 | import org.openqa.selenium.WebElement; 17 | import org.openqa.selenium.support.FindBy; 18 | 19 | public class CartPage extends BasePage { 20 | 21 | @FindBy(css = "td[class='product-name'] a") 22 | private WebElement productNameFld; 23 | 24 | @FindBy(css = "input[type=\"number\"]") 25 | private WebElement productQuantityFld; 26 | 27 | @FindBy(css = ".checkout-button") 28 | private WebElement proceedToCheckoutBtn; 29 | 30 | public CartPage(WebDriver driver) { 31 | super(driver); 32 | } 33 | 34 | public String getProductName() { 35 | return getElementText(productNameFld); 36 | } 37 | 38 | public int getProductQuantity() { 39 | return Integer.parseInt(getElementElementAttribute_Value(productQuantityFld)); 40 | } 41 | 42 | public void checkout() { 43 | click(proceedToCheckoutBtn); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/pages/CheckoutPage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.pages; 14 | 15 | import org.openqa.selenium.By; 16 | import org.openqa.selenium.WebDriver; 17 | import org.openqa.selenium.WebElement; 18 | import org.openqa.selenium.support.FindBy; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | 21 | import awesomecucumber.domainobjects.BillingDetails; 22 | 23 | public class CheckoutPage extends BasePage { 24 | 25 | @FindBy(id = "billing_first_name") 26 | private WebElement billingFirstnameFld; 27 | 28 | @FindBy(id = "billing_last_name") 29 | private WebElement billingLastNameFld; 30 | 31 | @FindBy(id = "billing_address_1") 32 | private WebElement billingAddressOneFld; 33 | 34 | @FindBy(id = "billing_city") 35 | private WebElement billingCityFld; 36 | 37 | @FindBy(id = "billing_state") 38 | private WebElement billingStateDropDown; 39 | 40 | @FindBy(id = "select2-billing_state-container") 41 | private WebElement alternateBillingStateDropDown; 42 | 43 | @FindBy(id = "billing_postcode") 44 | private WebElement billingZipFld; 45 | 46 | @FindBy(id = "billing_email") 47 | private WebElement billingEmailFld; 48 | 49 | @FindBy(id = "place_order") 50 | private WebElement placeOrderBtn; 51 | 52 | @FindBy(css = ".woocommerce-notice") 53 | private WebElement noticeTxt; 54 | 55 | private final By overlay = By.cssSelector(".blockUI.blockOverlay"); 56 | 57 | public CheckoutPage(WebDriver driver) { 58 | super(driver); 59 | } 60 | 61 | public CheckoutPage enterBillingFirstName(String billingFirstName) { 62 | clearAndSendKeys(billingFirstnameFld, billingFirstName); 63 | return this; 64 | } 65 | 66 | public CheckoutPage enterBillingLastName(String billingLastName) { 67 | clearAndSendKeys(billingLastNameFld, billingLastName); 68 | return this; 69 | } 70 | 71 | public CheckoutPage enterBillingAddressLineOne(String billingAddressLineOne) { 72 | clearAndSendKeys(billingAddressOneFld, billingAddressLineOne); 73 | 74 | return this; 75 | } 76 | 77 | public CheckoutPage enterBillingCity(String billingCity) { 78 | clearAndSendKeys(billingCityFld, billingCity); 79 | return this; 80 | } 81 | 82 | public CheckoutPage selectBillingState(String billingStateName) { 83 | 84 | /** 85 | * We have commented the code using Select class becauase that does not work 86 | * with Firefox browser. 87 | * 88 | * There is a issue open for it. 89 | * 90 | */ 91 | click(alternateBillingStateDropDown); 92 | // wait.until(ExpectedConditions.elementToBeClickable(alternateBillingStateDropDown)).click(); 93 | WebElement element = wait 94 | .until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()='" + billingStateName + "']"))); 95 | 96 | scrollToElement(element); 97 | click(element); 98 | 99 | /* 100 | * Select select = new 101 | * Select(wait.until(ExpectedConditions.visibilityOf(billingStateDropDown))); 102 | * select.selectByVisibleText(billingStateName); 103 | */ 104 | return this; 105 | } 106 | 107 | public CheckoutPage enterBillingZip(String billingZip) { 108 | clearAndSendKeys(billingZipFld, billingZip); 109 | return this; 110 | } 111 | 112 | public CheckoutPage enterBillingEmail(String billingEmail) { 113 | clearAndSendKeys(billingEmailFld, billingEmail); 114 | return this; 115 | } 116 | 117 | public CheckoutPage setBillingDetails(BillingDetails billingDetails) { 118 | return enterBillingFirstName(billingDetails.getBillingFirstName()) 119 | .enterBillingLastName(billingDetails.getBillingLastName()) 120 | .enterBillingAddressLineOne(billingDetails.getBillingAddressOne()) 121 | .enterBillingCity(billingDetails.getBillingCity()) 122 | .selectBillingState(billingDetails.getBillingStateName()) 123 | .enterBillingZip(billingDetails.getBillingZip()) 124 | .enterBillingEmail(billingDetails.getBillingEmail()); 125 | } 126 | 127 | public CheckoutPage placeOrder() { 128 | waitForOverlaysToDisappear(overlay); 129 | click(placeOrderBtn); 130 | return this; 131 | } 132 | 133 | public String getNotice() { 134 | return getElementText(noticeTxt); 135 | 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/pages/ProductPage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.pages; 14 | 15 | import org.openqa.selenium.Keys; 16 | import org.openqa.selenium.WebDriver; 17 | import org.openqa.selenium.WebElement; 18 | import org.openqa.selenium.support.FindBy; 19 | 20 | public class ProductPage extends BasePage { 21 | 22 | @FindBy(css = "input[type='number']") 23 | private WebElement quantityInputFld; 24 | 25 | @FindBy(css = "button[type='submit']") 26 | private WebElement addToCartBtn; 27 | 28 | @FindBy(css = "[role='alert'] .button") 29 | private WebElement viewCartBtn; 30 | 31 | @FindBy(css = "div[role='alert']") 32 | private WebElement bannerTxt; 33 | 34 | public ProductPage(WebDriver driver) { 35 | super(driver); 36 | } 37 | 38 | public void enterQuantity(int quantity) { 39 | clearAndSendKeys(quantityInputFld, Integer.toString(quantity)); 40 | } 41 | 42 | public int getQuantity() { 43 | return Integer.parseInt(getElementElementAttribute_Value(quantityInputFld)); 44 | } 45 | 46 | public void addToCart() { 47 | click(addToCartBtn); 48 | click(viewCartBtn); 49 | } 50 | 51 | public void pressAddToCartBtn() { 52 | click(addToCartBtn); 53 | } 54 | 55 | public String getValidationMsg() { 56 | return getElementElementCustomAttribute(quantityInputFld, "validationMessage"); 57 | } 58 | 59 | public String getBannerTxt() { 60 | return getElementText(bannerTxt); 61 | } 62 | 63 | public int updateQuantityUsingArrows(String direction) { 64 | switch (direction) { 65 | case "up": { 66 | waitForElementToBeClickable(quantityInputFld).sendKeys(Keys.ARROW_UP); 67 | break; 68 | } 69 | case "down": { 70 | waitForElementToBeClickable(quantityInputFld).sendKeys(Keys.ARROW_DOWN); 71 | break; 72 | } 73 | default: 74 | throw new IllegalStateException("INVALID ARROW DIRECTION" + direction); 75 | } 76 | System.out.println("QUANTITY: " + getQuantity()); 77 | return getQuantity(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/pages/StorePage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.pages; 14 | 15 | import java.nio.charset.StandardCharsets; 16 | import java.util.List; 17 | 18 | import org.openqa.selenium.By; 19 | import org.openqa.selenium.WebDriver; 20 | import org.openqa.selenium.WebElement; 21 | import org.openqa.selenium.support.FindBy; 22 | 23 | public class StorePage extends BasePage { 24 | 25 | @FindBy(css = "a[title='View cart']") 26 | private WebElement viewCartLink; 27 | 28 | @FindBy(xpath = "//h1[normalize-space()='Store']") 29 | private WebElement titleTxt; 30 | 31 | @FindBy(xpath = "//img") 32 | private List images; 33 | 34 | public StorePage(WebDriver driver) { 35 | super(driver); 36 | } 37 | 38 | public void addToCart(String productName) { 39 | String raw = "a[aria-label='Add “" + productName + "” to your cart']"; 40 | byte[] bytes = raw.getBytes(StandardCharsets.UTF_8); 41 | String utf8Encoded = new String(bytes, StandardCharsets.UTF_8); 42 | By addToCartBtn = By.cssSelector(utf8Encoded); 43 | waitForElementVisibility(titleTxt); 44 | click(addToCartBtn); 45 | click(viewCartLink); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/runners/MyJUnitRunnerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | /* 14 | package awesomecucumber.runners; 15 | 16 | import io.cucumber.junit.Cucumber; 17 | import io.cucumber.junit.CucumberOptions; 18 | import org.junit.runner.RunWith; 19 | 20 | @RunWith(Cucumber.class) 21 | @CucumberOptions( 22 | glue = {"awesomecucumber"}, 23 | features = "src/test/resources/features" 24 | ) 25 | public class MyJUnitRunnerTest { 26 | } 27 | */ 28 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/runners/MyTestNGRunnerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.runners; 14 | 15 | import io.cucumber.testng.AbstractTestNGCucumberTests; 16 | import io.cucumber.testng.CucumberOptions; 17 | import org.testng.annotations.DataProvider; 18 | 19 | @CucumberOptions( 20 | plugin = { 21 | "html:target/cucumber/cucumber.html" , 22 | "me.jvt.cucumber.report.PrettyReports:target/cucumber/" 23 | }, 24 | glue = { "awesomecucumber" }, 25 | // glue = {"awesomecucumber.stepdefinitions","awesomecucumber.hooks"}, 26 | features = "src/test/resources/features", 27 | tags = "@smoke") 28 | //tags = "@regression") 29 | //tags = "@demo") 30 | public class MyTestNGRunnerTest extends AbstractTestNGCucumberTests { 31 | 32 | /** 33 | * https://cucumber.io/docs/guides/parallel-execution/#testng 34 | * 35 | * Cucumber can be executed in parallel using TestNG and Maven test execution 36 | * plugins by setting the dataprovider parallel option to true. 37 | * 38 | * In TestNG the scenarios and rows in a scenario outline are executed in 39 | * multiple threads. One can use either Maven Surefire or Failsafe plugin for 40 | * executing the runners. 41 | **/ 42 | 43 | @Override 44 | @DataProvider(parallel = true) 45 | public Object[][] scenarios() { 46 | return super.scenarios(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/CartStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import org.testng.Assert; 16 | 17 | import awesomecucumber.apis.CartApi; 18 | import awesomecucumber.context.TestContext; 19 | import awesomecucumber.domainobjects.Product; 20 | import awesomecucumber.factory.PageFactoryManager; 21 | import awesomecucumber.pages.CartPage; 22 | import io.cucumber.java.en.And; 23 | import io.cucumber.java.en.Then; 24 | 25 | public class CartStepDefinitions { 26 | private final CartPage cartPage; 27 | private final TestContext context; 28 | 29 | public CartStepDefinitions(TestContext context) { 30 | this.context = context; 31 | cartPage = PageFactoryManager.getCartPage(context.driver); 32 | } 33 | 34 | @Then("I should see {int} {product} in the cart") 35 | public void iShouldSeeInTheCart(int quantity, Product product) { 36 | Assert.assertEquals(product.getName(), cartPage.getProductName()); 37 | Assert.assertEquals(quantity, cartPage.getProductQuantity()); 38 | } 39 | 40 | @And("I have {int} {product} in the cart") 41 | public void iHaveInTheCart(int quantity, Product product) throws Exception { 42 | // storePage.addToCart("Blue Shoes"); 43 | // CartApi cartApi = new CartApi(context.cookies.get()); 44 | CartApi cartApi = new CartApi(context.cookies.getCookies()); 45 | product = context.productList.getProductByName(product.getName()); 46 | cartApi.addToCart(product.getId(), quantity); 47 | // context.cookies.set(cartApi.getCookies()); 48 | context.cookies.setCookies(cartApi.getCookies()); 49 | context.cookies.injectCookiesToBrowser(context.driver); 50 | context.product = product; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/CheckoutStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import org.testng.Assert; 16 | 17 | import awesomecucumber.context.TestContext; 18 | import awesomecucumber.enums.EndPoint; 19 | import awesomecucumber.factory.PageFactoryManager; 20 | import awesomecucumber.pages.CheckoutPage; 21 | import io.cucumber.java.en.And; 22 | import io.cucumber.java.en.Then; 23 | import io.cucumber.java.en.When; 24 | 25 | public class CheckoutStepDefinitions { 26 | private final TestContext context; 27 | private final CheckoutPage checkoutPage; 28 | 29 | public CheckoutStepDefinitions(TestContext context){ 30 | this.context = context; 31 | checkoutPage = PageFactoryManager.getCheckoutPage(context.driver); 32 | } 33 | 34 | @When("I provide billing details") 35 | public void iProvideBillingDetails() { 36 | /* 37 | * context.billingDetails -> We are using the same billing details set in 38 | * CustomerStepDefinitions (Method: myBillingDetailsAre()) 39 | */ 40 | checkoutPage.setBillingDetails(context.billingDetails); 41 | } 42 | 43 | @And("I place an order") 44 | public void iPlaceAnOrder() { 45 | checkoutPage.placeOrder(); 46 | } 47 | 48 | @Then("the order should be placed successfully") 49 | public void theOrderShouldBePlacedSuccessfully() { 50 | Assert.assertEquals("Thank you. Your order has been received.", checkoutPage.getNotice()); 51 | } 52 | 53 | @And("I'm on the Checkout page") 54 | public void iMOnTheCheckoutPage() { 55 | checkoutPage.load(EndPoint.CHECKOUT.url); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/CustomerStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import awesomecucumber.context.TestContext; 16 | import awesomecucumber.domainobjects.BillingDetails; 17 | import awesomecucumber.enums.EndPoint; 18 | import awesomecucumber.factory.PageFactoryManager; 19 | import awesomecucumber.pages.StorePage; 20 | import io.cucumber.java.en.And; 21 | import io.cucumber.java.en.Given; 22 | 23 | public class CustomerStepDefinitions { 24 | private final TestContext context; 25 | private final StorePage storePage; 26 | 27 | public CustomerStepDefinitions(TestContext context) { 28 | this.context = context; 29 | storePage = PageFactoryManager.getStorePage(context.driver); 30 | } 31 | 32 | @And("my billing details are") 33 | public void myBillingDetailsAre(BillingDetails billingDetails) { 34 | context.billingDetails = billingDetails; 35 | } 36 | 37 | @Given("I'm a guest customer") 38 | public void iMAGuestCustomer() { 39 | // storePage.load(FrameworkConstants.STORE); 40 | storePage.load(EndPoint.STORE.url); 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/MyStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import org.openqa.selenium.WebDriver; 16 | 17 | import awesomecucumber.context.TestContext; 18 | import awesomecucumber.domainobjects.BillingDetails; 19 | 20 | public class MyStepDefinitions { 21 | private final WebDriver driver; 22 | private BillingDetails billingDetails; 23 | 24 | public MyStepDefinitions(TestContext context){ 25 | driver = context.driver; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/ProductStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import org.testng.Assert; 16 | 17 | import awesomecucumber.context.TestContext; 18 | import awesomecucumber.domainobjects.Product; 19 | import awesomecucumber.factory.PageFactoryManager; 20 | import awesomecucumber.pages.ProductPage; 21 | import io.cucumber.java.en.And; 22 | import io.cucumber.java.en.Given; 23 | import io.cucumber.java.en.Then; 24 | import io.cucumber.java.en.When; 25 | 26 | public class ProductStepDefinitions { 27 | private final ProductPage productPage; 28 | private final TestContext context; 29 | 30 | public ProductStepDefinitions(TestContext context) { 31 | this.context = context; 32 | productPage = PageFactoryManager.getProductPage(context.driver); 33 | } 34 | 35 | @Given("I'm browsing {product}") 36 | public void iAmBrowsing(Product product) { 37 | productPage.load("/product/" + product.getName().replaceAll("\\s", "-") + "/"); 38 | context.product = product; 39 | } 40 | 41 | @When("I add {int} quantity to the cart") 42 | public void iAddToTheCart(int quantity) { 43 | productPage.enterQuantity(quantity); 44 | productPage.addToCart(); 45 | } 46 | 47 | @When("I add {int} quantity") 48 | public void iSelectQuantity(int quantity) { 49 | productPage.enterQuantity(quantity); 50 | productPage.pressAddToCartBtn(); 51 | context.product = new Product(); 52 | context.product.setQuantity(quantity); 53 | } 54 | 55 | @Then("I should see an error") 56 | public void iShouldSeeAnError() { 57 | Assert.assertEquals(productPage.getValidationMsg(), "Value must be greater than or equal to 1."); 58 | Assert.fail("Failing this step intentionally to check the screenshot attached int the Report"); 59 | } 60 | 61 | @And("the selected quantity is {int}") 62 | public void theSelectedQuantityIs(int currentQuantity) { 63 | productPage.enterQuantity(currentQuantity); 64 | } 65 | 66 | @When("I use {word} arrow to change the quantity") 67 | public void iUseDirectionArrowToChangeTheQuantity(String direction) { 68 | context.product = new Product(); 69 | context.product.setQuantity(productPage.updateQuantityUsingArrows(direction)); 70 | } 71 | 72 | @Then("the selected quantity changes to {int}") 73 | public void theSelectedQuantityChangesToNewQuantity(int newQuantity) { 74 | Assert.assertEquals(context.product.getQuantity(), newQuantity); 75 | } 76 | 77 | @Then("I should see the banner with text {string}") 78 | public void iShouldSeeTheBannerWithTxt(String text) { 79 | Assert.assertTrue(productPage.getBannerTxt().contains(text), 80 | "Expected: " + text + ", ACTUAL: " + productPage.getBannerTxt()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/stepdefinitions/StoreStepDefinitions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.stepdefinitions; 14 | 15 | import awesomecucumber.context.TestContext; 16 | import awesomecucumber.domainobjects.Product; 17 | import awesomecucumber.enums.EndPoint; 18 | import awesomecucumber.factory.PageFactoryManager; 19 | import awesomecucumber.pages.StorePage; 20 | import io.cucumber.java.en.Given; 21 | import io.cucumber.java.en.When; 22 | 23 | public class StoreStepDefinitions { 24 | private final StorePage storePage; 25 | private final TestContext context; 26 | 27 | public StoreStepDefinitions(TestContext context){ 28 | this.context = context; 29 | storePage = PageFactoryManager.getStorePage(context.driver); 30 | } 31 | 32 | @Given("I'm on the Store Page") 33 | public void iMOnTheStorePage() { 34 | storePage.load(EndPoint.STORE.url); 35 | } 36 | 37 | @When("I add it again") 38 | public void iAddItAgain() { 39 | storePage.addToCart(context.product.getName()); 40 | } 41 | 42 | @When("I add a {product} to the cart") 43 | public void iAddAToTheCart(Product product) { 44 | storePage.addToCart(product.getName()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/ConfigLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import static awesomecucumber.constants.FrameworkConstants.DIRECTORY_ENV_CONFIG; 16 | import static awesomecucumber.constants.FrameworkConstants.ENV_CONFIG_INT; 17 | import static awesomecucumber.constants.FrameworkConstants.ENV_CONFIG_PROD; 18 | import static awesomecucumber.constants.FrameworkConstants.ENV_CONFIG_QA; 19 | import static awesomecucumber.constants.FrameworkConstants.ENV_CONFIG_STG; 20 | import static awesomecucumber.constants.FrameworkConstants.PARAMETER_ENV; 21 | 22 | import java.util.Properties; 23 | 24 | import awesomecucumber.enums.EnvType; 25 | 26 | /** 27 | * Singleton Design Pattern is implemented here 28 | */ 29 | public class ConfigLoader { 30 | 31 | private static final String BASE_URL = "baseUrl"; 32 | private static final String SEND_EMAIL_TO_USERS = "send_email_to_users"; 33 | 34 | 35 | // private final Properties properties; 36 | private Properties properties; 37 | 38 | private static ConfigLoader configLoader; 39 | 40 | private ConfigLoader() { 41 | 42 | /** 43 | * Setting the Environment Parameter here. 44 | * 45 | * By default, Stage will be taken 46 | */ 47 | // PARAMETER_ENV = "env"; 48 | String env = System.getProperty(PARAMETER_ENV, String.valueOf(EnvType.STG)); 49 | 50 | switch (EnvType.valueOf(env)) { 51 | 52 | case QA: { 53 | properties = PropertyUtils.propertyLoader(DIRECTORY_ENV_CONFIG + ENV_CONFIG_QA); 54 | break; 55 | } 56 | case INT: { 57 | properties = PropertyUtils.propertyLoader(DIRECTORY_ENV_CONFIG + ENV_CONFIG_INT); 58 | break; 59 | } 60 | case STG: { 61 | properties = PropertyUtils.propertyLoader(DIRECTORY_ENV_CONFIG + ENV_CONFIG_STG); 62 | break; 63 | } 64 | case PROD: { 65 | properties = PropertyUtils.propertyLoader(DIRECTORY_ENV_CONFIG + ENV_CONFIG_PROD); 66 | break; 67 | } 68 | default: 69 | throw new IllegalStateException("INVALID ENV: " + env); 70 | } 71 | } 72 | 73 | public static ConfigLoader getInstance() { 74 | if (configLoader == null) { 75 | configLoader = new ConfigLoader(); 76 | } 77 | return configLoader; 78 | } 79 | 80 | public String getBaseUrl() { 81 | return getPropertyValue(BASE_URL); 82 | } 83 | 84 | public String getSendEmailToUsers() { 85 | return getPropertyValue(SEND_EMAIL_TO_USERS); 86 | } 87 | 88 | private String getPropertyValue(String propertyKey) { 89 | String prop = properties.getProperty(propertyKey); 90 | if (prop != null) { 91 | return prop.trim(); 92 | } else { 93 | throw new RuntimeException("Property " + propertyKey + " is not specified in the config.properties file"); 94 | } 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/CookieUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import io.restassured.http.Cookies; 16 | import org.openqa.selenium.Cookie; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | public class CookieUtils { 22 | 23 | /*Convert RestAssured Cookies -> Selenium Cookies*/ 24 | public List convertRestAssuredCookiesToSeleniumCookies(Cookies cookies) { 25 | 26 | List restAssuredCookies; 27 | restAssuredCookies = cookies.asList(); 28 | 29 | List seleniumCookies = new ArrayList<>(); 30 | 31 | for (io.restassured.http.Cookie restAssuredCookie : restAssuredCookies) { 32 | seleniumCookies.add( 33 | new Cookie(restAssuredCookie.getName(), 34 | restAssuredCookie.getValue(), 35 | restAssuredCookie.getDomain(), 36 | restAssuredCookie.getPath(), 37 | restAssuredCookie.getExpiryDate(), 38 | restAssuredCookie.isSecured(), 39 | restAssuredCookie.isHttpOnly(), 40 | /*Present in Selenium 4.x*/ 41 | restAssuredCookie.getSameSite())); 42 | } 43 | return seleniumCookies; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/EmailSendUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import static awesomecucumber.constants.FrameworkConstants.PROJECT_NAME; 16 | import static awesomecucumber.constants.FrameworkConstants.REPORTS_CUCUMBER_LOCAL; 17 | import static awesomecucumber.constants.FrameworkConstants.YES; 18 | import static awesomecucumber.java_Mail_API.EmailConfig.FROM; 19 | import static awesomecucumber.java_Mail_API.EmailConfig.PASSWORD; 20 | import static awesomecucumber.java_Mail_API.EmailConfig.PORT; 21 | import static awesomecucumber.java_Mail_API.EmailConfig.SERVER; 22 | import static awesomecucumber.java_Mail_API.EmailConfig.SUBJECT; 23 | import static awesomecucumber.java_Mail_API.EmailConfig.TO; 24 | 25 | import javax.mail.MessagingException; 26 | 27 | import awesomecucumber.java_Mail_API.EmailAttachmentsSender; 28 | 29 | public class EmailSendUtils { 30 | 31 | /** 32 | * sendEmail_WithAttachmentsAndFormattedBodyText_ToManyUsersRajat 33 | */ 34 | public static void sendEmail() { 35 | System.out.println("****************************************"); 36 | System.out.println("Email send - START"); 37 | System.out.println("****************************************"); 38 | 39 | if (ConfigLoader.getInstance().getSendEmailToUsers().equalsIgnoreCase(YES)) { 40 | System.out.println("File name: " + REPORTS_CUCUMBER_LOCAL); 41 | 42 | String messageBody = getTestCasesCountInFormat(); 43 | System.out.println(messageBody); 44 | 45 | try { 46 | EmailAttachmentsSender.sendEmailWithAttachments(SERVER, PORT, FROM, PASSWORD, TO, SUBJECT, messageBody, 47 | REPORTS_CUCUMBER_LOCAL); 48 | 49 | System.out.println("****************************************"); 50 | System.out.println("Email sent successfully."); 51 | System.out.println("****************************************"); 52 | } catch (MessagingException e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | } 57 | 58 | } 59 | 60 | private static String getTestCasesCountInFormat() { 61 | 62 | return "\r\n" + "\r\n" + " \r\n" + "\r\n" 63 | + " \r\n\r\n\r\n\r\n" + " \r\n" 73 | + " \r\n" 77 | + " \r\n" 81 | + " \r\n" + " \r\n" + " \r\n" 82 | + "

" 64 | + PROJECT_NAME + "

\r\n\r\n" 65 | + " \r\n" 66 | + " \r\n" + " \r\n" + " \r\n" 68 | + "
" 67 | + "
Total
\r\n" + "
\r\n" 69 | + " \r\n" + " \r\n" 70 | + " \r\n" + " \r\n" 72 | + " \r\n" + "
" 71 | + "
Passed
\r\n" + "
\r\n" + " \r\n" 74 | + " \r\n" + " \r\n" 76 | + " \r\n" + "
" 75 | + "
Failed
\r\n" + " \r\n" + "
\r\n" + " \r\n" 78 | + " \r\n" + " \r\n" 80 | + " \r\n" + "
" 79 | + "
Skipped
\r\n" + " \r\n" + "
\r\n" + " \r\n" + " \r\n" + ""; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/JacksonUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; 19 | 20 | public class JacksonUtils { 21 | 22 | public static T deserializeJson(String fileName, Class T) throws IOException { 23 | InputStream is = JacksonUtils.class.getClassLoader().getResourceAsStream(fileName); 24 | ObjectMapper objectMapper = new ObjectMapper(); 25 | return objectMapper.readValue(is, T); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/PropertyUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import java.io.BufferedReader; 16 | import java.io.FileNotFoundException; 17 | import java.io.FileReader; 18 | import java.io.IOException; 19 | import java.util.Properties; 20 | 21 | public class PropertyUtils { 22 | 23 | public static Properties propertyLoader(String filePath) { 24 | Properties properties = new Properties(); 25 | BufferedReader reader; 26 | try { 27 | reader = new BufferedReader(new FileReader(filePath)); 28 | try { 29 | properties.load(reader); 30 | reader.close(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | throw new RuntimeException("failed to load properties file " + filePath); 34 | } 35 | } catch (FileNotFoundException e) { 36 | e.printStackTrace(); 37 | throw new RuntimeException("properties file not found at " + filePath); 38 | } 39 | return properties; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/awesomecucumber/utils/ZipUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Rajat Verma 3 | * https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | * https://github.com/rajatt95 5 | * https://rajatt95.github.io/ 6 | * 7 | * Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | * Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | */ 10 | 11 | /***************************************************/ 12 | 13 | package awesomecucumber.utils; 14 | 15 | import java.io.File; 16 | import static awesomecucumber.constants.FrameworkConstants.REPORTS_CUCUMBER_LOCATION; 17 | import static awesomecucumber.constants.FrameworkConstants.REPORTS_ZIPPED_FILE_NAME; 18 | import org.zeroturnaround.zip.ZipUtil; 19 | 20 | public class ZipUtils { 21 | 22 | /* 23 | * make Zip file of target/cucumber folder in Project Root folder (Name: 24 | * CucumberReports.zip) 25 | */ 26 | public static void zip() { 27 | 28 | ZipUtil.pack(new File(REPORTS_CUCUMBER_LOCATION), new File(REPORTS_ZIPPED_FILE_NAME)); 29 | 30 | System.out.println("Zipped Cucumber reports successfuly"); 31 | } 32 | 33 | // public static void main(String[] args) { 34 | // 35 | // String reportsLocation = "./target/cucumber/"; 36 | // ZipUtil.pack(new File(reportsLocation), new File("CucumberReports.zip")); 37 | // 38 | // } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/config/int_config.properties: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | 13 | baseUrl=https://int.askomdch.com -------------------------------------------------------------------------------- /src/test/resources/config/prod_config.properties: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | baseUrl=https://prod.askomdch.com -------------------------------------------------------------------------------- /src/test/resources/config/qa_config.properties: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | baseUrl=https://qa.askomdch.com -------------------------------------------------------------------------------- /src/test/resources/config/stg_config.properties: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | baseUrl=https://askomdch.com 14 | 15 | #send_email_to_users --> yes or no 16 | #If yes -> then, provide your mail credentials -> src/main/java -> package org.selenium.java_Mail_API.EmailConfig; 17 | #This Email will be sent using Java mail API 18 | send_email_to_users=no 19 | -------------------------------------------------------------------------------- /src/test/resources/cucumber.properties: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | #To publish the reports in Cloud 14 | #This report self-destructs in 24 hrs. 15 | cucumber.publish.enabled=true 16 | cucumber.publish.quiet=true 17 | -------------------------------------------------------------------------------- /src/test/resources/features/add_to_cart.feature: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | @regression 14 | Feature: Add to cart 15 | 16 | As a customer of AskOmDch app, 17 | I should be able to add product(s) to the cart, 18 | So that I can purchase them 19 | 20 | Rule: Add from Store 21 | 22 | @smoke @demo 23 | Scenario Outline: Add one quantity from Store 24 | Given I'm on the Store Page 25 | When I add a "" to the cart 26 | Then I should see 1 "" in the cart 27 | Examples: 28 | | product_name | 29 | | Blue Shoes | 30 | | Anchor Bracelet | 31 | 32 | Scenario: Add the product already in the cart 33 | Given I'm on the Store Page 34 | And I have 1 "Blue Shoes" in the cart 35 | When I add it again 36 | Then I should see 2 "Blue Shoes" in the cart 37 | 38 | Rule: Add from Product page 39 | 40 | @bvt @sanity 41 | Scenario Outline: Add the product to the cart 42 | Given I'm browsing "" 43 | When I add quantity to the cart 44 | Then I should see "" in the cart 45 | Examples: 46 | | product_name | quantity | 47 | | Blue Shoes | 1 | 48 | | Anchor Bracelet | 2 | 49 | 50 | @bvt 51 | Scenario: Add the product already in the cart 52 | Given I'm browsing "Blue Shoes" 53 | And I have 1 "Blue Shoes" in the cart 54 | When I add 1 quantity to the cart 55 | Then I should see 2 "Blue Shoes" in the cart 56 | 57 | @smoke 58 | Scenario: Show an error when try to add zero quantity 59 | Given I'm browsing "Blue Shoes" 60 | When I add 0 quantity 61 | Then I should see an error 62 | 63 | @sanity 64 | Scenario Outline: Change the product quantity using arrows 65 | Given I'm browsing "Blue Shoes" 66 | And the selected quantity is 67 | When I use arrow to change the quantity 68 | Then the selected quantity changes to 69 | Examples: 70 | | direction | currentQuantity | newQuantity | 71 | | up | 1 | 2 | 72 | | down | 2 | 1 | 73 | | down | 1 | 1 | 74 | 75 | @sanity 76 | Scenario: Show a Banner when I add to cart 77 | Given I'm browsing "Blue Shoes" 78 | When I add 1 quantity 79 | Then I should see the banner with text "“Blue Shoes” has been added to your cart." 80 | -------------------------------------------------------------------------------- /src/test/resources/features/guest_place_an_order.feature: -------------------------------------------------------------------------------- 1 | #/** 2 | #* @author Rajat Verma 3 | #* https://www.linkedin.com/in/rajat-v-3b0685128/ 4 | #* https://github.com/rajatt95 5 | #* https://rajatt95.github.io/ 6 | #* 7 | #* Course: Cucumber BDD Masterclass with Selenium 4 & Java + Framework (https://www.udemy.com/course/cucumber-bdd-masterclass/) 8 | #* Tutor: Omprakash Chavan (https://www.udemy.com/user/omprakash-chavan/) 9 | #*/ 10 | # 11 | #/***************************************************/ 12 | # 13 | @regression 14 | Feature: Place an order 15 | 16 | @sanity @bvt 17 | Scenario: using default payment option 18 | Given I'm a guest customer 19 | And my billing details are 20 | | firstname | lastname | country | address_line1 | city | state | zip | email | 21 | | demo | user | United States (US) | 6300 Spring Creek | Plano | Texas | 75024 | askomdch@gmail.com | 22 | And I have 1 "Blue Shoes" in the cart 23 | And I'm on the Checkout page 24 | When I provide billing details 25 | And I place an order 26 | Then the order should be placed successfully -------------------------------------------------------------------------------- /src/test/resources/products.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1215, 4 | "name": "Blue Shoes" 5 | } 6 | ] --------------------------------------------------------------------------------