🕷️ 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
Adding tests for `PlayWrightFetcher` class
Karim shoaire4eb4427098d
diff --git a/tests/fetchers/test_playwright.py b/tests/fetchers/test_playwright.pynew file mode 100644index 0000000..f0ba143--- /dev/null+++ b/tests/fetchers/test_playwright.py@@ -0,0 +1,68 @@+import unittest+import pytest_httpbin++from scrapling import PlayWrightFetcher+++@pytest_httpbin.use_class_based_httpbin+# @pytest_httpbin.use_class_based_httpbin_secure+class TestPlayWrightFetcher(unittest.TestCase):+ def setUp(self):+ self.fetcher = PlayWrightFetcher(auto_match=False)+ 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, 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, disable_webgl=True, hide_canvas=False).status, 200)+ self.assertEqual(self.fetcher.fetch(self.html_url, disable_webgl=False, hide_canvas=True).status, 200)+ self.assertEqual(self.fetcher.fetch(self.html_url, stealth=True).status, 200)+ self.assertEqual(self.fetcher.fetch(self.html_url, useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0').status, 200)++ def test_cdp_url(self):+ """Test if it's going to try to connect to cdp url or not"""+ with self.assertRaises(ValueError):+ _ = self.fetcher.fetch(self.html_url, cdp_url='blahblah')++ with self.assertRaises(ValueError):+ _ = self.fetcher.fetch(self.html_url, cdp_url='blahblah', nstbrowser_mode=True)++ with self.assertRaises(Exception):+ # There's no type for this error in PlayWright, it's just `Error`+ _ = self.fetcher.fetch(self.html_url, cdp_url='ws://blahblah')++ 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)