Shopify webpage testing : Test checkout process

By ensuring that the checkout process on a Shopify website is running effectively, including calculating the correct total cost of orders, ensuring that payment is completed successfully and that the customers order details are properly saved.

Language: Java

Framework: Selenium 4

copy
1/​/​Assuming that the checkout process is initiated from the cart page2/​/​Assuming that the payment gateway is integrated with Shopify and has no issues34import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.By;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.chrome.ChromeOptions;1112public class ShopifyCheckoutTest {1314 public static void main(String[] args) {1516 /​/​Local driver setup17 System.setProperty("webdriver.chrome.driver", "path/​to/​chromedriver");18 WebDriver driver = new ChromeDriver(); 1920 /​/​Remote client setup with desired capabilities21 /​/​ ChromeOptions options = new ChromeOptions();22 /​/​ options.setCapability("browserName", "chrome");23 /​/​ options.setCapability("version", "91.0");24 /​/​ options.setCapability("platform", "Windows 10");25 /​/​ WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), options);2627 driver.get("https:/​/​www.shopify.com/​");28 driver.manage().window().maximize();29 30 /​/​Perform actions to initiate checkout process from cart page31 WebElement cartIcon = driver.findElement(By.className("cart-icon"));32 cartIcon.click();33 34 WebElement checkoutButton = driver.findElement(By.className("checkout-btn"));35 checkoutButton.click();36 37 /​/​Verify that checkout process is initiated properly38 WebDriverWait wait = new WebDriverWait(driver, 10);39 wait.until(ExpectedConditions.urlContains("/​checkout"));4041 /​/​Assuming that the order details have been filled in properly42 /​/​Perform actions to complete payment process43 WebElement totalPrice = driver.findElement(By.className("total-price"));44 double totalCost = Double.parseDouble(totalPrice.getText().replace("$", ""));45 /​/​Assuming that the correct total cost is displayed and saved in a variable46 47 WebElement paymentMethod = driver.findElement(By.id("payment-method"));48 paymentMethod.click();49 /​/​Assuming that payment method is selected successfully50 51 WebElement placeOrderButton = driver.findElement(By.id("place-order-button"));52 placeOrderButton.click();53 54 /​/​Verify that payment is completed successfully and order details are saved properly55 wait.until(ExpectedConditions.urlContains("/​thank_you"));56 /​/​Assuming that "/​thank_you" is the order confirmation page57 WebElement orderDetails = driver.findElement(By.className("order-details"));58 /​/​Assuming that order details are displayed properly 5960 /​/​Close driver61 driver.quit();62 }63}

Language: Python

Framework: Selenium 4

copy
1"""Assumptions:2- The Shopify website has a checkout process that can be accessed through a URL3- The total cost of orders is displayed on the checkout page4- Payment can be completed successfully with a valid payment method5- Order details are properly saved and can be verified on a confirmation page6"""78# Import necessary Selenium modules9from selenium import webdriver10from selenium.webdriver.common.keys import Keys11from selenium.webdriver.support.ui import WebDriverWait12from selenium.webdriver.support.ui import Select13from selenium.webdriver.support import expected_conditions as EC14from selenium.webdriver.common.by import By1516# Define checkout URL17checkout_url = "https:/​/​example-shopify-checkout.com"1819# Use local Chrome driver20driver = webdriver.Chrome()2122# Connect to remote client with desired capabilities:23# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities24# desired_capabilities = DesiredCapabilities.CHROME.copy()25# remote_driver_url = "http:/​/​127.0.0.1:4444/​wd/​hub"26# driver = webdriver.Remote(remote_driver_url, desired_capabilities)2728# Navigate to checkout URL29driver.get(checkout_url)3031# Enter customer information on checkout page32driver.find_element_by_id("first-name").send_keys("John")33driver.find_element_by_id("last-name").send_keys("Doe")34driver.find_element_by_id("address").send_keys("123 Main St.")35driver.find_element_by_id("city").send_keys("Anytown")36driver.find_element_by_id("zip").send_keys("12345")37driver.find_element_by_id("phone").send_keys("555-555-5555")38driver.find_element_by_id("email").send_keys("john.doe@example.com")3940# Select shipping and payment options41shipping_select = Select(driver.find_element_by_name("shipping-method"))42shipping_select.select_by_value("standard")43payment_radio = driver.find_element_by_id("payment-method-card")44driver.execute_script("arguments[0].click();", payment_radio)4546# Enter payment information47driver.find_element_by_id("cardnumber").send_keys("4111111111111111") # Example credit card number48driver.find_element_by_id("expiration").send_keys("1222") # Example expiration date49driver.find_element_by_id("cvv").send_keys("123") # Example CVV code5051# Click on "Place order" button52driver.find_element_by_css_selector(".step__footer__continue-btn").click()5354# Wait for confirmation page to load55confirmation_header = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".os-order-number h1")))5657# Assert that order details are properly saved58assert confirmation_header.text.startswith("Thank you"), "Order confirmation header not found"59assert driver.find_element_by_css_selector(".os-payment .os-text-secondary").text.startswith("4111"), "Payment information not saved correctly"60assert driver.find_element_by_css_selector(".os-shipping .os-text-secondary").text.startswith("Standard"), "Shipping information not saved correctly"6162# Get total cost of order63total_cost = driver.find_element_by_css_selector(".os-total .os-summary-item__value").text6465# Assert that total cost of order is calculated correctly66assert total_cost == "$100.00", "Total cost of order is incorrect"6768# Quit the driver69driver.quit()

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing