Skip to content

Commit 7200405

Browse files
committed
Merge branch 'master' of github.com:WPO-Foundation/wptagent
2 parents 242c35a + 852122d commit 7200405

28 files changed

Lines changed: 407 additions & 165 deletions

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN apt-get update && \
4444
google-chrome-unstable \
4545
firefox \
4646
firefox-trunk \
47+
firefox-geckodriver \
4748
opera-stable \
4849
opera-beta \
4950
opera-developer \
@@ -69,6 +70,7 @@ RUN apt-get update && \
6970
brotli \
7071
'fonttools>=3.44.0,<4.0.0' \
7172
marionette_driver \
73+
selenium \
7274
future
7375

7476
COPY wptagent.py /wptagent/wptagent.py

internal/adb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from threading import Timer
1313
import time
14-
if (sys.version_info > (3, 0)):
14+
if (sys.version_info >= (3, 0)):
1515
from time import monotonic
1616
else:
1717
from monotonic import monotonic
@@ -140,7 +140,7 @@ def start(self):
140140
self.simplert_path = None
141141
if self.options.simplert is not None and platform.system() == 'Linux':
142142
running = False
143-
if (sys.version_info > (3, 0)):
143+
if (sys.version_info >= (3, 0)):
144144
stdout = subprocess.check_output(['ps', 'ax'], encoding='UTF-8')
145145
else:
146146
stdout = subprocess.check_output(['ps', 'ax'])

internal/android_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import subprocess
1212
import sys
1313
import time
14-
if (sys.version_info > (3, 0)):
14+
if (sys.version_info >= (3, 0)):
1515
from time import monotonic
1616
GZIP_TEXT = 'wt'
1717
else:

internal/blackbox_android.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99
import sys
1010
import time
11-
if (sys.version_info > (3, 0)):
11+
if (sys.version_info >= (3, 0)):
1212
from time import monotonic
1313
else:
1414
from monotonic import monotonic

internal/browsers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ def get_browser(self, name, job):
8080
elif name in self.browsers and 'exe' in self.browsers[name]:
8181
job['browser_info'] = self.browsers[name]
8282
if 'type' in self.browsers[name] and self.browsers[name]['type'] == 'Firefox':
83-
from .firefox import Firefox
84-
browser = Firefox(self.browsers[name]['exe'], self.options, job)
83+
if self.options.webdriver:
84+
from .firefox_webdriver import FirefoxWebDriver
85+
browser = FirefoxWebDriver(self.browsers[name]['exe'], self.options, job)
86+
else:
87+
from .firefox import Firefox
88+
browser = Firefox(self.browsers[name]['exe'], self.options, job)
8589
elif 'type' in self.browsers[name] and self.browsers[name]['type'] == 'Edge':
8690
from .microsoft_edge import Edge
8791
browser = Edge(self.browsers[name]['exe'], self.options, job)

internal/chrome_android.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import shutil
1111
import sys
1212
import time
13-
if (sys.version_info > (3, 0)):
13+
if (sys.version_info >= (3, 0)):
1414
from time import monotonic
1515
else:
1616
from monotonic import monotonic

internal/desktop_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sys
1717
import threading
1818
import time
19-
if (sys.version_info > (3, 0)):
19+
if (sys.version_info >= (3, 0)):
2020
from time import monotonic
2121
GZIP_TEXT = 'wt'
2222
else:
@@ -685,7 +685,7 @@ def process_pcap(self):
685685
cmd = ['python', pcap_parser, '--json', '-i', pcap_file, '-d', slices_file]
686686
logging.debug(cmd)
687687
try:
688-
if (sys.version_info > (3, 0)):
688+
if (sys.version_info >= (3, 0)):
689689
stdout = subprocess.check_output(cmd, encoding='UTF-8')
690690
else:
691691
stdout = subprocess.check_output(cmd)

internal/devtools.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414
import time
1515
import zipfile
16-
if (sys.version_info > (3, 0)):
16+
if (sys.version_info >= (3, 0)):
1717
from time import monotonic
1818
from urllib.parse import urlsplit # pylint: disable=import-error
1919
unicode = str
@@ -82,9 +82,6 @@ def prepare(self):
8282
self.response_bodies = {}
8383
self.nav_error = None
8484
self.nav_error_code = None
85-
self.main_request = None
86-
self.main_request_headers = None
87-
self.response_started = False
8885
self.start_timestamp = None
8986
self.path_base = os.path.join(self.task['dir'], self.task['prefix'])
9087
self.support_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "support")
@@ -754,9 +751,13 @@ def wait_for_page_load(self):
754751
pass
755752
now = monotonic()
756753
elapsed_test = now - start_time
754+
if 'minimumTestSeconds' in self.task and \
755+
elapsed_test < self.task['minimumTestSeconds'] and \
756+
now < end_time:
757+
continue
757758
if self.nav_error is not None:
758759
done = True
759-
if self.page_loaded is None:
760+
if self.page_loaded is None or 'minimumTestSeconds' in self.task:
760761
self.task['error'] = self.nav_error
761762
if self.nav_error_code is not None:
762763
self.task['page_data']['result'] = self.nav_error_code
@@ -768,7 +769,7 @@ def wait_for_page_load(self):
768769
if self.page_loaded is None:
769770
self.task['error'] = "Page Load Timeout"
770771
self.task['page_data']['result'] = 99997
771-
elif 'time' not in self.job or elapsed_test > self.job['time']:
772+
else:
772773
elapsed_activity = now - self.last_activity
773774
elapsed_page_load = now - self.page_loaded if self.page_loaded else 0
774775
if elapsed_page_load >= 1 and elapsed_activity >= self.task['activity_time']:

