Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zomato Web Assignment implemented on getting-started-with-teswiz #51

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ task run(type: JavaExec) {
def logDirectory = "target/" + getCurrentDatestamp() + "/" + getCurrentTimestamp()
println "Using LOG_DIR: $logDirectory"
System.setProperty "LOG_DIR", "$logDirectory"
environment "APPLITOOLS_API_KEY", System.getenv("teswiz_APPLITOOLS_API_KEY")
environment "APPLITOOLS_API_KEY", System.getenv("qecc_APPLITOOLS_API_KEY")

def configFile = System.getenv("CONFIG")
if(null == configFile || !file(configFile).exists()) {
Expand Down
2 changes: 1 addition & 1 deletion configs/applitools_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serverUrl": "https://eyesapi.applitools.com/",
"serverUrl": "https://jioeyes.applitools.com/",
"defaultMatchLevel": "strict",
"enableBenchmarkPerValidation": true,
"sendDOM": true,
Expand Down
26 changes: 26 additions & 0 deletions configs/zomato_local_config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
RUNNER=distribute
FRAMEWORK=cucumber
RUNNER_LEVEL=methods
APP_NAME=zomato
APPLITOOLS_CONFIGURATION=./configs/applitools_config.json
BASE_URL_FOR_WEB=ZOMATO_BASE_URL
BROWSER=chrome
ENVIRONMENT_CONFIG_FILE=./src/test/resources/environments.json
CLEANUP_DEVICE_BEFORE_STARTING_EXECUTION=false
IS_VISUAL=true
LOG_DIR=target
LOG_PROPERTIES_FILE=./src/test/resources/log4j.properties
PARALLEL=1
PLATFORM=android
PROXY_KEY=HTTP_PROXY
BUILD_ID=BUILDID
WEBDRIVER_MANAGER_PROXY_KEY=HTTP_PROXY
REPORT_PORTAL_FILE=src/test/resources/reportportal.properties
REMOTE_WEBDRIVER_GRID_PORT=TESWIZ_GRID_PORT
RUN_IN_CI=false
TARGET_ENVIRONMENT=prod
TEST_DATA_FILE=./src/test/resources/testData.json
MAX_NUMBER_OF_APPIUM_DRIVERS=5
MAX_NUMBER_OF_WEB_DRIVERS=5
BROWSER_CONFIG_FILE=./configs/browser_config.json
BRANCH_NAME=BUILD_SOURCEBRANCH
111 changes: 111 additions & 0 deletions src/test/java/com/znsio/sample/e2e/businessLayer/zomato/ZomatoBL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.znsio.sample.e2e.businessLayer.zomato;

import com.context.TestExecutionContext;
import com.znsio.sample.e2e.entities.SAMPLE_TEST_CONTEXT;
import com.znsio.sample.e2e.screen.zomato.DineOutScreen;
import com.znsio.sample.e2e.screen.zomato.HomePageScreen;
import com.znsio.sample.e2e.screen.zomato.RestaurantScreen;
import com.znsio.teswiz.entities.Platform;
import com.znsio.teswiz.runner.Runner;
import org.apache.log4j.Logger;
import org.assertj.core.api.SoftAssertions;

import static org.assertj.core.api.Assertions.assertThat;

public class ZomatoBL {
private static final Logger LOGGER = Logger.getLogger(ZomatoBL.class.getName());
private final TestExecutionContext context;
private final SoftAssertions softly;
private final String currentUserPersona;
private final Platform currentPlatform;

public ZomatoBL(String userPersona, Platform forPlatform) {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = userPersona;
this.currentPlatform = forPlatform;
Runner.setCurrentDriverForUser(userPersona, forPlatform, context);
}

public ZomatoBL() {
long threadId = Thread.currentThread().getId();
this.context = Runner.getTestExecutionContext(threadId);
softly = Runner.getSoftAssertion(threadId);
this.currentUserPersona = SAMPLE_TEST_CONTEXT.ME;
this.currentPlatform = Runner.getPlatform();
}

public ZomatoBL launchHomePageAndValidate() {
boolean isHomePageLaunchedSuccessfully = HomePageScreen.get().verifyHomePageLaunch();
assertThat(isHomePageLaunchedSuccessfully).as("Url mismatch occurred, try opening the correct url for the application").isTrue();
LOGGER.info("Homepage launched successfully");
return this;
}

public ZomatoBL selectDiningOption() {
HomePageScreen.get().selectDiningOption();
return this;
}

public ZomatoBL verifyRedirectionToDineoutPage() {
boolean isRedirectionToDineoutPageSuccessful = DineOutScreen.get().verifyRedirectionToDineoutPage();
assertThat(isRedirectionToDineoutPageSuccessful).as("Load the correct page, redirection to dineout was not successful ").isTrue();
LOGGER.info("Redirected to Dine-out page successfully");
return this;
}

public ZomatoBL selectLocationForRestaurant() {
DineOutScreen.get().selectLocation();
return this;
}

public ZomatoBL verifySelectedLocationWithLocationDisplayed() {
boolean isCorrectLocationSelected = DineOutScreen.get().verifyLocationDisplayed();
assertThat(isCorrectLocationSelected).as("Incorrect/Improper location was set").isTrue();
LOGGER.info("Displayed Location is correct");
return this;
}

public ZomatoBL chooseRestaurantFromSelectedLocation() {
DineOutScreen.get().selectSpecificRestaurant();
return this;
}

public ZomatoBL verifySelectedRestaurantWithRestaurantDisplayed() {
boolean isCorrectRestaurantDisplayed = RestaurantScreen.get().verifyRestaurantDisplayed();
assertThat(isCorrectRestaurantDisplayed).as("incorrect location set").isTrue();
LOGGER.info("Displayed Restaurant is correct");
return this;
}

public ZomatoBL bookATableOnASpecificDateAndTimeForGuests() {
boolean isBookATableOptionSelected = RestaurantScreen.get().clickOnBookATable().verifyBookATableOptionSelected();
assertThat(isBookATableOptionSelected).as("Book a Table option not selected").isTrue();
LOGGER.info("Book a Table option successfully selected");

boolean isDateDisplayedSameAsSelected = RestaurantScreen.get().selectDate().verifyDateSelectedMatchingWithDateDisplayed();
softly.assertThat(isDateDisplayedSameAsSelected).as("Incorrect date displayed or no date selected").isTrue();
LOGGER.info("Correct Date selected");

boolean areNumberOfGuestsDisplayedSameAsSelected = RestaurantScreen.get().selectNumberOfGuests().verifyNumberOfGuestsSelectedMatchingWithNumberOfGuestsDisplayed();
softly.assertThat(areNumberOfGuestsDisplayedSameAsSelected).as("Incorrect number of guests displayed or no guests selected").isTrue();
LOGGER.info("Correct Number of Guests selected");

boolean isTimeSlotSelected = RestaurantScreen.get().selectTimeSlot().verifyTimeSlotSelected();
softly.assertThat(isTimeSlotSelected).as("No timeslot selected").isTrue();
LOGGER.info("Timeslot selected");

boolean areGuestDetailsCorrect = RestaurantScreen.get().fillGuestBasicDetails().verifyGuestDetails();
softly.assertThat(areGuestDetailsCorrect).as("Guest details filled are incorrect or incomplete").isTrue();
LOGGER.info("Guest details filled correctly");
return this;
}

public ZomatoBL verifyLoginPopUpMessage() {
boolean isLoginPopUpMessageDisplayed = RestaurantScreen.get().verifyLoginPopUpMessageDisplayed();
assertThat(isLoginPopUpMessageDisplayed).as("Login Pop Up message not displayed").isTrue();
LOGGER.info("Login Pop up Message displayed");
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class SAMPLE_TEST_CONTEXT
extends TEST_CONTEXT {
public static final String ME = "me";
public static final String RESTAURANT_NAME = "";
public static final String MEETING_ID = "meetingId";
public static final String MEETING_PASSWORD = "meetingPassword";
public static final String INVITATION_LINK = "invitationLink";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.znsio.sample.e2e.screen.web.zomato;

import com.context.SessionContext;
import com.context.TestExecutionContext;
import com.znsio.sample.e2e.entities.SAMPLE_TEST_CONTEXT;
import com.znsio.sample.e2e.screen.zomato.DineOutScreen;
import com.znsio.teswiz.runner.Driver;
import com.znsio.teswiz.runner.Visual;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;

import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class DineOutScreenWeb extends DineOutScreen {
private final Driver driver;
private final Visual visually;
private final String SCREEN_NAME = DineOutScreenWeb.class.getSimpleName();
private static final Logger LOGGER = Logger.getLogger(DineOutScreenWeb.class.getName());
private final TestExecutionContext context;
private final String dineoutPagePartialUrl = "dine-out";
private final By byDiningOutTabText = By.xpath("//div[text()='Dining Out']");
private final By byLocationSearchInput = By.xpath("(//ul[starts-with(@id,'navigation')]/li/div//div/div/input)[1]");
private final By byLocationSearchDropdown = By.xpath("(//ul[starts-with(@id,'navigation')]/li/div/div/div/i)[2]");
private String subLocationCityNameText = "//ul[starts-with(@id,'navigation')]/li/div/div/div/div/div/p[starts-with(@class,'sc') and text()='%s']";
private final By byRestaurantNameText = By.xpath("//div[@id='root']/div/div[9]/div/div[3]/div/div/a/div/h4");

public DineOutScreenWeb(Driver driver, Visual visually) {
this.driver = driver;
this.visually = visually;
context = SessionContext.getTestExecutionContext(Thread.currentThread().getId());
}

@Override
public boolean verifyRedirectionToDineoutPage() {
driver.getInnerDriver().manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
LOGGER.info("Verifying redirection to dine out page using url");
return driver.getInnerDriver().getCurrentUrl().contains(dineoutPagePartialUrl) && driver.isElementPresent(byDiningOutTabText);
}

@Override
public DineOutScreen selectLocation() {
visually.checkWindow(SCREEN_NAME, "Dineout Screen");
String location = getLocationFromTestData();
LOGGER.info("Got location from test data");
driver.waitTillElementIsPresent(byLocationSearchInput);
driver.findElement(byLocationSearchInput).sendKeys(location);
driver.findElement(byLocationSearchInput).sendKeys(Keys.RETURN);
LOGGER.info("Entered location in search field");
String[] subLocations = location.split(",");
subLocationCityNameText = String.format(subLocationCityNameText, subLocations[0]);
LOGGER.info("Waiting for search options to appear");
driver.getInnerDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
if (driver.isElementPresent(By.xpath(subLocationCityNameText))) {
if (!driver.findElement(By.xpath(subLocationCityNameText)).isDisplayed()) {
driver.findElement(byLocationSearchDropdown).click();
LOGGER.info("Clicking on search dropdown, as dropdown is not already open");
}
LOGGER.info("Selecting location from options");
driver.findElement(By.xpath(subLocationCityNameText)).click();
}
return this;
}

private String getLocationFromTestData() {
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
jsonObject = (JSONObject) parser.parse(new FileReader("src/test/resources/testData.json"));
} catch (IOException | ParseException e) {
throw new RuntimeException(e);
}
jsonObject = (JSONObject) jsonObject.get("prod");
return (String) jsonObject.get("ZOMATO_RESTAURANT_LOCATION");
}

@Override
public boolean verifyLocationDisplayed() {
visually.checkWindow(SCREEN_NAME, "Dineout Screen");
String location = getLocationFromTestData();
LOGGER.info("Verifying location selected and location displayed after selection are same or not");
driver.getInnerDriver().manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
return driver.findElement(byLocationSearchInput).getAttribute("placeholder").contains(location);
}

@Override
public DineOutScreen selectSpecificRestaurant() {
driver.getInnerDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
LOGGER.info("Saving restaurant name in context");
context.addTestState(SAMPLE_TEST_CONTEXT.RESTAURANT_NAME, driver.findElement(byRestaurantNameText).getText());
LOGGER.info("Selecting a specific restaurant");
driver.findElement(byRestaurantNameText).click();
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.znsio.sample.e2e.screen.web.zomato;

import com.znsio.sample.e2e.screen.zomato.HomePageScreen;
import com.znsio.teswiz.runner.Driver;
import com.znsio.teswiz.runner.Visual;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;

import java.util.concurrent.TimeUnit;

public class HomePageScreenWeb extends HomePageScreen {
private final Driver driver;
private final Visual visually;
private final String SCREEN_NAME = HomePageScreenWeb.class.getSimpleName();
private static final Logger LOGGER = Logger.getLogger(HomePageScreenWeb.class.getName());
private final String homePagePartialUrl = "www.zomato.com";
private final By byDiningCardText = By.xpath("//p[text()='Dining']");

public HomePageScreenWeb(Driver driver, Visual visually) {
this.driver = driver;
this.visually = visually;
}

@Override
public boolean verifyHomePageLaunch() {
driver.getInnerDriver().manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
LOGGER.info("Verifying Home Page launch");
return driver.getInnerDriver().getCurrentUrl().contains(homePagePartialUrl);
}

@Override
public HomePageScreen selectDiningOption() {
driver.waitTillElementIsPresent(byDiningCardText);
visually.checkWindow(SCREEN_NAME, "HomePage Screen");
LOGGER.info("Selecting Dining option");
driver.findElement(byDiningCardText).click();
return this;
}
}
Loading