UNPKG

visual-healer

Version:

Self-healing visual regression & selector suggestions for web UI tests.

198 lines (143 loc) โ€ข 4.67 kB
# ๐Ÿ”Ž Visual Healer **Visual Test Auto-Healer** is a CLI tool that detects UI layout shifts, broken selectors, and visual changes โ€” then proposes automatic fixes and generates reports. Perfect for regression testing and CI pipelines. ![npm](https://img.shields.io/npm/v/visual-healer?style=flat-square) ![CI](https://img.shields.io/badge/CI-ready-green?style=flat-square) ![License](https://img.shields.io/npm/l/visual-healer?style=flat-square) --- ## ๐Ÿš€ Features * โœ… Detect layout shifts using visual diffing * โœ… Compare DOM elements and bounding boxes * โœ… Auto-suggest updated selectors using smart heuristics * โœ… Generate: * ๐Ÿ“„ Markdown report * ๐ŸŒ HTML report * ๐Ÿงช JUnit XML report (CI-ready) * โœ… Support for `--ci` mode to fail builds on detection * โœ… Custom `--fail-on` filters (`healing`, `layout-shift`, `invalid-selector`) * โœ… CI-safe Puppeteer launch to avoid sandbox errors * โœ… Easy integration with GitHub Actions, GitLab CI, Jenkins --- ## ๐Ÿ“ข What's New in v1.0.4 - **CI-safe Puppeteer launch** to prevent โ€œNo usable sandbox!โ€ errors in CI environments. - Updated **GitHub Actions workflow**: - **Gating step**: fails the build only for layout shifts. - **Non-blocking healing step**: runs auto-healing analysis without blocking merges. - More reliable selector validation in CI environments. --- ## ๐Ÿ“ฆ Installation Run directly with `npx`: ```bash npx visual-healer analyze https://example.com ``` Or install globally: ```bash npm install -g visual-healer ``` --- ## ๐Ÿงช Usage ### Basic command ```bash npx visual-healer analyze https://example.com ``` ### With CI mode ```bash npx visual-healer analyze https://example.com --ci ``` ### Fail CI only on specific issue type ```bash # Fail only if auto-healing triggered npx visual-healer analyze https://example.com --ci --fail-on healing # Fail only on layout shifts npx visual-healer analyze https://example.com --ci --fail-on layout-shift # Fail only if suggested selector is invalid npx visual-healer analyze https://example.com --ci --fail-on invalid-selector ``` --- ## ๐Ÿ“‚ Output After running, the tool generates: ``` /reports โ”œโ”€โ”€ report.md - Human-readable summary โ”œโ”€โ”€ report.html - Rich visual report with screenshots โ”œโ”€โ”€ junit-report.xml - CI-compatible test results โ”œโ”€โ”€ diff.png - Visual difference snapshot โ””โ”€โ”€ elements/*.png - Cropped UI element images ``` --- ## ๐Ÿ’ป Local Example ```bash # Install dependencies npm install # Run the example node examples/run-example.js ``` This will: * Capture screenshot & DOM metadata from a sample URL * Compare against a baseline (if available) * Generate HTML, Markdown, and JUnit reports in `/reports` * Show healing suggestions and visual diffs --- ## ๐Ÿ” GitHub Actions Example `.github/workflows/visual-healer.yml`: ```yaml name: Visual Healer on: pull_request: branches: [ main ] jobs: heal-and-diff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci # Gatekeeper: only fail PRs on layout shifts - name: Check for layout shifts (gating) run: | npx visual-healer analyze https://example.com --ci --fail-on layout-shift # Also run healing, but do not fail the job; still upload artifacts - name: Run healing analysis (non-blocking) continue-on-error: true run: | npx visual-healer analyze https://example.com --ci --fail-on healing - name: Upload report if: always() uses: actions/upload-artifact@v4 with: name: visual-healer-report path: reports ``` --- ## ๐Ÿ” GitLab CI Example `.gitlab-ci.yml`: ```yaml visual-healer: image: node:20 script: - npm ci - npx visual-healer analyze https://example.com --ci --fail-on healing artifacts: when: always paths: - reports/junit-report.xml reports: junit: reports/junit-report.xml ``` --- ## ๐Ÿ’ก Roadmap * [x] CLI mode * [x] Visual diffing * [x] Selector confidence + code snippets * [x] CI filters * [x] JUnit report output * [ ] AI-powered selector generation * [ ] Web dashboard (optional SaaS) --- ## ๐Ÿง‘โ€๐Ÿ’ป Author Made by **Kakha Kitiashvili** [GitHub Repo](https://github.com/kaha3/visual-healer) --- ## ๐Ÿ“„ License MIT