From e572938af349a51ff755d493203fce1d2ef777d5 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Wed, 17 Mar 2021 11:47:24 +0000 Subject: [PATCH] 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 --- test/cors/main.py | 12 +++++++++++- tools/playbooks/cors/run.yaml | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/cors/main.py b/test/cors/main.py index 8f4314d9f7..5da06ae681 100755 --- a/test/cors/main.py +++ b/test/cors/main.py @@ -180,9 +180,19 @@ def run(args, url): browsers = list(ALL_BROWSERS) if 'all' in args.browsers else args.browsers ran_one = False 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()) try: - browser = driver() + browser = driver(**kwargs) except Exception as e: if not ('needs to be in PATH' in str(e) or 'SafariDriver was not found' in str(e)): diff --git a/tools/playbooks/cors/run.yaml b/tools/playbooks/cors/run.yaml index a6076f82d9..cd8d73d092 100644 --- a/tools/playbooks/cors/run.yaml +++ b/tools/playbooks/cors/run.yaml @@ -9,7 +9,7 @@ - name: Run CORS tests shell: > - xvfb-run python + python {{ ansible_env.HOME }}/{{ zuul.project.src_dir }}/test/cors/main.py --output {{ ansible_env.HOME }}/cors-test-results.txt all