Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@spryv/agent) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Nahdi Online Champix Search Automation
A comprehensive Playwright automation script that searches for 'champix' on nahdionline.com and opens the first result.
Features
- Robust Selector Strategy: Multiple fallback selectors for each element
- Error Handling: Comprehensive error handling with retry mechanisms
- Popup Management: Automatic handling of cookie banners and age verification
- Detailed Logging: Timestamped logs with different severity levels
- Screenshots: Automatic screenshots at key steps and on errors
- Network Awareness: Waits for network idle state for reliable automation
- Retry Logic: Configurable retry attempts for flaky scenarios
Project Structure
├── nahdi-champix-automation.js # Basic automation script
├── nahdi-champix-automation-enhanced.js # Enhanced script with full features
├── MANUAL_TESTING_GUIDE.md # Guide for manual testing and selector discovery
├── package.json # Node.js dependencies
├── test-runner.js # Test runner with validation
├── screenshots/ # Auto-generated screenshots
└── README.md # This fileSetup Instructions
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
Installation
Clone or download this project
Install dependencies
npm install
Install Playwright browsers
npm run setupOr manually:
npx playwright install npx playwright install-deps
Usage
Basic Script
# Run the basic automation script
node nahdi-champix-automation.jsEnhanced Script (Recommended)
# Run the enhanced script with full features
node nahdi-champix-automation-enhanced.jsTest Runner
# Run with validation and reporting
node test-runner.jsConfiguration
Edit the CONFIG object in the enhanced script to customize behavior:
const CONFIG = {
headless: false, // Set to true for headless mode
timeout: 30000, // Timeout in milliseconds
searchTerm: 'champix', // Search term to use
screenshotDir: './screenshots',
waitForNetworkIdle: true, // Wait for network requests to finish
retryAttempts: 3 // Number of retry attempts
};Manual Testing
Before running the automation, follow the manual testing guide:
- Read
MANUAL_TESTING_GUIDE.md - Manually test the website to identify correct selectors
- Update the
SELECTORSobject in the script with accurate selectors - Test the automation script
Output
The script generates:
Screenshots: Saved in
./screenshots/directoryinitial-page-load-[timestamp].pngafter-search-input-[timestamp].pngsearch-results-page-[timestamp].pngproduct-page-[timestamp].pngerror-state-[timestamp].png(if errors occur)
Logs: Detailed execution logs saved as text files
automation-log-[timestamp].txt
Troubleshooting
Common Issues
Selectors not found
- Run manual testing to identify correct selectors
- Update the
SELECTORSobject in the script - Check if the website structure has changed
Timeout errors
- Increase the
timeoutvalue in CONFIG - Check your internet connection
- Verify the website is accessible
- Increase the
Popup blocking automation
- Check screenshots to see if popups appeared
- Update popup selectors in the script
- Add manual popup handling if needed
Browser launch failures
- Ensure Playwright browsers are installed:
npx playwright install - Try running with
headless: falseto see what's happening - Check system requirements for Playwright
- Ensure Playwright browsers are installed:
Debug Mode
To debug issues:
- Set
headless: falsein CONFIG - Add breakpoints or
await page.pause()in the script - Check browser developer tools
- Review screenshots and logs
Customization
Adding New Selectors
If selectors need updates, modify the SELECTORS object:
const SELECTORS = {
search: {
input: [
'your-new-selector',
'input[type="search"]',
// ... existing selectors
]
}
};Changing Search Term
Update the CONFIG.searchTerm value:
const CONFIG = {
searchTerm: 'your-search-term',
// ... other config
};Adding New Steps
Extend the NahdiAutomation class with new methods:
class NahdiAutomation {
async yourNewStep() {
this.log('Performing new step...');
// Your automation logic here
}
async run() {
// ... existing steps
await this.yourNewStep();
}
}Browser Support
This automation is tested with:
- Chromium (default)
- Chrome
- Firefox (may require selector adjustments)
- Safari (may require selector adjustments)
Contributing
To improve this automation:
- Test manually using the guide
- Update selectors based on findings
- Add error handling for new scenarios
- Update documentation
License
MIT License - feel free to use and modify as needed.