This test case checks that the search feature works correctly and that it returns relevant results when a search query is entered.
Language: Java
Framework: Selenium 4
1//Assumptions: 2//1. That the Shopify webpage has a search feature with a search bar and search button.3//2. That the webpage is loaded in the driver.45//Code to test the search feature in Shopify webpage using Selenium 4 in Java:67//To use local driver:8WebDriver driver = new ChromeDriver();910//To connect to remote client with desired capabilities:11//DesiredCapabilities capabilities = DesiredCapabilities.chrome();12//WebDriver driver = new RemoteWebDriver(new URL("remote url"), capabilities);1314//To access the Shopify webpage:15driver.get("https://www.shopify.com/");1617//Locating the search bar:18WebElement search_bar = driver.findElement(By.name("q"));1920//Entering the search query:21search_bar.sendKeys("Shopify themes");2223//Locating the search button:24WebElement search_button = driver.findElement(By.cssSelector("button[type='submit']"));2526//Clicking the search button:27search_button.click();2829//Checking if the search results page is displayed:30Assert.assertEquals(driver.getTitle(), "Search Results – Shopify", "Search Feature is not working."); 3132//Closing the webpage:33driver.close();
Language: Python
Framework: Selenium 4
1Assumptions:2- The search feature is implemented with an input field and a submit button on the Shopify webpage.3- The search query can be any valid text string.4- The search results page displays the product images, names, descriptions, and prices for all relevant products.5- The search feature is accessible on all pages of the Shopify webpage.67Code:89# Import Selenium WebDriver and its support classes10from selenium import webdriver11from selenium.webdriver.common.by import By12from selenium.webdriver.common.keys import Keys13from selenium.webdriver.support.ui import WebDriverWait14from selenium.webdriver.support import expected_conditions as EC1516# Define the local driver path and desired capabilities for remote client17driver_path = 'local-driver-path'18desired_caps = {19 'browserName': 'chrome',20 'version': 'latest',21 'platform': 'WINDOWS',22 'name': 'Shopify Search Testing'23}2425# Connect to local driver26driver = webdriver.Chrome(driver_path)2728# Connect to remote client with desired capabilities (commented out for local testing)29'''30from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver31from selenium.webdriver.common.desired_capabilities import DesiredCapabilities3233remote_url = 'remote-client-url'34driver = RemoteWebDriver(command_executor = remote_url, desired_capabilities = DesiredCapabilities.CHROME)35'''3637# Navigate to the Shopify webpage38driver.get('https://www.shopify.com/')3940# Find the search input field and enter a search query41search_input = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@name='q']")))42search_input.clear()43search_input.send_keys('shopify products')44search_input.send_keys(Keys.RETURN)4546# Check the search results page for relevant products47result_items = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//div[@class='product-item']")))48assert len(result_items) > 04950# Output a message if the test passed51print("Shopify search feature test passed.")5253# Close the browser session54driver.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.
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.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing