diff --git a/tests/conftest.py b/tests/conftest.py index b02d854..4e34829 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/helper.py b/tests/helper.py deleted file mode 100644 index 06d335b..0000000 --- a/tests/helper.py +++ /dev/null @@ -1,43 +0,0 @@ -import pytest -import shutil -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) diff --git a/tests/test_browser.py b/tests/test_browser.py index 596d413..23216d3 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1,6 +1,5 @@ from yadc.browser import Browser, TorBrowser import pytest -from helper import chrome, chromedriver, tor def run_test_browser(b): diff --git a/tests/test_undetected_browser.py b/tests/test_undetected_browser.py index baee857..084891f 100644 --- a/tests/test_undetected_browser.py +++ b/tests/test_undetected_browser.py @@ -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 @@ -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)