diff --git a/.github/workflows/selenium-tests.yml b/.github/workflows/selenium-tests.yml index f37848b..ba89cbc 100644 --- a/.github/workflows/selenium-tests.yml +++ b/.github/workflows/selenium-tests.yml @@ -1,5 +1,6 @@ name: Run all tests + on: workflow_dispatch: push: @@ -17,7 +18,7 @@ jobs: services: selenium: - image: selenium/standalone-chrome:latest + image: selenium/standalone-firefox:latest ports: - 4444:4444 options: >- @@ -44,5 +45,6 @@ jobs: - name: Run Selenium tests env: SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub + BROWSER_NAME: firefox run: | - pytest tests/test_login.py -sv --headless --base-url http://localhost:4444/wd/hub \ No newline at end of file + pytest tests/test_login.py -sv --headless \ No newline at end of file diff --git a/conftest.py b/conftest.py index 0abdce9..45b3998 100644 --- a/conftest.py +++ b/conftest.py @@ -28,8 +28,9 @@ @pytest.fixture(scope="class", autouse=True) def setup(request, pytestconfig): """Fixture to set up the browser/webdriver""" - browser_name = os.environ.get("BROWSER_NAME") + browser_name = os.environ.get("BROWSER_NAME", "chrome") headless_mode = pytestconfig.getoption("--headless") + remote_url = os.environ.get("SELENIUM_REMOTE_URL") browser = None options = ChromeOptions() # Default to Chrome options @@ -38,25 +39,40 @@ def setup(request, pytestconfig): options.add_argument("--headless=new") options.add_argument("--no-sandbox") options.add_argument("--disable-gpu") - service = ChromeService(ChromeDriverManager().install()) - browser = webdriver.Chrome(service=service, options=options) + + if remote_url: + browser = webdriver.Remote( + command_executor=remote_url, + options=options + ) + else: + service = ChromeService(ChromeDriverManager().install()) + browser = webdriver.Chrome(service=service, options=options) + elif browser_name == "firefox": options = FirefoxOptions() if headless_mode: options.add_argument("--headless") options.set_preference("extensions.enabled", False) - service = FirefoxService(executable_path=GeckoDriverManager().install()) - browser = webdriver.Firefox(service=service, options=options) - elif browser_name == "headless": - options.add_argument("--headless") - options.add_argument("--no-sandbox") - options.add_argument("--disable-gpu") - service = ChromeService(ChromeDriverManager().install()) - browser = webdriver.Chrome(service=service, options=options) + if remote_url: + browser = webdriver.Remote( + command_executor=remote_url, + options=options + ) + else: + service = FirefoxService(executable_path=GeckoDriverManager().install()) + browser = webdriver.Firefox(service=service, options=options) else: raise ValueError("Invalid BROWSER_NAME: {}".format(browser_name)) + # elif browser_name == "headless": + # options.add_argument("--headless") + # options.add_argument("--no-sandbox") + # options.add_argument("--disable-gpu") + # service = ChromeService(ChromeDriverManager().install()) + # browser = webdriver.Chrome(service=service, options=options) + wait = WebDriverWait(browser, 10) if browser is not None: