Test ScrapeGraphAI functionality in an isolated environment without consuming API credits
Scenario | Description |
---|---|
Simulate scraping responses to test without real API calls | Use mock mode to test scraping functionality without real API calls. Create mock responses in your application to test data processing logic or use custom handlers to simulate various response scenarios. |
Scale isolated testing for teams | Your team can test in separate mock environments to make sure that data and actions are completely isolated from other tests. Changes made in one mock configuration donβt interfere with changes in another. |
Test without API key requirements | You can test your integration without providing real API keys, making it easier for external developers, implementation partners, or design agencies to work with your code without access to your live API credentials. |
Test in development or CI/CD pipelines | Access mock mode from your development environment or continuous integration pipelines. Test ScrapeGraphAI functionality directly in your code or use familiar testing frameworks and fixtures. |
mock=True
when initializing the client:
mock_responses
parameter:
Available Endpoint Overrides
Advanced Custom Handler
Complete JavaScript Mock Example
Client(mock=True)
initializationmock_responses
parameter for overridesmock_handler
for custom logicSGAI_MOCK=true
enableMock()
global activationsetMockResponses()
for overridessetMockHandler()
for custom logicSGAI_MOCK=1
Feature | Python SDK | JavaScript SDK |
---|---|---|
Global Mock Mode | Client(mock=True) | enableMock() |
Per-Request Mock | {mock: True} in params | {mock: true} in options |
Custom Responses | mock_responses dict | setMockResponses() |
Custom Handler | mock_handler function | setMockHandler() |
Environment Variable | SGAI_MOCK=true | SGAI_MOCK=1 |
Async Support | AsyncClient(mock=True) | Native async/await |
Common Issues
mock=True
is set when initializing the clientmock_handler
parameter correctly(method, url, kwargs)
Complete Mock Example