Skip to content

Commit

Permalink
Add BROWSER_NAME for local and remote execution
Browse files Browse the repository at this point in the history
Change the run command in the .yml file
  • Loading branch information
Ayima Okeeva committed Dec 3, 2024
1 parent 98ca5c9 commit 9b36bee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/selenium-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Run all tests


on:
workflow_dispatch:
push:
Expand All @@ -17,7 +18,7 @@ jobs:

services:
selenium:
image: selenium/standalone-chrome:latest
image: selenium/standalone-firefox:latest
ports:
- 4444:4444
options: >-
Expand All @@ -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
pytest tests/test_login.py -sv --headless
38 changes: 27 additions & 11 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit 9b36bee

Please sign in to comment.