├── .gitignore ├── src └── main │ ├── resources │ ├── testData │ │ ├── DataSheet.xlsx │ │ └── DataSheet_client2.xlsx │ └── features │ │ └── LoginToApplication.feature │ └── java │ └── automationPractice │ ├── runner │ └── Run.java │ ├── utilities │ ├── CommonMethods.java │ ├── PageObjects.java │ ├── Driver.java │ ├── ExcelUtil.java │ └── ConfigurationReader.java │ ├── step_definitions │ ├── DataSteps.java │ ├── AssertionSteps.java │ ├── NavigationSteps.java │ ├── Hooks.java │ └── InputSteps.java │ └── pages │ ├── Login.java │ ├── Dashboard.java │ ├── BasePage.java │ └── ContactPage.java ├── Configurations.properties └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ 3 | *.iml -------------------------------------------------------------------------------- /src/main/resources/testData/DataSheet.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skarlet03/office_hour_cucumber_project/HEAD/src/main/resources/testData/DataSheet.xlsx -------------------------------------------------------------------------------- /src/main/resources/testData/DataSheet_client2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skarlet03/office_hour_cucumber_project/HEAD/src/main/resources/testData/DataSheet_client2.xlsx -------------------------------------------------------------------------------- /Configurations.properties: -------------------------------------------------------------------------------- 1 | browser=chrome 2 | vytrack_url=http://qa3.vytrack.com 3 | manager-username=salesmanager110 4 | manager-password=UserUser123 5 | vytrackdata1=/src/main/resources/testData/DataSheet.xlsx 6 | vytrackdata2=/src/main/resources/testData/DataSheet_client2.xlsx -------------------------------------------------------------------------------- /src/main/java/automationPractice/runner/Run.java: -------------------------------------------------------------------------------- 1 | package automationPractice.runner; 2 | 3 | import io.cucumber.junit.Cucumber; 4 | import io.cucumber.junit.CucumberOptions; 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(Cucumber.class) 8 | @CucumberOptions( 9 | features = "src/main/resources/features", 10 | glue = "automationPractice/step_definitions", 11 | dryRun = false, 12 | tags = "@TC004" 13 | ) 14 | 15 | public class Run { 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/utilities/CommonMethods.java: -------------------------------------------------------------------------------- 1 | package automationPractice.utilities; 2 | 3 | import java.util.Map; 4 | 5 | public interface CommonMethods { 6 | 7 | public default void clickButton(String button){} 8 | 9 | public default void enterValue(String field, String value){} 10 | 11 | public default void validateResult (String object, String expected){} 12 | 13 | public default void selectValue (String listName, String value){} 14 | 15 | public default void enterValue(Map datamap){} 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/step_definitions/DataSteps.java: -------------------------------------------------------------------------------- 1 | package automationPractice.step_definitions; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.utilities.PageObjects; 5 | import io.cucumber.java.en.Given; 6 | 7 | public class DataSteps { 8 | 9 | @Given("User gets the test data from {string} excel {string} sheet {string} row") 10 | public void user_gets_the_test_data_from_excel_sheet_row(String docName, String sheetName, String rowNum) { 11 | BasePage basePage = PageObjects.getPageObject("Base"); 12 | basePage.getData(docName, sheetName, rowNum); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/step_definitions/AssertionSteps.java: -------------------------------------------------------------------------------- 1 | package automationPractice.step_definitions; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.utilities.PageObjects; 5 | import io.cucumber.java.en.Then; 6 | 7 | public class AssertionSteps { 8 | 9 | @Then("{string} should be {string} on {string} page") 10 | public void should_be_on_page(String object, String expected, String pagename) { 11 | BasePage basePage = PageObjects.getPageObject(pagename); 12 | // BasePage basePage = new Dashboard(); 13 | basePage.validateResult(object, expected); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/utilities/PageObjects.java: -------------------------------------------------------------------------------- 1 | package automationPractice.utilities; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.pages.ContactPage; 5 | import automationPractice.pages.Dashboard; 6 | import automationPractice.pages.Login; 7 | import org.junit.Assert; 8 | 9 | public class PageObjects { 10 | 11 | private PageObjects(){} 12 | 13 | public static BasePage getPageObject(String pageName){ 14 | pageName = pageName.toUpperCase(); 15 | switch (pageName){ 16 | case "LOGIN": 17 | return new Login(); 18 | case "DASHBOARD": 19 | return new Dashboard(); 20 | case "CONTACT": 21 | return new ContactPage(); 22 | case "BASE": 23 | return new BasePage(); 24 | default: 25 | Assert.fail("Page is not declared"); 26 | } 27 | return new BasePage(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/step_definitions/NavigationSteps.java: -------------------------------------------------------------------------------- 1 | package automationPractice.step_definitions; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.pages.Login; 5 | import automationPractice.utilities.ConfigurationReader; 6 | import automationPractice.utilities.Driver; 7 | import automationPractice.utilities.PageObjects; 8 | import io.cucumber.java.en.Given; 9 | import io.cucumber.java.en.When; 10 | import org.junit.Assert; 11 | 12 | public class NavigationSteps { 13 | 14 | @Given("User on {string} page for {string} application") 15 | public void user_on_page_for_application(String pageName, String appName) { 16 | appName = appName.toUpperCase(); 17 | switch (appName){ 18 | case "VYTRACK": 19 | Driver.get().get(ConfigurationReader.get("vytrack_url")); 20 | break; 21 | default: 22 | Assert.fail("Application name " + appName + " not defined."); 23 | } 24 | 25 | } 26 | 27 | @When("User clicks on {string} button on {string} page") 28 | public void user_clicks_on_button_on_page(String buttonName, String pageName) { 29 | // Login , Login 30 | BasePage page = PageObjects.getPageObject(pageName); 31 | //BasePage page = new Login(); 32 | page.clickButton(buttonName); // clickButton executed from Login class 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/step_definitions/Hooks.java: -------------------------------------------------------------------------------- 1 | package automationPractice.step_definitions; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.utilities.Driver; 5 | import io.cucumber.java.After; 6 | import io.cucumber.java.Before; 7 | import org.openqa.selenium.support.ui.WebDriverWait; 8 | 9 | import java.util.concurrent.TimeUnit; 10 | 11 | public class Hooks { 12 | 13 | 14 | @Before(order = 0) 15 | public void setUpScenario() { 16 | System.out.println("set up browser"); 17 | Driver.get().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 18 | Driver.get().manage().window().fullscreen(); 19 | BasePage.webDriverWait = new WebDriverWait(Driver.get(), 10); 20 | } 21 | 22 | @Before(value = "@db", order = 1) 23 | public void connect(){ 24 | System.out.println("connecting to db"); 25 | } 26 | 27 | @After 28 | public void tearDownScenario() { 29 | System.out.println("close driver"); 30 | // Driver.closeDriver(); 31 | } 32 | 33 | @After("@db") 34 | public void closeConnection() { 35 | System.out.println("closing connection to db"); 36 | } 37 | 38 | 39 | // @BeforeStep 40 | public void setUpStep() { 41 | System.out.println("prints before every step"); 42 | } 43 | 44 | // @AfterStep 45 | public void tearDownStep(){ 46 | System.out.println("prints after every step"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/pages/Login.java: -------------------------------------------------------------------------------- 1 | package automationPractice.pages; 2 | 3 | import org.junit.Assert; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | 7 | 8 | public class Login extends BasePage { 9 | 10 | 11 | 12 | @FindBy(id = "_submit") 13 | public WebElement btn_login; 14 | 15 | @FindBy(id = "prependedInput") 16 | public WebElement txt_username; 17 | 18 | @FindBy(id = "prependedInput2") 19 | public WebElement txt_password; 20 | 21 | //lst_ - list 22 | //ckbx_ - checkbox 23 | 24 | @Override 25 | public void clickButton(String button) { 26 | button = button.toUpperCase(); 27 | switch (button) { 28 | case "LOGIN": 29 | btn_login.click(); 30 | break; 31 | default: 32 | Assert.fail("There are no button " + button + " availiable in switch statement"); 33 | } 34 | } 35 | 36 | @Override 37 | public void enterValue(String field, String value) { 38 | field = field.toUpperCase(); 39 | switch (field){ 40 | case "USERNAME": 41 | txt_username.sendKeys(value); 42 | break; 43 | case "PASSWORD": 44 | txt_password.sendKeys(value); 45 | break; 46 | default: 47 | Assert.fail("There are no field " + field + " availiable in switch statement"); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/pages/Dashboard.java: -------------------------------------------------------------------------------- 1 | package automationPractice.pages; 2 | 3 | import automationPractice.step_definitions.Hooks; 4 | import automationPractice.utilities.Driver; 5 | import org.junit.Assert; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | 10 | public class Dashboard extends BasePage{ 11 | 12 | @FindBy (xpath = "//span[.='Contacts']/following-sibling::a") 13 | public WebElement btn_contacts; 14 | 15 | @Override 16 | public void clickButton(String button) { 17 | button = button.toUpperCase(); 18 | switch (button) { 19 | case "ACCOUNTS": 20 | // btn_accounts.click(); 21 | break; 22 | case "CONTACTS": 23 | 24 | // webDriverWait.until(ExpectedConditions.visibilityOfAllElements(btn_contacts)); 25 | try { 26 | Thread.sleep(3000); 27 | } catch (InterruptedException e) { 28 | e.printStackTrace(); 29 | } 30 | btn_contacts.click(); 31 | break; 32 | default: 33 | Assert.fail("There are no button " + button + " availiable in switch statement"); 34 | } 35 | } 36 | 37 | @Override 38 | public void validateResult (String object, String expected){ 39 | object = object.toUpperCase(); 40 | switch (object){ 41 | case "TITLE": 42 | webDriverWait.until(ExpectedConditions.titleIs(expected)); 43 | Assert.assertEquals(expected, Driver.get().getTitle()); 44 | break; 45 | default: 46 | Assert.fail("There are no object " + object + " availiable in switch statement"); 47 | } 48 | 49 | } 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | office_hour_cucumber_project 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | 22 | 23 | 1.8 24 | 1.8 25 | 26 | 27 | 28 | org.seleniumhq.selenium 29 | selenium-java 30 | 3.141.59 31 | 32 | 33 | io.cucumber 34 | cucumber-java 35 | 5.6.0 36 | 37 | 38 | io.cucumber 39 | cucumber-junit 40 | 5.6.0 41 | 42 | 43 | io.github.bonigarcia 44 | webdrivermanager 45 | 3.8.1 46 | 47 | 48 | org.apache.poi 49 | poi 50 | 4.1.1 51 | 52 | 53 | 54 | org.apache.poi 55 | poi-ooxml 56 | 4.1.0 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/pages/BasePage.java: -------------------------------------------------------------------------------- 1 | package automationPractice.pages; 2 | 3 | import automationPractice.utilities.CommonMethods; 4 | import automationPractice.utilities.ConfigurationReader; 5 | import automationPractice.utilities.Driver; 6 | import automationPractice.utilities.ExcelUtil; 7 | import org.openqa.selenium.support.PageFactory; 8 | import org.openqa.selenium.support.ui.Select; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | 11 | public class BasePage implements CommonMethods { 12 | 13 | public static String str_firstName, str_lastName, str_phone, str_city, str_postalCode, str_street, str_state, str_country; 14 | public static WebDriverWait webDriverWait; 15 | Select select; 16 | 17 | public BasePage() { 18 | PageFactory.initElements(Driver.get(), this); 19 | } 20 | 21 | public void getData(String docName, String sheetName, String rowNum) { 22 | int row = Integer.parseInt(rowNum); 23 | String path = System.getProperty("user.dir") + ConfigurationReader.get(docName); 24 | ExcelUtil excel = new ExcelUtil(path, sheetName); 25 | str_firstName = excel.getCellData(row, 1); 26 | str_lastName = excel.getCellData(row, 2); 27 | str_phone = excel.getCellData(row, 3); 28 | str_street = excel.getCellData(row, 4); 29 | str_postalCode = excel.getCellData(row, 5); 30 | str_city = excel.getCellData(row, 6); 31 | str_country = excel.getCellData(row, 7); 32 | str_state = excel.getCellData(row, 8); 33 | 34 | System.out.println(str_firstName + " " + str_lastName + " " + str_phone); 35 | } 36 | 37 | public static String filterExcelData(String field, String value) { 38 | field = field.toUpperCase(); 39 | switch (field) { 40 | case "FIRST NAME": 41 | value = str_firstName; 42 | break; 43 | case "LAST NAME": 44 | value = str_lastName; 45 | break; 46 | case "STREET": 47 | value = str_street; 48 | break; 49 | case "PHONE": 50 | value = str_phone; 51 | break; 52 | case "CITY": 53 | value = str_city; 54 | break; 55 | case "ZIPCODE": 56 | value = str_postalCode; 57 | break; 58 | case "STATE": 59 | value = str_state; 60 | break; 61 | case "COUNTRY": 62 | value = str_country; 63 | break; 64 | } 65 | 66 | return value; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/step_definitions/InputSteps.java: -------------------------------------------------------------------------------- 1 | package automationPractice.step_definitions; 2 | 3 | import automationPractice.pages.BasePage; 4 | import automationPractice.utilities.ConfigurationReader; 5 | import automationPractice.utilities.PageObjects; 6 | import io.cucumber.java.en.Then; 7 | import io.cucumber.java.en.When; 8 | 9 | import java.util.HashMap; 10 | import java.util.LinkedHashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import static automationPractice.pages.BasePage.filterExcelData; 15 | 16 | 17 | public class InputSteps { 18 | 19 | 20 | 21 | @When("User enters {string} as {string} on {string} page") 22 | public void user_enters_as_on_page(String field, String value, String pageName) { 23 | BasePage page = PageObjects.getPageObject(pageName); 24 | //BasePage page = new Login(); 25 | if (value.equalsIgnoreCase("manager-username")){ 26 | value = ConfigurationReader.get("manager-username"); // salesmanager110 27 | } else if (value.equalsIgnoreCase("manager-password")){ 28 | value = ConfigurationReader.get("manager-password"); // salesmanager110 29 | }else if (value.equalsIgnoreCase("excel")){ 30 | value = filterExcelData(field, value); 31 | } 32 | page.enterValue(field, value); // (username, salesmanager110) 33 | } 34 | 35 | @When("User selects {string} as {string} on {string} page") 36 | public void user_selects_as_on_page(String listName, String value, String pageName) { 37 | BasePage page = PageObjects.getPageObject(pageName); 38 | if (value.equalsIgnoreCase("excel")) { 39 | value = filterExcelData(listName, value); 40 | } 41 | page.selectValue(listName, value); 42 | } 43 | 44 | 45 | @Then("User enters following information on {string} page") 46 | public void user_enters_following_information_on_page(String pageName, Map> table) { 47 | //Map> table -> Map 48 | BasePage page = PageObjects.getPageObject(pageName); 49 | System.out.println(table); 50 | Map dataMap = new LinkedHashMap<>(); 51 | for (String key:table.keySet()) { 52 | String initValue = table.get(key).get(0); //"excel" 53 | //First Name=[excel] ==> when I say table.get("First Name") will return [excel] and .get(0) -> String "excel" 54 | String value = initValue; 55 | if (value.equalsIgnoreCase("excel")) { 56 | value = filterExcelData(key, initValue); 57 | } 58 | //filterExcelData("First Name", "excel") => value from excel 59 | dataMap.put(key, value); //{First Name = value from excel , .... } 60 | } 61 | page.enterValue(dataMap); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/utilities/Driver.java: -------------------------------------------------------------------------------- 1 | package automationPractice.utilities; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebDriverException; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.chrome.ChromeOptions; 8 | import org.openqa.selenium.edge.EdgeDriver; 9 | import org.openqa.selenium.firefox.FirefoxDriver; 10 | import org.openqa.selenium.firefox.FirefoxOptions; 11 | import org.openqa.selenium.ie.InternetExplorerDriver; 12 | import org.openqa.selenium.safari.SafariDriver; 13 | 14 | public class Driver { 15 | 16 | private Driver(){} 17 | private static InheritableThreadLocal driver = new InheritableThreadLocal<>(); 18 | 19 | public static WebDriver get() { 20 | //if this thread doesn't have driver - create it and add to pool 21 | if (driver.get() == null) { 22 | // if we pass the driver from terminal then use that one 23 | // if we do not pass the driver from terminal then use the one properties file 24 | String browser = System.getProperty("browser") != null ? browser = System.getProperty("browser") : ConfigurationReader.get("browser"); 25 | 26 | switch (browser) { 27 | case "chrome": 28 | WebDriverManager.chromedriver().setup(); 29 | driver.set(new ChromeDriver()); 30 | break; 31 | case "chrome-headless": 32 | WebDriverManager.chromedriver().setup(); 33 | driver.set(new ChromeDriver(new ChromeOptions().setHeadless(true))); 34 | break; 35 | case "firefox": 36 | WebDriverManager.firefoxdriver().setup(); 37 | driver.set(new FirefoxDriver()); 38 | break; 39 | case "firefox-headless": 40 | WebDriverManager.firefoxdriver().setup(); 41 | driver.set(new FirefoxDriver(new FirefoxOptions().setHeadless(true))); 42 | break; 43 | case "ie": 44 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 45 | throw new WebDriverException("Your OS doesn't support Internet Explorer"); 46 | WebDriverManager.iedriver().setup(); 47 | driver.set(new InternetExplorerDriver()); 48 | break; 49 | 50 | case "edge": 51 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 52 | throw new WebDriverException("Your OS doesn't support Edge"); 53 | WebDriverManager.edgedriver().setup(); 54 | driver.set(new EdgeDriver()); 55 | break; 56 | case "safari": 57 | if (!System.getProperty("os.name").toLowerCase().contains("mac")) 58 | throw new WebDriverException("Your OS doesn't support Safari"); 59 | WebDriverManager.getInstance(SafariDriver.class).setup(); 60 | driver.set(new SafariDriver()); 61 | break; 62 | 63 | default: 64 | throw new RuntimeException("Invalid browser name"); 65 | } 66 | } 67 | return driver.get(); 68 | } 69 | 70 | public static void closeDriver() { 71 | driver.get().quit(); 72 | driver.remove(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/pages/ContactPage.java: -------------------------------------------------------------------------------- 1 | package automationPractice.pages; 2 | 3 | import org.junit.Assert; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.ui.ExpectedConditions; 7 | import org.openqa.selenium.support.ui.Select; 8 | 9 | import java.util.Map; 10 | 11 | public class ContactPage extends BasePage{ 12 | 13 | @FindBy (linkText = "Create Contact") 14 | public WebElement btn_createContact; 15 | 16 | @FindBy (xpath = "(//input[@data-name = 'field__first-name'])[1]") 17 | public WebElement txt_firstName; 18 | 19 | @FindBy (xpath = "(//input[@data-name = 'field__last-name'])[1]") 20 | public WebElement txt_lastName; 21 | 22 | @FindBy (name = "oro_contact_form[phones][0][phone]") 23 | public WebElement txt_phone; 24 | 25 | @FindBy (name = "oro_contact_form[addresses][0][street]") 26 | public WebElement txt_street; 27 | 28 | @FindBy (name = "oro_contact_form[addresses][0][city]") 29 | public WebElement txt_city; 30 | 31 | @FindBy (name = "oro_contact_form[addresses][0][postalCode]") 32 | public WebElement txt_zipCode; 33 | 34 | @FindBy (name = "oro_contact_form[addresses][0][country]") 35 | public WebElement lst_country; 36 | 37 | @FindBy (xpath = "//select[@data-name = 'field__region']") 38 | public WebElement lst_state; 39 | 40 | 41 | 42 | @Override 43 | public void clickButton(String button) { 44 | button = button.toUpperCase(); 45 | switch (button) { 46 | case "CREATE CONTACT": 47 | webDriverWait.until(ExpectedConditions.visibilityOfAllElements(btn_createContact)); 48 | webDriverWait.until(ExpectedConditions.elementToBeClickable(btn_createContact)); 49 | btn_createContact.click(); 50 | break; 51 | default: 52 | Assert.fail("There are no button " + button + " availiable in switch statement"); 53 | } 54 | } 55 | 56 | @Override 57 | public void enterValue(String field, String value) { 58 | field = field.toUpperCase(); 59 | switch (field){ 60 | case "FIRST NAME": 61 | txt_firstName.sendKeys(value); 62 | break; 63 | case "LAST NAME": 64 | txt_lastName.sendKeys(value); 65 | break; 66 | case "STREET": 67 | txt_street.sendKeys(value); 68 | break; 69 | case "PHONE": 70 | txt_phone.sendKeys(value); 71 | break; 72 | case "CITY": 73 | txt_city.sendKeys(value); 74 | break; 75 | case "ZIPCODE": 76 | txt_zipCode.sendKeys(value); 77 | break; 78 | default: 79 | Assert.fail("There are no field " + field + " availiable in switch statement"); 80 | } 81 | } 82 | 83 | @Override 84 | public void selectValue (String listName, String value){ 85 | listName = listName.toUpperCase(); 86 | switch (listName){ 87 | case "STATE": 88 | select = new Select(lst_state); 89 | select.selectByValue("US-" + value); 90 | break; 91 | case "COUNTRY": 92 | select = new Select(lst_country); 93 | select.selectByValue(value); 94 | break; 95 | } 96 | } 97 | 98 | @Override 99 | public void enterValue(Map datamap) { 100 | for (String key : datamap.keySet()) { 101 | if (key.equalsIgnoreCase("State") || key.equalsIgnoreCase("Country")){ 102 | selectValue(key, datamap.get(key)); 103 | continue; 104 | } 105 | enterValue(key, datamap.get(key)); 106 | } 107 | } 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/resources/features/LoginToApplication.feature: -------------------------------------------------------------------------------- 1 | Feature: Login To Application 2 | 3 | @ManagerLogin @TC001 4 | # We will have different implementation of differend methods in each page 5 | Scenario: Login as a manager 6 | Given User on "Login" page for "VyTrack" application 7 | When User enters "username" as "manager-username" on "Login" page 8 | # When User enters "username" as "mira@cybertek.com" on "Login" page 9 | When User enters "password" as "manager-password" on "Login" page 10 | And User clicks on "Login" button on "Login" page 11 | Then "Title" should be "Dashboard" on "Dashboard" page 12 | And User clicks on "Contacts" button on "Dashboard" page 13 | 14 | @ExcelData @TC002 15 | Scenario: Excel Data 16 | Given User on "Login" page for "VyTrack" application 17 | And User gets the test data from "vytrackdata1" excel "Data Sheet" sheet "1" row 18 | When User enters "username" as "manager-username" on "Login" page 19 | When User enters "password" as "manager-password" on "Login" page 20 | And User clicks on "Login" button on "Login" page 21 | Then "Title" should be "Dashboard" on "Dashboard" page 22 | And User clicks on "Contacts" button on "Dashboard" page 23 | #And User clicks on "Create new contact" button on "Dashboard" page 24 | # And User enters following information 25 | # |first name| last name|email||| 26 | # |excel|excel|qa@company.com|| 27 | 28 | @ExcelData2 @TC003 29 | Scenario Outline: Excel Data 30 | Given User on "Login" page for "VyTrack" application 31 | And User gets the test data from "" excel "" sheet "" row 32 | When User enters "username" as "manager-username" on "Login" page 33 | When User enters "password" as "manager-password" on "Login" page 34 | And User clicks on "Login" button on "Login" page 35 | Then "Title" should be "Dashboard" on "Dashboard" page 36 | And User clicks on "Contacts" button on "Dashboard" page 37 | And User clicks on "Create Contact" button on "Contact" page 38 | When User enters "First Name" as "excel" on "Contact" page 39 | When User enters "Last Name" as "excel" on "Contact" page 40 | When User enters "Phone" as "excel" on "Contact" page 41 | When User enters "Street" as "excel" on "Contact" page 42 | When User enters "City" as "excel" on "Contact" page 43 | When User enters "ZipCode" as "excel" on "Contact" page 44 | When User selects "Country" as "excel" on "Contact" page 45 | When User selects "State" as "excel" on "Contact" page 46 | 47 | @client2 48 | Examples: 49 | | row | ExcelDocument | SheetName | 50 | | 3 | vytrackdata2 | Data Sheet | 51 | # | 6 |vytrackdata2 |Data Sheet2| 52 | # | 2 |vytrackdata2 | 53 | # | 5 |vytrackdata2 | 54 | 55 | @TC004 56 | Scenario Outline: Excel with map example 57 | Given User on "Login" page for "VyTrack" application 58 | And User gets the test data from "" excel "" sheet "" row 59 | When User enters "username" as "manager-username" on "Login" page 60 | When User enters "password" as "manager-password" on "Login" page 61 | And User clicks on "Login" button on "Login" page 62 | Then "Title" should be "Dashboard" on "Dashboard" page 63 | And User clicks on "Contacts" button on "Dashboard" page 64 | And User clicks on "Create Contact" button on "Contact" page 65 | And User enters following information on "Contact" page 66 | | First Name | | 67 | | Last Name | excel | 68 | | Phone | excel | 69 | | Street | excel | 70 | | City | excel | 71 | | ZipCode | excel | 72 | | Country | excel | 73 | | State | excel | 74 | 75 | @client2 76 | Examples: 77 | | row | ExcelDocument | SheetName | First Name | 78 | | 3 | vytrackdata2 | Data Sheet | excel | 79 | # | 4 | vytrackdata2 | Data Sheet2 | Mary | 80 | #ctrl + shift + alt + l to alight/format the file -------------------------------------------------------------------------------- /src/main/java/automationPractice/utilities/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package automationPractice.utilities; 2 | 3 | 4 | 5 | import org.apache.poi.ss.usermodel.*; 6 | import org.junit.Assert; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.FileOutputStream; 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | public class ExcelUtil { 16 | 17 | private Sheet workSheet; 18 | private Workbook workBook; 19 | private String path; 20 | public ExcelUtil(String path, String sheetName) { 21 | this.path = path; 22 | try { 23 | // Open the Excel file 24 | FileInputStream ExcelFile = new FileInputStream(path); 25 | // Access the required test data sheet 26 | workBook = WorkbookFactory.create(ExcelFile); 27 | workSheet = workBook.getSheet(sheetName); 28 | } catch (Exception e) { 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | public String getCellData(int rowNum, int colNum) { 34 | Cell cell; 35 | try { 36 | cell = workSheet.getRow(rowNum).getCell(colNum); 37 | String cellData = cell.toString(); 38 | return cellData; 39 | } catch (Exception e) { 40 | throw new RuntimeException(e); 41 | } 42 | } 43 | 44 | public String[][] getDataArray() { 45 | String[][] data = new String[rowCount()][columnCount()]; 46 | for (int i = 0; i > getDataList() { 56 | // get all columns 57 | List columns = getColumnsNames(); 58 | // this will be returned 59 | List> data = new ArrayList<>(); 60 | for (int i = 1; i < rowCount(); i++) { 61 | // get each row 62 | Row row = workSheet.getRow(i); 63 | // create map of the row using the column and value 64 | // column map key, cell value --> map bvalue 65 | Map rowMap = new HashMap(); 66 | for (Cell cell : row) { 67 | int columnIndex = cell.getColumnIndex(); 68 | rowMap.put(columns.get(columnIndex), cell.toString()); 69 | } 70 | data.add(rowMap); 71 | } 72 | return data; 73 | } 74 | 75 | public List getColumnsNames() { 76 | List columns = new ArrayList<>(); 77 | for (Cell cell : workSheet.getRow(0)) { 78 | columns.add(cell.toString()); 79 | } 80 | return columns; 81 | } 82 | 83 | public void setCellData(String value, int rowNum, int colNum) { 84 | Cell cell; 85 | Row row; 86 | try { 87 | row = workSheet.getRow(rowNum); 88 | cell = row.getCell(colNum); 89 | if (cell == null) { 90 | cell = row.createCell(colNum); 91 | cell.setCellValue(value); 92 | } else { 93 | cell.setCellValue(value); 94 | } 95 | FileOutputStream fileOut = new FileOutputStream(path); 96 | workBook.write(fileOut); 97 | fileOut.close(); 98 | } catch (Exception e) { 99 | e.printStackTrace(); 100 | } 101 | } 102 | 103 | public void setCellData(String value, String columnName, int row) { 104 | int column = getColumnsNames().indexOf(columnName); 105 | setCellData(value, row, column); 106 | } 107 | 108 | public int columnCount() { 109 | return workSheet.getRow(0).getLastCellNum(); 110 | } 111 | 112 | public int rowCount() { 113 | return workSheet.getLastRowNum()+1; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/automationPractice/utilities/ConfigurationReader.java: -------------------------------------------------------------------------------- 1 | package automationPractice.utilities; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.WebDriverException; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.chrome.ChromeOptions; 8 | import org.openqa.selenium.edge.EdgeDriver; 9 | import org.openqa.selenium.firefox.FirefoxDriver; 10 | import org.openqa.selenium.firefox.FirefoxOptions; 11 | import org.openqa.selenium.ie.InternetExplorerDriver; 12 | import org.openqa.selenium.safari.SafariDriver; 13 | 14 | import java.io.FileInputStream; 15 | import java.util.Properties; 16 | 17 | public class ConfigurationReader { 18 | 19 | private static Properties properties; 20 | 21 | static { 22 | 23 | try { 24 | String path = "Configurations.properties"; 25 | FileInputStream input = new FileInputStream(path); 26 | properties = new Properties(); 27 | properties.load(input); 28 | 29 | input.close(); 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | 33 | } 34 | } 35 | 36 | public static String get(String keyName) { 37 | return properties.getProperty(keyName); 38 | } 39 | 40 | 41 | public static class Driver { 42 | private Driver() { 43 | 44 | } 45 | 46 | private static WebDriver driver; 47 | 48 | public static WebDriver get() { 49 | if (driver == null) { 50 | String browser = ConfigurationReader.get("browser"); 51 | switch (browser) { 52 | case "chrome": 53 | WebDriverManager.chromedriver().setup(); 54 | driver = new ChromeDriver(); 55 | break; 56 | case "chrome-headless": 57 | WebDriverManager.chromedriver().setup(); 58 | driver = new ChromeDriver(new ChromeOptions().setHeadless(true)); 59 | break; 60 | case "firefox": 61 | WebDriverManager.firefoxdriver().setup(); 62 | driver = new FirefoxDriver(); 63 | break; 64 | case "firefox-headless": 65 | WebDriverManager.firefoxdriver().setup(); 66 | driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true)); 67 | break; 68 | case "ie": 69 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 70 | throw new WebDriverException("Your OS doesn't support Internet Explorer"); 71 | WebDriverManager.iedriver().setup(); 72 | driver = new InternetExplorerDriver(); 73 | break; 74 | 75 | case "edge": 76 | if (!System.getProperty("os.name").toLowerCase().contains("windows")) 77 | throw new WebDriverException("Your OS doesn't support Edge"); 78 | WebDriverManager.edgedriver().setup(); 79 | driver = new EdgeDriver(); 80 | break; 81 | 82 | case "safari": 83 | if (!System.getProperty("os.name").toLowerCase().contains("mac")) 84 | throw new WebDriverException("Your OS doesn't support Safari"); 85 | WebDriverManager.getInstance(SafariDriver.class).setup(); 86 | driver = new SafariDriver(); 87 | break; 88 | } 89 | 90 | 91 | 92 | } 93 | 94 | return driver; 95 | } 96 | 97 | public static void closeDriver() { 98 | if (driver != null) { 99 | driver.quit(); 100 | driver = null; 101 | } 102 | } 103 | } 104 | 105 | } 106 | --------------------------------------------------------------------------------