Playwright + TypeScript automation that scrapes daily forecast data from AccuWeather, validates temperature conversion, and exports reports.
- Open
https://www.accuweather.com - Navigate to the configured city daily forecast page
- Scrape all available day cards (typically up to 15)
- For each day, extract Day/Night detail data
- Enrich humidity from the hourly forecast page
- Validate Fahrenheit/Celsius conversion
- Save final report as JSON and HTML
daily-weather-report-main/
├── playwright.config.ts
├── package.json
├── tsconfig.json
├── .env.example
├── src/
│ ├── config/
│ │ └── config.ts
│ ├── pages/
│ │ ├── BasePage.ts
│ │ ├── HomePage.ts
│ │ ├── DailyForecastPage.ts
│ │ ├── DayDetailPage.ts
│ │ └── HourlyForecastPage.ts
│ ├── types/
│ │ └── weather.ts
│ └── utils/
│ ├── temperatureConverter.ts
│ ├── reportHelpers.ts
│ ├── fileReporter.ts
│ └── logger.ts
├── tests/
│ └── weather/
│ └── daily-weather.spec.ts
├── reports/
└── scripts/
├── run-hourly.sh
└── com.weather.scraper.plist
The spec runs in serial mode and has 2 tests:
Scrape all days and validate weather dataSave reports in JSON and HTML formats
Page objects use layered selector fallback in priority order:
data-qaselectors- semantic class/structure selectors
- text-based selectors (last fallback)
This helps reduce flaky scraping when AccuWeather changes markup.
Set values in .env (copy from .env.example):
CITY_NAMECITY_LOCATION_IDCITY_COUNTRYCITY_SLUGHEADLESSTIMEZONEREPORT_OUTPUT_DIRSCRAPE_DELAY_MS
Example:
CITY_NAME=Ho Chi Minh City
CITY_LOCATION_ID=353981
CITY_COUNTRY=vn
CITY_SLUG=ho-chi-minh-city
HEADLESS=true
REPORT_OUTPUT_DIR=reportsnpm install
npx playwright install
npm run run:weatherUseful commands:
npm run test:headed
npm run test:debug
npm run test:reportEach run writes files to reports/:
weather_*.json(full report payload)weather_report_*.html(readable report page)
- Uses system Chrome (
channel: 'chrome') to improve stability against site anti-bot checks. scripts/com.weather.scraper.plistis for macOS LaunchAgent scheduling.scripts/run-hourly.shis a shell scheduler helper (macOS/Linux style).