Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selenium webdriver on WSL #99

Merged
merged 6 commits into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import enum
import json
import math
import os
import shutil
import socket
import subprocess
Expand Down Expand Up @@ -57,22 +58,48 @@ class AbstractWebTest(unittest.TestCase):
driver: webdriver.Firefox

def setUp(self) -> None:
if not self.reuse_selenium_web_driver():
opts = selenium.webdriver.firefox.options.Options()
opts.add_argument("-headless")
self.driver = webdriver.Firefox(options=opts)

self.server_runner = InterfaceThreadRunner(shc.web.WebServer, "localhost", 42080, 'index')
self.server = self.server_runner.interface

@classmethod
def setUpClass(cls) -> None:
opts = selenium.webdriver.firefox.options.Options()
opts.add_argument("-headless")
cls.driver = webdriver.Firefox(options=opts)
if cls.reuse_selenium_web_driver():
opts = selenium.webdriver.firefox.options.Options()
opts.add_argument("-headless")
cls.driver = webdriver.Firefox(options=opts)

def tearDown(self) -> None:
if not self.reuse_selenium_web_driver():
self.driver.close()
self.driver.quit()

self.server_runner.stop()

@classmethod
def tearDownClass(cls) -> None:
cls.driver.close()
cls.driver.quit()
if cls.reuse_selenium_web_driver():
cls.driver.close()
cls.driver.quit()

@staticmethod
def reuse_selenium_web_driver() -> bool:
"""Determine whether the selenium driver shall be shared between all consecutive tests in this class.

Checks whether the environment variable SHC_TEST_REUSE_WEB_DRIVER is set.
On WSL default ist not sharing the driver since this causes concurrency conflicts.
"""
if (value := os.getenv('SHC_TEST_REUSE_WEB_DRIVER')) is not None:
return value.strip().lower() in ['1', 'true', 'yes', 'on']

if "WSL_DISTRO_NAME" in os.environ or "WSL_INTEROP" in os.environ:
return False

return True


class SimpleWebTest(AbstractWebTest):
Expand Down