Use headless option for cors functional test runner

Some selenium webdrivers (e.g. Chrome, Firefox) support a headless
option so we can expose that as an option for the test runner too.

Use this in an attempt to fix "Error: cannot open display: :99" errors
seen in the gate.

Related-Bug: #1918864
Change-Id: I2a549ce829eb0bc38406575582202e1d8dd1a0e2
This commit is contained in:
Alistair Coles 2021-03-17 11:47:24 +00:00 committed by Tim Burke
parent 354a86a80e
commit e572938af3
2 changed files with 12 additions and 2 deletions

View File

@ -180,9 +180,19 @@ def run(args, url):
browsers = list(ALL_BROWSERS) if 'all' in args.browsers else args.browsers browsers = list(ALL_BROWSERS) if 'all' in args.browsers else args.browsers
ran_one = False ran_one = False
for browser_name in browsers: for browser_name in browsers:
kwargs = {}
try:
options = getattr(
selenium.webdriver, browser_name.title() + 'Options')()
options.headless = True
kwargs['options'] = options
except AttributeError:
# not all browser types have Options class
pass
driver = getattr(selenium.webdriver, browser_name.title()) driver = getattr(selenium.webdriver, browser_name.title())
try: try:
browser = driver() browser = driver(**kwargs)
except Exception as e: except Exception as e:
if not ('needs to be in PATH' in str(e) or if not ('needs to be in PATH' in str(e) or
'SafariDriver was not found' in str(e)): 'SafariDriver was not found' in str(e)):

View File

@ -9,7 +9,7 @@
- name: Run CORS tests - name: Run CORS tests
shell: > shell: >
xvfb-run python python
{{ ansible_env.HOME }}/{{ zuul.project.src_dir }}/test/cors/main.py {{ ansible_env.HOME }}/{{ zuul.project.src_dir }}/test/cors/main.py
--output {{ ansible_env.HOME }}/cors-test-results.txt --output {{ ansible_env.HOME }}/cors-test-results.txt
all all