Skip to content

🕷️ 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

Testing some of the new tests on Github action

Karim shoaire594bba0c4e5
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 77dd783..d6d6ef6 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -44,6 +44,17 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
+ - name: Install Playwright Dependencies
+ run: |
+ pip install playwright
+ playwright install chromium
+ playwright install-deps chromium
+
+ - name: Install Camoufox Dependencies
+ run: |
+ pip install camoufox
+ python -m camoufox fetch --browserforge
+
- name: Run tests
env: ${{ matrix.env }}
run: |
diff --git a/tests/requirements.txt b/tests/requirements.txt
index cffeec6..fd7ef96 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,2 +1,6 @@
pytest
-pytest-cov
\ No newline at end of file
+pytest-cov
+playwright
+camoufox
+pytest-httpbin
+pytest-playwright
diff --git a/tests/test_fetchers/__init__.py b/tests/test_fetchers/__init__.py
new file mode 100644
index 0000000..1014360
--- /dev/null
+++ b/tests/test_fetchers/__init__.py
@@ -0,0 +1 @@
+# Because I'm too lazy to mock requests :)
diff --git a/tests/test_fetchers/test_stealthy_fetcher.py b/tests/test_fetchers/test_stealthy_fetcher.py
new file mode 100644
index 0000000..b6c6182
--- /dev/null
+++ b/tests/test_fetchers/test_stealthy_fetcher.py
@@ -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)
diff --git a/tox.ini b/tox.ini
index 77d25dd..fdf42c3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,14 +4,18 @@
# and then run "tox" from this directory.
[tox]
-envlist = pre-commit,py37,py38,py39,py310,py311,py312
+envlist = pre-commit,py{38,39,310,311,312,313}
[testenv]
usedevelop = True
changedir = tests
deps =
-r{toxinidir}/tests/requirements.txt
-commands = pytest --cov=scrapling --cov-report=xml
+commands =
+ playwright install chromium
+ playwright install-deps chromium
+ camoufox fetch --browserforge
+ pytest --cov=scrapling --cov-report=xml
[testenv:pre-commit]
basepython = python3