-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdLoadTimeTest.py
More file actions
executable file
·54 lines (43 loc) · 1.65 KB
/
AdLoadTimeTest.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import sys
if len(sys.argv)>1:
executable_path = sys.argv[1]
else:
executable_path = "windows/chromedriver.exe"
prefix = raw_input("file prefix:")
adblock = raw_input("ad block on? [y or n] ")
iterations = int(raw_input("number of iterations: "))
url = raw_input("url: ")
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
adblockprefix="AdBlockOff"
if adblock=='y':
chrome_options.add_extension('AdBlock_v3.8.4.crx')
adblockprefix="AdBlockOn"
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.set_window_size(1280, 760)
fName=prefix+"_"+adblockprefix+"_firstPaint_"+str(iterations)
f2Name=prefix+"_"+adblockprefix+"_loadEventEnd_"+str(iterations)
f = open(fName, 'w')
f2 = open(f2Name, 'w')
print "Test initiating, this can take a few seconds..."
if adblock=='y':
driver.execute_script("window.close();")
driver.switch_to_window(driver.window_handles[0])
for i in xrange(0,iterations):
driver.get(url)
if i==0:
print "skiping first request to avoid cache measurement discrepancies"
continue
t = driver.execute_script("return ((window.chrome.loadTimes().firstPaintTime * 1000 - window.performance.timing.navigationStart))")
t2 = driver.execute_script("return ((window.performance.timing.loadEventEnd - window.performance.timing.navigationStart))")
print "firstPaint: %d" % t
print "loadEventEnd: %d" % t2
f.write('%d\n' % t)
f2.write('%d\n' % t2)
f.close()
f2.close()