🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
Python aiai-scrapingautomationcrawlercrawlingcrawling-pythondatadata-extractionmcpmcp-serverplaywrightpythonscrapingselectorsstealthweb-scraperweb-scrapingweb-scraping-pythonwebscrapingxpath
test: Update and improve Camo/Dynamic tests
Karim shoair4c33c4760946
diff --git a/tests/fetchers/async/test_camoufox.py b/tests/fetchers/async/test_camoufox.pyindex ff97fb8..3e5ba5c 100644--- a/tests/fetchers/async/test_camoufox.py+++ b/tests/fetchers/async/test_camoufox.py@@ -27,37 +27,11 @@ class TestStealthyFetcher:}async def test_basic_fetch(self, fetcher, urls):- """Test doing basic fetch request with multiple statuses"""+ """Test doing a basic fetch request with multiple statuses"""assert (await fetcher.async_fetch(urls["status_200"])).status == 200assert (await fetcher.async_fetch(urls["status_404"])).status == 404assert (await fetcher.async_fetch(urls["status_501"])).status == 501- async def test_networkidle(self, fetcher, urls):- """Test if waiting for `networkidle` make page does not finish loading or not"""- assert (- await fetcher.async_fetch(urls["basic_url"], network_idle=True)- ).status == 200-- async def test_blocking_resources(self, fetcher, urls):- """Test if blocking resources make page does not finish loading or not"""- assert (- await fetcher.async_fetch(urls["basic_url"], block_images=True)- ).status == 200- assert (- await fetcher.async_fetch(urls["basic_url"], disable_resources=True)- ).status == 200-- async def test_waiting_selector(self, fetcher, urls):- """Test if waiting for a selector make page does not finish loading or not"""- assert (- await fetcher.async_fetch(urls["html_url"], wait_selector="h1")- ).status == 200- assert (- await fetcher.async_fetch(- urls["html_url"], wait_selector="h1", wait_selector_state="visible"- )- ).status == 200-async def test_cookies_loading(self, fetcher, urls):"""Test if cookies are set after the request"""response = await fetcher.async_fetch(urls["cookies_url"])@@ -65,7 +39,7 @@ class TestStealthyFetcher:assert cookies == {"test": "value"}async def test_automation(self, fetcher, urls):- """Test if automation break the code or not"""+ """Test if automation breaks the code or not"""async def scroll_page(page):await page.mouse.wheel(10, 0)@@ -74,34 +48,38 @@ class TestStealthyFetcher:return pageassert (- await fetcher.async_fetch(urls["html_url"], page_action=scroll_page)- ).status == 200-- async def test_properties(self, fetcher, urls):- """Test if different arguments breaks the code or not"""- assert (- await fetcher.async_fetch(- urls["html_url"], block_webrtc=True, allow_webgl=True- )- ).status == 200-- assert (- await fetcher.async_fetch(- urls["html_url"], block_webrtc=False, allow_webgl=True- )- ).status == 200-- assert (- await fetcher.async_fetch(- urls["html_url"], block_webrtc=True, allow_webgl=False- )+ await fetcher.async_fetch(urls["html_url"], page_action=scroll_page, humanize=True)).status == 200- assert (- await fetcher.async_fetch(- urls["html_url"], extra_headers={"ayo": ""}, os_randomize=True- )- ).status == 200+ @pytest.mark.parametrize(+ "kwargs",+ [+ {"block_webrtc": True, "allow_webgl": True, "disable_ads": False},+ {"block_webrtc": False, "allow_webgl": True, "block_images": True},+ {"block_webrtc": True, "allow_webgl": False, "disable_resources": True},+ {"block_images": True, "disable_resources": True, },+ {"wait_selector": "h1", "wait_selector_state": "attached"},+ {"wait_selector": "h1", "wait_selector_state": "visible"},+ {+ "network_idle": True,+ "wait": 10,+ "cookies": [],+ "google_search": True,+ "extra_headers": {"ayo": ""},+ "os_randomize": True,+ "disable_ads": True,+ "custom_config": {"keep_comments": False, "keep_cdata": False},+ "additional_args": {"window": (1920, 1080)},+ },+ ],+ )+ async def test_properties(self, fetcher, urls, kwargs):+ """Test if different arguments break the code or not"""+ response = await fetcher.async_fetch(+ urls["html_url"],+ **kwargs+ )+ assert response.status == 200async def test_infinite_timeout(self, fetcher, urls):"""Test if infinite timeout breaks the code or not"""diff --git a/tests/fetchers/async/test_dynamic.py b/tests/fetchers/async/test_dynamic.pyindex 5755136..70716e3 100644--- a/tests/fetchers/async/test_dynamic.py+++ b/tests/fetchers/async/test_dynamic.py@@ -30,29 +30,6 @@ class TestDynamicFetcherAsync:response = await fetcher.async_fetch(urls["status_200"])assert response.status == 200- @pytest.mark.asyncio- async def test_networkidle(self, fetcher, urls):- """Test if waiting for `networkidle` make page does not finish loading or not"""- response = await fetcher.async_fetch(urls["basic_url"], network_idle=True)- assert response.status == 200-- @pytest.mark.asyncio- async def test_blocking_resources(self, fetcher, urls):- """Test if blocking resources make the page does not finish loading or not"""- response = await fetcher.async_fetch(urls["basic_url"], disable_resources=True)- assert response.status == 200-- @pytest.mark.asyncio- async def test_waiting_selector(self, fetcher, urls):- """Test if waiting for a selector make page does not finish loading or not"""- response1 = await fetcher.async_fetch(urls["html_url"], wait_selector="h1")- assert response1.status == 200-- response2 = await fetcher.async_fetch(- urls["html_url"], wait_selector="h1", wait_selector_state="visible"- )- assert response2.status == 200-@pytest.mark.asyncioasync def test_cookies_loading(self, fetcher, urls):"""Test if cookies are set after the request"""@@ -77,12 +54,21 @@ class TestDynamicFetcherAsync:"kwargs",[{"disable_webgl": True, "hide_canvas": False},- {"disable_webgl": False, "hide_canvas": True},+ {"disable_webgl": False, "hide_canvas": True, "disable_resources": True},{"stealth": True}, # causes issues with GitHub Actions+ {"wait_selector": "h1", "wait_selector_state": "attached"},+ {"wait_selector": "h1", "wait_selector_state": "visible"},{- "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"+ "google_search": True,+ "real_chrome": True,+ "wait": 10,+ "locale": "en-US",+ "extra_headers": {"ayo": ""},+ "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0",+ "cookies": [],+ "network_idle": True,+ "custom_config": {"keep_comments": False, "keep_cdata": False},},- {"extra_headers": {"ayo": ""}},],)@pytest.mark.asynciodiff --git a/tests/fetchers/sync/test_camoufox.py b/tests/fetchers/sync/test_camoufox.pyindex d15cd93..0c5cc86 100644--- a/tests/fetchers/sync/test_camoufox.py+++ b/tests/fetchers/sync/test_camoufox.py@@ -25,30 +25,11 @@ class TestStealthyFetcher:self.cookies_url = f"{httpbin.url}/cookies/set/test/value"def test_basic_fetch(self, fetcher):- """Test doing basic fetch request with multiple statuses"""+ """Test doing a basic fetch request with multiple statuses"""assert fetcher.fetch(self.status_200).status == 200assert fetcher.fetch(self.status_404).status == 404assert fetcher.fetch(self.status_501).status == 501- def test_networkidle(self, fetcher):- """Test if waiting for `networkidle` make page does not finish loading or not"""- assert fetcher.fetch(self.basic_url, network_idle=True).status == 200-- def test_blocking_resources(self, fetcher):- """Test if blocking resources make page does not finish loading or not"""- assert fetcher.fetch(self.basic_url, block_images=True).status == 200- assert fetcher.fetch(self.basic_url, disable_resources=True).status == 200-- def test_waiting_selector(self, fetcher):- """Test if waiting for a selector make page does not finish loading or not"""- assert fetcher.fetch(self.html_url, wait_selector="h1").status == 200- assert (- fetcher.fetch(- self.html_url, wait_selector="h1", wait_selector_state="visible"- ).status- == 200- )-def test_cookies_loading(self, fetcher):"""Test if cookies are set after the request"""response = fetcher.fetch(self.cookies_url)@@ -66,26 +47,35 @@ class TestStealthyFetcher:assert fetcher.fetch(self.html_url, page_action=scroll_page).status == 200- def test_properties(self, fetcher):- """Test if different arguments breaks the code or not"""- assert (- fetcher.fetch(self.html_url, block_webrtc=True, allow_webgl=True).status- == 200- )- assert (- fetcher.fetch(self.html_url, block_webrtc=False, allow_webgl=True).status- == 200- )- assert (- fetcher.fetch(self.html_url, block_webrtc=True, allow_webgl=False).status- == 200- )- assert (- fetcher.fetch(- self.html_url, extra_headers={"ayo": ""}, os_randomize=True- ).status- == 200+ @pytest.mark.parametrize(+ "kwargs",+ [+ {"block_webrtc": True, "allow_webgl": True, "disable_ads": False},+ {"block_webrtc": False, "allow_webgl": True, "block_images": True},+ {"block_webrtc": True, "allow_webgl": False, "disable_resources": True},+ {"block_images": True, "disable_resources": True, },+ {"wait_selector": "h1", "wait_selector_state": "attached"},+ {"wait_selector": "h1", "wait_selector_state": "visible"},+ {+ "network_idle": True,+ "wait": 10,+ "cookies": [],+ "google_search": True,+ "extra_headers": {"ayo": ""},+ "os_randomize": True,+ "disable_ads": True,+ "custom_config": {"keep_comments": False, "keep_cdata": False},+ "additional_args": {"window": (1920, 1080)},+ },+ ],+ )+ def test_properties(self, fetcher, kwargs):+ """Test if different arguments break the code or not"""+ response = fetcher.fetch(+ self.html_url,+ **kwargs)+ assert response.status == 200def test_infinite_timeout(self, fetcher):"""Test if infinite timeout breaks the code or not"""diff --git a/tests/fetchers/sync/test_dynamic.py b/tests/fetchers/sync/test_dynamic.pyindex 2f73361..2079647 100644--- a/tests/fetchers/sync/test_dynamic.py+++ b/tests/fetchers/sync/test_dynamic.py@@ -1,5 +1,3 @@-import os-import pytestimport pytest_httpbin@@ -33,24 +31,6 @@ class TestDynamicFetcher:# assert fetcher.fetch(self.status_404).status == 404# assert fetcher.fetch(self.status_501).status == 501- def test_networkidle(self, fetcher):- """Test if waiting for `networkidle` make page does not finish loading or not"""- assert fetcher.fetch(self.basic_url, network_idle=True).status == 200-- def test_blocking_resources(self, fetcher):- """Test if blocking resources make the page does not finish loading or not"""- assert fetcher.fetch(self.basic_url, disable_resources=True).status == 200-- def test_waiting_selector(self, fetcher):- """Test if waiting for a selector make page does not finish loading or not"""- assert fetcher.fetch(self.html_url, wait_selector="h1").status == 200- assert (- fetcher.fetch(- self.html_url, wait_selector="h1", wait_selector_state="visible"- ).status- == 200- )-def test_cookies_loading(self, fetcher):"""Test if cookies are set after the request"""response = fetcher.fetch(self.cookies_url)@@ -72,12 +52,21 @@ class TestDynamicFetcher:"kwargs",[{"disable_webgl": True, "hide_canvas": False},- {"disable_webgl": False, "hide_canvas": True},+ {"disable_webgl": False, "hide_canvas": True, "disable_resources": True},{"stealth": True}, # causes issues with GitHub Actions+ {"wait_selector": "h1", "wait_selector_state": "attached"},+ {"wait_selector": "h1", "wait_selector_state": "visible"},{- "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"+ "google_search": True,+ "real_chrome": True,+ "wait": 10,+ "locale": "en-US",+ "extra_headers": {"ayo": ""},+ "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0",+ "cookies": [],+ "network_idle": True,+ "custom_config": {"keep_comments": False, "keep_cdata": False},},- {"extra_headers": {"ayo": ""}},],)def test_properties(self, fetcher, kwargs):