Skip to content

Commit

Permalink
refactor: move fixtures to conftest.
Browse files Browse the repository at this point in the history
  • Loading branch information
2e0byo committed Jan 27, 2022
1 parent 0aea744 commit 0894321
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 60 deletions.
43 changes: 43 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
from pathlib import Path
import sys
import pytest
import shutil

sys.path.insert(0, str(Path(__file__).parent.parent))
from yadc.browser import Browser


def executable_path(*tries):
"""Find path to executable, or throw."""
path = None
for ex in tries:
path = shutil.which(ex)
if path:
break

if not path:
raise Exception(f"Unable to find path to {tries[0]}")

return path


@pytest.fixture
def chrome():
return executable_path(
"chrome",
"chromium",
"google-chrome-stable",
"chrome.exe",
r"C:\Program Files\Google\Chrome\Application\chrome.exe",
)


@pytest.fixture
def chromedriver():
return executable_path("chromedriver", "chromedriver.exe")


@pytest.fixture
def tor():
return executable_path("tor", "Tor/tor.exe")


@pytest.fixture
def browser(chrome, chromedriver):
return Browser(chrome=chrome, chromedriver=chromedriver)
43 changes: 0 additions & 43 deletions tests/helper.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from yadc.browser import Browser, TorBrowser
import pytest
from helper import chrome, chromedriver, tor


def run_test_browser(b):
Expand Down
61 changes: 45 additions & 16 deletions tests/test_undetected_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@

import pytest
from selenium.webdriver.common.by import By
from yadc.undetected_browser import ManualBusterUndetectedBrowser
from yadc.undetected_browser import (
ManualBusterUndetectedBrowser,
ManualBusterUndetectedTorBrowser,
UndetectedBrowser,
UndetectedTorBrowser,
)


@pytest.mark.graphical
@pytest.mark.manual
def test_manual_buster_undetected_browser(tmp_path):
br = ManualBusterUndetectedBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
def run_browser_test(browser):
unique_url = (
"chrome-extension://mpbjkejclgfgadiemmefgebjfooflfhl/src/options/index.html"
)
with br as driver:
with browser as driver:
driver.get(unique_url)
assert "Buster" in driver.page_source
driver.get("https://www.google.com")
assert "google" in driver.page_source.lower()
assert "Google Search" in driver.page_source


@pytest.mark.graphical
@pytest.mark.manual
def test_manual_buster_undetected_browser(tmp_path):
br = ManualBusterUndetectedBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
run_browser_test(br)


@pytest.mark.graphical
Expand All @@ -27,11 +36,31 @@ def test_automated_manual_buster_undetected_browser(tmp_path):
br = ManualBusterUndetectedBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
unique_url = (
"chrome-extension://mpbjkejclgfgadiemmefgebjfooflfhl/src/options/index.html"
run_browser_test(br)


@pytest.mark.graphical
@pytest.mark.manual
def test_manual_buster_undetected_tor_browser(tmp_path):
br = ManualBusterUndetectedTorBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
with br as driver:
driver.get(unique_url)
assert "Buster" in driver.page_source
driver.get("https://www.google.com")
assert "google" in driver.page_source.lower()
run_browser_test(br)


@pytest.mark.graphical
def test_automated_manual_buster_undetected_tor_browser(tmp_path):
shutil.copytree("tests/blank-profile", tmp_path / "blank-profile")
br = ManualBusterUndetectedTorBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
run_browser_test(br)


@pytest.mark.graphical
def test_automated_manual_buster_undetected_tor_browser(tmp_path):
shutil.copytree("tests/blank-profile", tmp_path / "blank-profile")
br = ManualBusterUndetectedTorBrowser(
buster=True, profile_dir=(tmp_path) / "blank-profile"
)
run_browser_test(br)

0 comments on commit 0894321

Please sign in to comment.