This test case checks that the site's performance is consistent across different mobile browsers, ensuring that customers can access the site easily regardless of the browser they are using.
Language: Java
Framework: Selenium 4
1Assumptions: 2- The site is already loaded on the mobile browsers that are being tested. 3- The mobile browsers being tested are Chrome and Safari.4- The device being used to test is an iPhone X with iOS 14.0.56//code to initiate local browser driver7System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");8DriverManager.setWebDriver(new ChromeDriver());910//code to initiate remote browser driver11DesiredCapabilities capabilities = DesiredCapabilities.iphone();12//Add necessary desired capabilities13RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL("https://your-grid-url.com/wd/hub"), capabilities);14//Navigate to the Shopify site on Chrome browser15DriverManager.getWebDriver().get("https://www.shopify.com/");16Thread.sleep(5000); //wait for page to load1718//test Shopify's performance on Chrome browser19String chromePageLoadTime = DriverManager.getWebDriver().executeJavaScript("return window.performance.timing.loadEventEnd - window.performance.timing.navigationStart").toString();20System.out.println("Page load time on Chrome browser: " + chromePageLoadTime + "ms");2122//Navigate to the Shopify site on Safari browser23DriverManager.getWebDriver().navigate().to("https://www.shopify.com/");24Thread.sleep(5000); //wait for page to load2526//test Shopify's performance on Safari browser27String safariPageLoadTime = DriverManager.getWebDriver().executeJavaScript("return window.performance.timing.loadEventEnd - window.performance.timing.navigationStart").toString();28System.out.println("Page load time on Safari browser: " + safariPageLoadTime + "ms"); 2930//close the browser driver31DriverManager.getWebDriver().quit();
Language: Python
Framework: Selenium 4
1#Assuming the URL for the Shopify page2url = "https://www.shopify.com/"34#Assuming mobiles to be android and iOS and browser to be Chrome and Safari56from selenium import webdriver7from selenium.webdriver.chrome.options import Options as ChromeOptions8from selenium.webdriver.common.desired_capabilities import DesiredCapabilities9from selenium.webdriver.common.keys import Keys10from selenium.webdriver.support.ui import WebDriverWait11from selenium.webdriver.support import expected_conditions as EC12from selenium.webdriver.common.by import By13import time1415#Mobile Emulation for Android16chrome_options = ChromeOptions()17chrome_options.add_experimental_option('mobileEmulation', {'deviceName': 'Google Pixel 2'})18driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", options=chrome_options)1920#Wait for page to load21driver.implicitly_wait(10)2223#Navigate to URL24driver.get(url)2526#Get performance metrics27perf_metrics_android_chrome = driver.execute_script("return window.performance.timing")2829#Close the emulated browser30driver.quit()3132#Mobile Emulation for iOS33chrome_options = ChromeOptions()34chrome_options.add_experimental_option('mobileEmulation', {'deviceName': 'iPhone X'})35driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", options=chrome_options)3637#Wait for page to load38driver.implicitly_wait(10)3940#Navigate to URL41driver.get(url)4243#Get performance metrics44perf_metrics_ios_safari = driver.execute_script("return window.performance.timing")4546#Close the emulated browser47driver.quit()4849#Print the performance metrics for both the mobile emulations5051print("Performance Metrics for Android - Chrome: \n", perf_metrics_android_chrome)52print("\n")53print("Performance Metrics for iOS - Safari: \n", perf_metrics_ios_safari)5455#Assuming to connect to remote client with Desired Capabilities56capabilities = DesiredCapabilities.CHROME.copy()57capabilities['platform'] = "WINDOWS"58capabilities['version'] = "10"59driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capabilities)6061#Wait for page to load62driver.implicitly_wait(10)6364#Navigate to URL65driver.get(url)6667#Get performance metrics68perf_metrics_remote = driver.execute_script("return window.performance.timing")6970#Close the remote browser71driver.quit()7273#Print the performance metrics for the remote client74print("\n")75print("Performance Metrics for Remote Client: \n", perf_metrics_remote)
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