Ensure that all links function properly and lead the user to the correct page. This test case ensures that the navigation menu is operational and that all links direct the user to the correct page, resulting in a consistent user experience.
Language: Java
Framework: Selenium 4
1//Assuming the Shopify webpage is already open and the navigation menu is displayed on the page23import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;89public class ShopifyNavMenuTest {1011 public static void main(String[] args) {12 13 //set chrome driver path and desired capabilities14 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");15 ChromeOptions options = new ChromeOptions();16 options.setCapability("version", "latest");17 options.setCapability("platform", "Windows 10");18 19 //connect to remote client with desired capabilities (if testing on a remote machine)20 //WebDriver driver = new RemoteWebDriver(new URL("http://<remote-machine-ip>:4444/wd/hub"), options);21 22 //initialize local chrome driver23 WebDriver driver = new ChromeDriver(options);24 25 //maximize window for better visibility26 driver.manage().window().maximize();27 28 //find all links in navigation menu and click them29 WebElement parentMenu = driver.findElement(By.xpath("//ul[@class='site-nav__list']/li/a"));30 for (WebElement navItem : parentMenu.findElements(By.xpath("./*"))) {31 navItem.click();32 33 //assert that page title is correct34 String expectedTitle = driver.findElement(By.xpath("//h1")).getText();35 assert expectedTitle.equals(navItem.getText()) : "Page title did not match expected title";36 }37 38 //close the browser39 driver.quit();40 }4142}4344//Assuming the navigation menu contains a list of links with correct text and href attributes
Language: Python
Framework: Selenium 4
1from selenium import webdriver23# Set up the driver4driver = webdriver.Chrome()56# Navigate to the Shopify webpage7driver.get("https://www.shopify.com/")89# Find the navigation menu element10nav_menu = driver.find_element_by_xpath("//ul[@class='site-nav__list']")1112# Find all link elements in the navigation menu13nav_links = nav_menu.find_elements_by_tag_name("a")1415# Loop through each link and check if it leads to the correct page16for link in nav_links:17 # Get the link URL18 url = link.get_attribute("href")19 20 # Open the link in a new tab21 link.click()22 driver.switch_to.window(driver.window_handles[-1])23 24 # Check if the URL of the new tab matches the expected URL25 assert driver.current_url == url, "Link not functional or leading to incorrect page"26 27 # Close the tab and switch back to the main window28 driver.close()29 driver.switch_to.window(driver.window_handles[0])3031# Close the driver32driver.quit()3334# Uncomment the following code to connect to a remote client with desired capabilities:35"""36from selenium.webdriver.common.desired_capabilities import DesiredCapabilities3738# Set desired capabilities39capabilities = DesiredCapabilities.CHROME.copy()40capabilities['version'] = '88.0'41capabilities['platform'] = 'Windows 10'42capabilities['name'] = 'Shopify Navigation Menu Test'4344# Connect to remote client45driver = webdriver.Remote(46 command_executor='http://127.0.0.1:4444/wd/hub',47 desired_capabilities=capabilities48)49 5051Assumptions:52- The navigation menu has a class name of "site-nav__list" and consists of a list of links.53- All links in the navigation menu are clickable and lead to a unique page URL.54- Opening a link in a new tab is acceptable for this test case.55- The expected URL for each link is the same as the link's href attribute.5657The code can be uncommented and modified to connect to a remote client with the desired capabilities.58"""
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