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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
getting location for method selectLocation from testData.json, change…
…d method names, modified/added logs, formatted code, optimized imports
Mukund1 Gupta authored and Mukund1 Gupta committed Jun 21, 2023
commit 6eb1f61f0191377ec07e14cc2ef3c31a484b706b
Original file line number Diff line number Diff line change
@@ -7,11 +7,14 @@
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 org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

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

public class DineOutScreenWeb extends DineOutScreen {
@@ -26,6 +29,7 @@ public class DineOutScreenWeb extends DineOutScreen {
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;
@@ -35,40 +39,61 @@ public DineOutScreenWeb(Driver driver, Visual visually) {
@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 selectLocationForRestaurants(String location) {
visually.checkWindow(SCREEN_NAME,"Dineout Screen Opened");
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 isCorrectLocationSelected(String location) {
visually.checkWindow(SCREEN_NAME, "Dineout Screen, Location Selected");
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);
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;
}