test: Update and improve Camo/Dynamic tests
This commit is contained in:
@@ -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 == 200
|
||||
assert (await fetcher.async_fetch(urls["status_404"])).status == 404
|
||||
assert (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 page
|
||||
|
||||
assert (
|
||||
await fetcher.async_fetch(urls["html_url"], page_action=scroll_page)
|
||||
await fetcher.async_fetch(urls["html_url"], page_action=scroll_page, humanize=True)
|
||||
).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
|
||||
)
|
||||
).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 == 200
|
||||
|
||||
async def test_infinite_timeout(self, fetcher, urls):
|
||||
"""Test if infinite timeout breaks the code or not"""
|
||||
|
||||
@@ -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.asyncio
|
||||
async 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.asyncio
|
||||
|
||||
@@ -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 == 200
|
||||
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 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 == 200
|
||||
|
||||
def test_infinite_timeout(self, fetcher):
|
||||
"""Test if infinite timeout breaks the code or not"""
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import 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):
|
||||
|
||||
Reference in New Issue
Block a user