import os import sys import pytest import asyncio import time # Add the parent directory to the Python path parent_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(parent_dir) from crawl4ai.async_webcrawler import AsyncWebCrawler @pytest.mark.asyncio async def test_successful_crawl(): async with AsyncWebCrawler(verbose=True) as crawler: url = "https://www.nbcnews.com/business" result = await crawler.arun(url=url, bypass_cache=True) assert result.success assert result.url == url assert result.html assert result.markdown assert result.cleaned_html @pytest.mark.asyncio async def test_invalid_url(): async with AsyncWebCrawler(verbose=True) as crawler: url = "https://www.invalidurl12345.com" result = await crawler.arun(url=url, bypass_cache=True) assert not result.success assert result.error_message @pytest.mark.asyncio async def test_multiple_urls(): async with AsyncWebCrawler(verbose=True) as crawler: urls = [ "https://www.nbcnews.com/business", "https://www.example.com", "https://www.python.org" ] results = await crawler.arun_many(urls=urls, bypass_cache=True) assert len(results) == len(urls) assert all(result.success for result in results) assert all(result.html for result in results) @pytest.mark.asyncio async def test_javascript_execution(): async with AsyncWebCrawler(verbose=True) as crawler: js_code = "document.body.innerHTML = '