0% found this document useful (0 votes)
18 views

Chatgpt

automation code

Uploaded by

jarin39487
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Chatgpt

automation code

Uploaded by

jarin39487
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import org.openqa.selenium.

By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DominosOrderAutomation {


private WebDriver driver;

public void setUp() {


// Set up WebDriver, assuming you have already downloaded and configured
ChromeDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver = new ChromeDriver();
}

public void openDominosWebsite() {


driver.get("https://www.dominos.co.in");
}

public void clickOrderOnlineNow() {


WebElement orderOnlineNowButton =
driver.findElement(By.xpath("//button[text()='Order Online Now']"));
orderOnlineNowButton.click();
}

public void enterPinCodeAndSelectFirstSuggestion(String pinCode) {


WebElement pinCodeField = driver.findElement(By.id("pin"));
pinCodeField.sendKeys(pinCode);
WebElement firstSuggestion = driver.findElement(By.xpath("//li[@class='ui-
menu-item'][1]"));
firstSuggestion.click();
}

public void addProductsToCart() {


// Add 2 quantities of each product in the VEG PIZZA section
addProductToCart("Caprese Gourmet Pizza", 2);
addProductToCart("Margherita", 2);
addProductToCart("Peppy Paneer", 2);

// Add 12 quantities of Pepsi 475ml in the BEVERAGES section


addProductToCart("Pepsi 475ml", 12);
}

public void assertCartSubtotalValue(double expectedSubtotal) {


double actualSubtotal = getCartSubtotalValue();
assert actualSubtotal == expectedSubtotal : "Assertion failed: Cart
Subtotal value is not as expected.";
}

public void removeProductsFromCart() {


// Remove 1 quantity of Margherita
removeProductFromCart("Margherita", 1);

// Remove 6 quantities of Pepsi 475ml


removeProductFromCart("Pepsi 475ml", 6);
}

public void getSubtotalAndClickCheckout() {


double subtotal = getCartSubtotalValue();
WebElement checkoutButton =
driver.findElement(By.xpath("//button[text()='Check Out']"));
checkoutButton.click();
// You can perform further actions on the Checkout page, such as filling in
customer details, etc.
}

public void assertSubtotalAtCheckoutWithPlaceOrderPriceDetails() {


double subtotalAtCheckout = getSubtotalAtCheckout();
double subtotalAtPlaceOrder = getSubtotalAtPlaceOrder();
assert subtotalAtCheckout == subtotalAtPlaceOrder : "Assertion failed:
Subtotal value at checkout is not same as Subtotal value at Place Order Price
Details.";
}

public void tearDown() {


driver.quit();
}

private void addProductToCart(String productName, int quantity) {


WebElement product = driver.findElement(By.xpath("//div[text()='" +
productName + "']"));
WebElement quantityField =
product.findElement(By.xpath(".//input[@type='text']"));
quantityField.clear();
quantityField.sendKeys(String.valueOf(quantity));
WebElement addToCartButton = product.findElement(By.xpath(".//a[@class='btn
btn-red btn-sm']"));
addToCartButton.click();
}

private void removeProductFromCart(String productName, int quantity) {


WebElement product = driver.findElement(By.xpath("//div[text()='" +
productName + "']"));
WebElement quantityField =
product.findElement(By.xpath(".//input[@type='text']"));
quantityField.clear();

//a[@onclick='redirectToOrderOnline()']//button[text()='ORDER ONLINE NOW']


//a[@href='https://m.dominos.co.in/changeAddress?
src=brand&_ga=2.69918165.457704975.1681797269-2096313385.1681797269']/button

You might also like