Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 70 lines (59 sloc) 2.48 KB
#!/usr/bin/env python
"""This script runs a series of tests using selenium and Chrome, both
on mobile and desktop.
To run it on desktop devices, you need to download Selenium's
ChromeDriver and put it somewhere in your PATH.
To run it in an android device, you need to:
Download Android SDK
export ANDROID_HOME=~/Android/Sdk
export PATH=~/Android/Sdk/platform-tools:$PATH
export JAVA_HOME=/usr/lib/jvm/default-java
Enable USB debugging in your phone, plug it via USB and make sure adb devices shows it
Change network settings if you want (eg. 3g, 4g, 2g)
npm install appium; appium
Disable screen lock on device
Run this script
import sys
import numpy as np
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def load_page(browser, url, times):
"""Load a page multiple times and show the load time gathered via the Navigation timing API"""
# let the browser adjust after initial load.
load_times = []
for idx in range(times):
load_time = browser.execute_script('''return new Date().getTime() - performance.timing.connectStart''')
print('{}/{}: {}'.format(idx, times, load_time))
print(' Median load time for {}: {:.2f}'.format(url, np.percentile(load_times, 50)))
print(' 95th percentile for {}: {:.2f}'.format(url, np.percentile(load_times, 95)))
print(' 99th percentile for {}: {:.2f}'.format(url, np.percentile(load_times, 99)))
if __name__ == '__main__':
USAGE = 'Usage: {} <mobile|desktop> <ntimes>'.format(sys.argv[0])
if len(sys.argv) != 3:
if not sys.argv[2].isdigit():
ntimes = int(sys.argv[2])
if sys.argv[1] == 'mobile':
browser = webdriver.Remote(
elif sys.argv[1] == 'desktop':
browser = webdriver.Chrome()
load_page(browser, '', ntimes)
load_page(browser, '', ntimes)