mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
replace selenium with nodriver
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
"""
|
||||
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from kleinanzeigen_bot.selenium_mixin import SeleniumMixin
|
||||
from kleinanzeigen_bot import utils
|
||||
|
||||
|
||||
@pytest.mark.itest
|
||||
def test_webdriver_auto_init():
|
||||
selenium_mixin = SeleniumMixin()
|
||||
selenium_mixin.browser_config.arguments = ["--no-sandbox"]
|
||||
|
||||
browser_path = selenium_mixin.get_compatible_browser()
|
||||
utils.ensure(browser_path is not None, "Browser not auto-detected")
|
||||
|
||||
selenium_mixin.webdriver = None
|
||||
selenium_mixin.create_webdriver_session()
|
||||
selenium_mixin.webdriver.quit()
|
||||
@@ -3,12 +3,11 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||
"""
|
||||
import os, sys, time
|
||||
import pytest
|
||||
from kleinanzeigen_bot import utils
|
||||
|
||||
|
||||
def test_ensure():
|
||||
def test_ensure() -> None:
|
||||
utils.ensure(True, "TRUE")
|
||||
utils.ensure("Some Value", "TRUE")
|
||||
utils.ensure(123, "TRUE")
|
||||
@@ -29,13 +28,3 @@ def test_ensure():
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
utils.ensure(lambda: False, "FALSE", timeout = 2)
|
||||
|
||||
|
||||
def test_pause():
|
||||
start = time.time()
|
||||
utils.pause(100, 100)
|
||||
elapsed = 1000 * (time.time() - start)
|
||||
if sys.platform == "darwin" and os.getenv("GITHUB_ACTIONS", "true") == "true":
|
||||
assert 99 < elapsed < 300
|
||||
else:
|
||||
assert 99 < elapsed < 120
|
||||
|
||||
41
tests/test_web_scraping_mixin.py
Normal file
41
tests/test_web_scraping_mixin.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
||||
"""
|
||||
import logging, os, time
|
||||
from typing import Any
|
||||
|
||||
import nodriver, pytest
|
||||
from flaky import flaky
|
||||
|
||||
from kleinanzeigen_bot.web_scraping_mixin import WebScrapingMixin
|
||||
from kleinanzeigen_bot.utils import ensure
|
||||
|
||||
if os.environ.get("CI"):
|
||||
logging.getLogger("kleinanzeigen_bot").setLevel(logging.DEBUG)
|
||||
logging.getLogger("nodriver").setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
def delay_rerun(*args:Any) -> bool: # pylint: disable=unused-argument
|
||||
time.sleep(5)
|
||||
return True
|
||||
|
||||
|
||||
async def atest_init() -> None:
|
||||
web_scraping_mixin = WebScrapingMixin()
|
||||
|
||||
browser_path = web_scraping_mixin.get_compatible_browser()
|
||||
ensure(browser_path is not None, "Browser not auto-detected")
|
||||
|
||||
web_scraping_mixin.close_browser_session()
|
||||
try:
|
||||
await web_scraping_mixin.create_browser_session()
|
||||
finally:
|
||||
web_scraping_mixin.close_browser_session()
|
||||
|
||||
|
||||
@flaky(max_runs = 3, min_passes = 1, rerun_filter = delay_rerun) # type: ignore[misc] # mypy
|
||||
@pytest.mark.itest
|
||||
def test_init() -> None:
|
||||
nodriver.loop().run_until_complete(atest_init())
|
||||
Reference in New Issue
Block a user