MCPcopy
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / test_scrape_method_retry_logic

Function test_scrape_method_retry_logic

tests/test_chromium.py:189–212  ·  view source on GitHub ↗

Test the retry logic in the scrape method.

(mock_playwright)

Source from the content-addressed store, hash-verified

187
188@pytest.mark.asyncio
189async def test_scrape_method_retry_logic(mock_playwright):
190 """Test the retry logic in the scrape method."""
191 mock_pw, mock_browser, mock_context, mock_page = mock_playwright
192
193 url = "http://example.com"
194 loader = ChromiumLoader([url], backend="playwright", retry_limit=3)
195
196 # Simulate two failures and then a success
197 mock_page.goto.side_effect = [asyncio.TimeoutError(), aiohttp.ClientError(), None]
198 mock_page.content.return_value = "<html>Success after retries</html>"
199
200 result = await loader.scrape(url)
201
202 assert "Success after retries" in result
203 assert mock_page.goto.call_count == 3
204 assert mock_page.content.call_count == 1
205
206 # Test failure after all retries
207 mock_page.goto.side_effect = asyncio.TimeoutError()
208
209 with pytest.raises(RuntimeError):
210 await loader.scrape(url)
211
212 assert mock_page.goto.call_count == 6 # 3 more attempts
213
214
215@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 2

scrapeMethod · 0.95
ChromiumLoaderClass · 0.90

Tested by

no test coverage detected