Automation framework for testing the U-Ask Chatbot using Playwright. This framework includes UI, AI response validation, and security tests to ensure the chatbot functions correctly across different languages and scenarios.
- Node.js (version 16 or higher)
- npm or yarn
-
Clone the repository:
git clone <repository-url> cd uask-automation
-
Install dependencies:
npm install
npm test- UI Tests:
npm run test:ui - AI Tests:
npm run test:ai - Security Tests:
npm run test:security
npm run test:headednpx playwright test tests/ui/chatbot-ui.spec.jsThe framework supports testing in multiple languages (English and Arabic). Tests are parameterized by locale using data from fixtures/test-data.json.
- English (en):
/en/uask - Arabic (ar):
/ar/uask
To run tests for a specific language, use the --grep option with the locale ID:
# Run only English tests
npx playwright test --grep "en"
# Run only Arabic tests
npx playwright test --grep "ar"- Add the new locale to
fixtures/test-data.jsonunder thelocalesarray - Add corresponding test data under the locale ID (e.g.,
"fr": [...]) - Tests will automatically include the new locale
The framework is configured to automatically capture evidence for failed tests:
- Screenshots: Automatically taken only when a test fails (
screenshot: 'only-on-failure'inplaywright.config.js) - Traces: Collected on the first retry of failed tests (
trace: 'on-first-retry') - Logs: Test output is logged to the console and HTML report
Failed test artifacts are stored in:
- Screenshots:
test-results/directory - Traces:
test-results/directory - HTML Report:
playwright-report/index.html
Tests the chatbot's user interface across desktop and mobile viewports for each supported language.
- Desktop View Loads Correctly: Verifies UI elements are visible on desktop
- Mobile View Loads Correctly: Verifies UI elements are visible on mobile
- Send Messages via Input Box: Tests message sending functionality
- Input Field Clears After Sending: Ensures input is cleared post-send
- Accessibility Checks: Validates WCAG compliance using axe-playwright
Validates the AI responses for relevance, accuracy, and hallucination detection.
- Clear and Relevant Responses: Checks response length and keyword presence
- Ground Truth Validation: Verifies responses contain expected factual information
- Hallucination Detection: Ensures responses don't contain fabricated information
- Intent Recognition: Tests various user intents (service inquiry, visa questions, general info)
Tests the chatbot's security against common web vulnerabilities.
- XSS Attack Prevention: Verifies input sanitization against cross-site scripting
- Prompt Injection Handling: Tests resistance to prompt manipulation attacks
- Input Validation: Ensures malicious inputs are handled safely
This framework includes AI-powered validation using OpenAI's GPT models to intelligently assess chatbot responses for relevance, accuracy, and hallucination detection.
-
Install OpenAI package (already included):
npm install openai dotenv
-
Configure OpenAI API Key:
- Create a
.envfile in the project root:OPENAI_API_KEY=sk-your-api-key-here
- Get your API key from OpenAI Dashboard
- Create a
-
Alternative: Set Environment Variable:
export OPENAI_API_KEY=sk-your-api-key-here
- Intelligent Response Validation: Uses GPT to evaluate chatbot responses for clarity, accuracy, and relevance
- Hallucination Detection: Identifies fabricated or false information in responses
- Context Awareness: Validates responses against provided context and ground truth data
- Multi-Language Support: Validates responses in English and Arabic
- Customizable Assertions: Define custom validation rules using natural language
Test scenarios are driven by data in fixtures/test-data.json:
- Locales: Language configurations
- Prompts: Sample user queries with expected responses
- Security Payloads: Malicious inputs for security testing
After running tests, view the HTML report:
npm run test:report