internal/devtools_browser.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import sys
1515
import threading
1616
import time
17-
if (sys.version_info > (3, 0)):
17+
if (sys.version_info >= (3, 0)):
1818
from time import monotonic
1919
from urllib.parse import urlsplit # pylint: disable=import-error
2020
unicode = str
@@ -128,8 +128,12 @@ def prepare_browser(self, task):
128128
wait=True)
129129

130130
# DevTools-based CPU throttling for desktop and emulated mobile tests
131+
# This throttling should only be applied for:
132+
# 1. Normal test runs where cgroups throttling (--throttle) is disabled
133+
# 2. Lighthouse test runs where a custom config path is not specified
131134
if not self.options.android and \
132135
(task['running_lighthouse'] or not self.options.throttle) and \
136+
(not task['running_lighthouse'] or not self.job['lighthouse_config']) and \
133137
'throttle_cpu' in self.job:
134138
logging.debug('DevTools CPU Throttle target: %0.3fx', self.job['throttle_cpu'])
135139
if self.job['throttle_cpu'] > 1:
@@ -340,7 +344,7 @@ def strip_non_text(self, data):
340344
self.strip_non_text(entry)
341345
elif isinstance(entry, str) or isinstance(entry, unicode):
342346
try:
343-
if (sys.version_info > (3, 0)):
347+
if (sys.version_info >= (3, 0)):
344348
entry.encode('utf-8').decode('utf-8')
345349
else:
346350
entry.decode('utf-8')
@@ -358,7 +362,7 @@ def strip_non_text(self, data):
358362
self.strip_non_text(entry)
359363
elif isinstance(entry, str) or isinstance(entry, unicode):
360364
try:
361-
if (sys.version_info > (3, 0)):
365+
if (sys.version_info >= (3, 0)):
362366
entry.encode('utf-8').decode('utf-8')
363367
else:
364368
entry.decode('utf-8')
@@ -498,6 +502,8 @@ def process_command(self, command):
498502
if 'target' in command:
499503
milliseconds = int(re.search(r'\d+', str(command['target'])).group())
500504
self.task['activity_time'] = max(0, min(30, float(milliseconds) / 1000.0))
505+
elif command['command'] == 'setminimumstepseconds':
506+
self.task['minimumTestSeconds'] = int(re.search(r'\d+', str(command['target'])).group())
501507
elif command['command'] == 'setuseragent':
502508
self.task['user_agent_string'] = command['target']
503509
elif command['command'] == 'setcookie':
@@ -574,7 +580,8 @@ def run_lighthouse_test(self, task):
574580
"""Run a lighthouse test against the current browser session"""
575581
task['lighthouse_log'] = ''
576582
if 'url' in self.job and self.job['url'] is not None:
577-
self.job['shaper'].configure(self.job, task)
583+
if not self.job['lighthouse_config']:
584+
self.job['shaper'].configure(self.job, task)
578585
output_path = os.path.join(task['dir'], 'lighthouse.json')
579586
json_file = os.path.join(task['dir'], 'lighthouse.report.json')
580587
json_gzip = os.path.join(task['dir'], 'lighthouse.json.gz')
@@ -584,24 +591,33 @@ def run_lighthouse_test(self, task):
584591
command = ['lighthouse',
585592
'"{0}"'.format(self.job['url']),
586593
'--channel', 'wpt',
587-
'--disable-network-throttling',
588-
'--disable-cpu-throttling',
589-
'--throttling-method', 'provided',
590594
'--enable-error-reporting',
591595
'--max-wait-for-load', str(int(time_limit * 1000)),
592596
'--port', str(task['port']),
593597
'--output', 'html',
594598
'--output', 'json',
595599
'--output-path', '"{0}"'.format(output_path)]
600+
if self.job['lighthouse_config']:
601+
try:
602+
lighthouse_config_file = os.path.join(task['dir'], 'lighthouse-config.json')
603+
with open(lighthouse_config_file, 'wt') as f_out:
604+
json.dump(json.loads(self.job['lighthouse_config']), f_out)
605+
command.extend(['--config-path', lighthouse_config_file])
606+
except Exception:
607+
logging.exception('Error adding custom config for lighthouse test')
608+
else:
609+
command.extend(['--throttling-method', 'provided'])
596610
if self.job['keep_lighthouse_trace']:
597611
command.append('--save-assets')
598612
if not self.job['keep_lighthouse_screenshots']:
599613
command.extend(['--skip-audits', 'screenshot-thumbnails'])
600-
if self.options.android or 'mobile' not in self.job or not self.job['mobile']:
614+
if self.options.android:
601615
command.extend(['--emulated-form-factor', 'none'])
602616
if 'user_agent_string' in self.job:
603617
sanitized_user_agent = re.sub(r'[^a-zA-Z0-9_\-.;:/()\[\] ]+', '', self.job['user_agent_string'])
604618
command.append('--chrome-flags="--user-agent=\'{0}\'"'.format(sanitized_user_agent))
619+
elif 'mobile' not in self.job or not self.job['mobile']:
620+
command.extend(['--emulated-form-factor', 'desktop'])
605621
if len(task['block']):
606622
for pattern in task['block']:
607623
pattern = "'" + pattern.replace("'", "'\\''") + "'"

0 commit comments

Comments
 (0)