This project contains comprehensive test cases for testing the Sitecore Content Hub REST API endpoints using Playwright. The tests cover authentication, entity management, asset operations, job management, selections, option lists, and more.
- Node.js (v16 or higher)
- A Sitecore Content Hub instance
- Valid Content Hub credentials (OAuth client credentials and user credentials)
npm install
npx playwright install- Copy the example environment file:
copy .env.example .env- Edit the
.envfile and fill in your actual Content Hub configuration:
# Content Hub Instance URL (without trailing slash)
CONTENT_HUB_BASE_URL=https://your-instance.stylelabs.cloud
# OAuth Client Credentials
CONTENT_HUB_CLIENT_ID=your-client-id
CONTENT_HUB_CLIENT_SECRET=your-client-secret
# User Credentials for OAuth Password Grant
CONTENT_HUB_USERNAME=your-username
CONTENT_HUB_PASSWORD=your-password- Log into your Content Hub instance as an administrator
- Navigate to Manage > Settings > Integrations > OAuth clients
- Create a new OAuth client or use an existing one
- Note down the Client ID and Client Secret
- Ensure the client has the necessary scopes (typically
api)
- Use a valid Content Hub user account with appropriate permissions
- The user should have access to the APIs you want to test
This test suite implements automatic rate limiting to respect Sitecore Content Hub API throttling limits:
- Rate Limit: Maximum 13 requests per second
- Implementation: Built-in rate limiting in the
ContentHubAPIClientclass - Automatic Handling: Tests automatically wait when rate limits are reached
- Sequential Execution: Tests run sequentially to prevent overwhelming the API
- Automatic Throttling: The client automatically enforces a 13 requests per second limit
- Transparent Delays: When rate limits are hit, the client waits before making the next request
- Console Logging: Rate limit delays are logged to help with debugging
- Reset Functionality: Rate limiting counters can be reset for testing purposes
The test suite is organized into the following categories:
- OAuth token acquisition
- Invalid credential handling
- Token validation
- Create, read, update, delete entities
- Entity property management
- Entity relationships
- Basic entity queries with filters
- Full-text search
- Pagination handling
- Sorting and filtering
- File upload initiation
- Upload progress tracking
- Asset information retrieval
- Job listing and filtering
- Job status monitoring
- Job details retrieval
- Selection creation and management
- Adding/removing entities from selections
- Selection queries
- Option list retrieval
- Option management
- Option list modifications
- Entity definition retrieval
- Member definition queries
- Schema validation
- 404 error handling
- Invalid parameter handling
- Malformed request handling
- Concurrent request handling
- Response time validation
npm testnpm run test:content-hubnpm run test:headednpm run test:debugnpm run reportThe test suite covers the following Content Hub REST API endpoints:
POST /api/oauth/token- OAuth token acquisition
GET /api/entities- List entitiesPOST /api/entities- Create entityGET /api/entities/{id}- Get entity by IDPUT /api/entities/{id}- Update entityDELETE /api/entities/{id}- Delete entityGET /api/entities/query- Query entities with filtersPOST /api/entities/query- Advanced entity searchGET /api/entities/search- Full-text search
POST /api/upload/initiate- Initiate file uploadGET /api/upload/progress/{id}- Get upload progress
GET /api/jobs- List jobsGET /api/jobs/{id}- Get job details
GET /api/selections- List selectionsPOST /api/selections- Create selectionPOST /api/selections/{id}/entities- Add entities to selection
GET /api/optionlists- List option listsGET /api/optionlists/{id}- Get option list detailsPOST /api/optionlists/{id}/options- Add option to list
GET /api/entitydefinitions- List entity definitionsGET /api/entitydefinitions/{id}- Get entity definitionGET /api/entitydefinitions/{id}/members- Get member definitions
| Variable | Description | Required |
|---|---|---|
CONTENT_HUB_BASE_URL |
Content Hub instance URL | Yes |
CONTENT_HUB_CLIENT_ID |
OAuth client ID | Yes |
CONTENT_HUB_CLIENT_SECRET |
OAuth client secret | Yes |
CONTENT_HUB_USERNAME |
Content Hub username | Yes |
CONTENT_HUB_PASSWORD |
Content Hub password | Yes |
DEBUG_API_CALLS |
Enable verbose logging | No |
The tests are configured to run with rate limiting considerations:
- Sequential Execution: Tests run one at a time (
fullyParallel: false) - Single Worker: Uses only one worker thread (
workers: 1) - Extended Timeouts: 60-second timeout to accommodate rate limiting delays
- Multiple Browsers: Still supports Chromium, Firefox, and WebKit
- Retry Logic: Includes retry logic for CI environments
Tests run in parallel by default and include retry logic for CI environments.
-
Authentication Failures
- Verify your OAuth client credentials are correct
- Ensure the OAuth client has the required scopes
- Check that the user credentials are valid
-
Network Timeouts
- Verify your Content Hub instance URL is accessible
- Check firewall/proxy settings
- Increase timeout values if needed
-
Permission Errors
- Ensure the user has appropriate permissions for the APIs being tested
- Check that the OAuth client has the necessary scopes
-
Test Data Conflicts
- Tests create temporary entities with timestamps to avoid conflicts
- If tests fail due to existing data, check for cleanup issues
- Use
--debugflag to step through tests:
npm run test:debug-
Enable API call logging by setting
DEBUG_API_CALLS=truein your.envfile -
Check the test report for detailed error information:
npm run reportWhen adding new test cases:
- Follow the existing test structure and naming conventions
- Use the
ContentHubAPIClienthelper class for API calls - Include proper error handling and assertions
- Add cleanup for any test data created
- Update this README if new endpoints are covered
- Never commit your
.envfile with real credentials - Use environment-specific credentials for different test environments
- Regularly rotate your OAuth client secrets
- Use least-privilege access for test user accounts