-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing some of the new tests on Github action
- Loading branch information
Showing
5 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
pytest | ||
pytest-cov | ||
pytest-cov | ||
playwright | ||
camoufox | ||
pytest-httpbin | ||
pytest-playwright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Because I'm too lazy to mock requests :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import unittest | ||
import pytest_httpbin | ||
|
||
from scrapling import StealthyFetcher | ||
|
||
|
||
@pytest_httpbin.use_class_based_httpbin | ||
# @pytest_httpbin.use_class_based_httpbin_secure | ||
class TestParser(unittest.TestCase): | ||
def setUp(self): | ||
self.fetcher = StealthyFetcher(auto_match=False) | ||
# httpsbin = self.httpbin_secure.url | ||
url = self.httpbin.url | ||
self.status_200 = f'{url}/status/200' | ||
self.status_404 = f'{url}/status/404' | ||
self.status_501 = f'{url}/status/501' | ||
self.basic_url = f'{url}/get' | ||
self.html_url = f'{url}/html' | ||
|
||
def test_basic_fetch(self): | ||
"""Test doing basic fetch request with multiple statuses""" | ||
self.assertEqual(self.fetcher.fetch(self.status_200).status, 200) | ||
self.assertEqual(self.fetcher.fetch(self.status_404).status, 404) | ||
self.assertEqual(self.fetcher.fetch(self.status_501).status, 501) | ||
|
||
def test_networkidle(self): | ||
"""Test if waiting for `networkidle` make page does not finish loading or not""" | ||
self.assertEqual(self.fetcher.fetch(self.basic_url, network_idle=True).status, 200) | ||
|
||
def test_blocking_resources(self): | ||
"""Test if blocking resources make page does not finish loading or not""" | ||
self.assertEqual(self.fetcher.fetch(self.basic_url, block_images=True).status, 200) | ||
self.assertEqual(self.fetcher.fetch(self.basic_url, disable_resources=True).status, 200) | ||
|
||
def test_waiting_selector(self): | ||
"""Test if waiting for a selector make page does not finish loading or not""" | ||
self.assertEqual(self.fetcher.fetch(self.html_url, wait_selector='h1').status, 200) | ||
|
||
def test_automation(self): | ||
"""Test if automation break the code or not""" | ||
def scroll_page(page): | ||
page.mouse.wheel(10, 0) | ||
page.mouse.move(100, 400) | ||
page.mouse.up() | ||
return page | ||
|
||
self.assertEqual(self.fetcher.fetch(self.html_url, page_action=scroll_page).status, 200) | ||
|
||
def test_properties(self): | ||
"""Test if different arguments breaks the code or not""" | ||
self.assertEqual(self.fetcher.fetch(self.html_url, block_webrtc=True, allow_webgl=True).status, 200) | ||
self.assertEqual(self.fetcher.fetch(self.html_url, block_webrtc=False, allow_webgl=True).status, 200) | ||
self.assertEqual(self.fetcher.fetch(self.html_url, block_webrtc=True, allow_webgl=False).status, 200) | ||
|
||
def test_infinite_timeout(self): | ||
"""Test if infinite timeout breaks the code or not""" | ||
self.assertEqual(self.fetcher.fetch(self.html_url, timeout=None).status, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters