This repository was archived by the owner on Jan 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Screenshot feature #23
Closed
Closed
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7d04f7d
Create screenshot-on-pr.yml
amarilda611 905ea34
Create screenshot.js
amarilda611 63889f4
Update screenshot-on-pr.yml
amarilda611 e9eefb3
Update screenshot-on-pr.yml
amarilda611 5d6888d
Update screenshot-on-pr.yml
amarilda611 ec21c34
Update screenshot.js
amarilda611 1a65cb1
Update screenshot-on-pr.yml
amarilda611 3b3c88e
Update screenshot-on-pr.yml
amarilda611 6417bc4
Update screenshot.js
amarilda611 31ae72b
Update screenshot.js
amarilda611 7f16749
Update screenshot-on-pr.yml
amarilda611 39e4fb1
Update screenshot.js
amarilda611 a56a3ab
Update screenshot-on-pr.yml
amarilda611 edefe7b
Update screenshot.js
amarilda611 a202684
Update screenshot-on-pr.yml
amarilda611 96305e6
Update screenshot.js
amarilda611 cf62c61
Update screenshot-on-pr.yml
amarilda611 bc9fddb
Update screenshot.js
amarilda611 ace0b77
Update screenshot-on-pr.yml
amarilda611 9571ef0
Update screenshot.js
amarilda611 20585b1
Update screenshot-on-pr.yml
amarilda611 d621a5d
Update screenshot.js
amarilda611 1c554c8
Update screenshot-on-pr.yml
amarilda611 96339ab
Update screenshot.js
amarilda611 11a009e
Update screenshot-on-pr.yml
amarilda611 4346c3d
Update screenshot.js
amarilda611 fb094a9
Update screenshot-on-pr.yml
amarilda611 3287807
Update screenshot.js
amarilda611 edc849d
Update screenshot-on-pr.yml
amarilda611 79b94cd
Update screenshot.js
amarilda611 1518ae1
Update screenshot-on-pr.yml
amarilda611 4bfe625
Update screenshot.js
amarilda611 892d49f
Update screenshot-on-pr.yml
amarilda611 bd4d4ff
Update screenshot.js
amarilda611 e6570eb
Update screenshot.js
amarilda611 cf992cf
Update screenshot-on-pr.yml
amarilda611 f2d64e7
Update screenshot.js
amarilda611 5930382
Update screenshot-on-pr.yml
amarilda611 1b97bb6
Update screenshot.js
amarilda611 a62b880
Update screenshot-on-pr.yml
amarilda611 17102b8
Update screenshot.js
amarilda611 c0a14df
Update screenshot-on-pr.yml
amarilda611 9a94ddf
Update screenshot.js
amarilda611 3b66f9b
Update screenshot-on-pr.yml
amarilda611 8fa3703
Update screenshot.js
amarilda611 a4f3527
Update screenshot-on-pr.yml
amarilda611 0e32018
Update screenshot.js
amarilda611 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| name: Playwright Visual Review | ||
|
|
||
| concurrency: | ||
| group: playwright-screenshots-${{ github.head_ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| visual-review: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| npm install --package-lock-only --ignore-scripts | ||
| npm install playwright | ||
|
|
||
| - name: Install Playwright | ||
| run: npx playwright install --with-deps | ||
|
|
||
| # UPDATED SCREENSHOT CAPTURE WITH DEBUGGING | ||
| - name: Capture GUI screenshots | ||
| id: capture-screenshots | ||
| run: | | ||
| # Enable verbose Playwright debugging | ||
| export DEBUG=pw:api,pw:browser,pw:protocol | ||
|
|
||
| # Add detailed logging | ||
| echo "Starting screenshot capture with debug logging..." | ||
| echo "Target URL: $TARGET_URL" | ||
|
|
||
| node scripts/screenshot.js | ||
|
|
||
| # List captured files for verification | ||
| echo "Screenshot files:" | ||
| ls -l tests_artifacts || echo "No artifacts directory" | ||
| continue-on-error: true | ||
| timeout-minutes: 5 | ||
| env: | ||
| TARGET_URL: "https://your-app.com/login" # UPDATE TO YOUR ACTUAL URL | ||
|
|
||
| # DEBUGGING AND ERROR HANDLING | ||
| - name: Check for screenshots | ||
| if: always() && steps.capture-screenshots.outcome != 'success' | ||
| run: | | ||
| echo "Screenshot capture failed! Debugging information:" | ||
| ls -lR tests_artifacts || echo "No artifacts directory" | ||
| if [ -f tests_artifacts/error-state.png ]; then | ||
| echo "Error screenshot available in artifacts" | ||
| fi | ||
| if [ -f tests_artifacts/error-page.html ]; then | ||
| echo "Error page HTML available in artifacts" | ||
| fi | ||
| exit 1 # Fail the job explicitly | ||
|
|
||
| - name: Upload debug artifacts | ||
| if: always() && steps.capture-screenshots.outcome != 'success' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: screenshot-debug | ||
| path: tests_artifacts/ | ||
| retention-days: 1 | ||
|
|
||
| # MAIN FLOW CONTINUES IF SCREENSHOTS SUCCEEDED | ||
| - name: Upload screenshots to repo | ||
| if: steps.capture-screenshots.outcome == 'success' | ||
| uses: JamesIves/github-pages-deploy-action@v4 | ||
| with: | ||
| branch: gh-pages | ||
| folder: tests_artifacts | ||
| clean: true | ||
| commit-message: "Upload GUI screenshots [skip ci]" | ||
|
|
||
| - name: Prepare image URLs | ||
| if: steps.capture-screenshots.outcome == 'success' | ||
| id: images | ||
| run: | | ||
| BASE_URL="https://raw.githubusercontent.com/${{ github.repository }}/gh-pages/" | ||
| IMAGES=$(find tests_artifacts -name '*.png' -not -name 'error-*') | ||
| MARKDOWN="" | ||
|
|
||
| for image in $IMAGES; do | ||
| FILENAME=$(basename "$image") | ||
| URL="$BASE_URL$FILENAME" | ||
| MARKDOWN+="\n\n" | ||
| done | ||
|
|
||
| echo "markdown_images<<EOF" >> $GITHUB_OUTPUT | ||
| echo -e "$MARKDOWN" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Post PR comment with images | ||
| if: steps.capture-screenshots.outcome == 'success' | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| header: gui-screenshots | ||
| message: | | ||
| ## 🖼️ Automated GUI Test Preview | ||
| Below are the UI states captured during tests: | ||
|
|
||
| ${{ steps.images.outputs.markdown_images }} | ||
|
|
||
| [View full debug info](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | ||
|
|
||
| # ERROR COMMENT | ||
| - name: Post error comment | ||
| if: failure() && steps.capture-screenshots.outcome != 'success' | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| header: gui-screenshots-error | ||
| message: | | ||
| ## ❌ GUI Screenshot Capture Failed | ||
| Screenshot capture failed during execution. Debugging information: | ||
|
|
||
| - [View debug artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | ||
| - Check application availability and element selectors | ||
|
|
||
| Common fixes: | ||
| 1. Verify application URL is accessible from GitHub's servers | ||
| 2. Check element selectors in screenshot.js | ||
| 3. Increase timeouts if application is slow to load |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,144 @@ | ||||
| const { chromium } = require('playwright'); | ||||
| const fs = require('fs'); | ||||
| const path = require('path'); | ||||
|
|
||||
| // Configuration | ||||
| const OUTPUT_DIR = path.join(__dirname, '../tests_artifacts'); | ||||
| const TIMEOUT = 120000; // 2 minutes timeout | ||||
| const TARGET_URL = process.env.TARGET_URL || 'https://your-app.com/login'; // From environment variable | ||||
|
|
||||
| // Create output directory if needed | ||||
| if (!fs.existsSync(OUTPUT_DIR)) { | ||||
| fs.mkdirSync(OUTPUT_DIR, { recursive: true }); | ||||
| } | ||||
|
|
||||
| (async () => { | ||||
| let browser; | ||||
| let page; | ||||
|
|
||||
| try { | ||||
| console.log('Launching browser...'); | ||||
| browser = await chromium.launch({ headless: true }); | ||||
| const context = await browser.newContext(); | ||||
| page = await context.newPage(); | ||||
|
|
||||
| // Set extended timeout for all actions | ||||
| page.setDefaultTimeout(TIMEOUT); | ||||
|
|
||||
| // 1. Navigate to target URL | ||||
| console.log(`Navigating to: ${TARGET_URL}`); | ||||
| await page.goto(TARGET_URL, { | ||||
| waitUntil: 'domcontentloaded', | ||||
| timeout: TIMEOUT | ||||
| }); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [prettier] reported by reviewdog 🐶
Suggested change
|
||||
| // Capture initial page state | ||||
| console.log('Page loaded. Capturing login page...'); | ||||
| await page.screenshot({ path: path.join(OUTPUT_DIR, '01-login-page.png') }); | ||||
| fs.writeFileSync(path.join(OUTPUT_DIR, 'login-page.html'), await page.content()); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [prettier] reported by reviewdog 🐶
Suggested change
|
||||
| // 2. Attempt to find and fill username | ||||
| console.log('Searching for username field...'); | ||||
| const usernameSelectors = [ | ||||
| '#username', | ||||
| 'input[name="username"]', | ||||
| 'input[type="text"]', | ||||
| 'input[type="email"]', | ||||
| 'input[id*="user"]', | ||||
| 'input[name*="user"]' | ||||
| ]; | ||||
|
|
||||
| const usernameField = await findVisibleElement(page, usernameSelectors); | ||||
| if (!usernameField) throw new Error('Username field not found'); | ||||
| await usernameField.fill('testuser'); | ||||
| console.log('Username filled'); | ||||
|
|
||||
| // 3. Attempt to find and fill password | ||||
| console.log('Searching for password field...'); | ||||
| const passwordSelectors = [ | ||||
| '#password', | ||||
| 'input[name="password"]', | ||||
| 'input[type="password"]', | ||||
| 'input[id*="pass"]', | ||||
| 'input[name*="pass"]' | ||||
| ]; | ||||
|
|
||||
| const passwordField = await findVisibleElement(page, passwordSelectors); | ||||
| if (!passwordField) throw new Error('Password field not found'); | ||||
| await passwordField.fill('testpass'); | ||||
| console.log('Password filled'); | ||||
|
|
||||
| // 4. Attempt to find and click login button | ||||
| console.log('Searching for login button...'); | ||||
| const loginButtonSelectors = [ | ||||
| '#login-btn', | ||||
| 'button[type="submit"]', | ||||
| 'button:has-text("Sign in")', | ||||
| 'button:has-text("Log in")', | ||||
| 'button:has-text("Login")', | ||||
| 'input[type="submit"]' | ||||
| ]; | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [prettier] reported by reviewdog 🐶
Suggested change
|
||||
| const loginButton = await findVisibleElement(page, loginButtonSelectors); | ||||
| if (!loginButton) throw new Error('Login button not found'); | ||||
| await loginButton.click(); | ||||
| console.log('Login button clicked'); | ||||
|
|
||||
| // 5. Wait for navigation to complete | ||||
| console.log('Waiting for post-login page...'); | ||||
| await page.waitForLoadState('networkidle', { timeout: TIMEOUT }); | ||||
|
|
||||
| // Capture dashboard state | ||||
| console.log('Page loaded. Capturing dashboard...'); | ||||
| await page.waitForSelector('.dashboard, .main-content, [class*="content"]', { | ||||
| state: 'visible', | ||||
| timeout: TIMEOUT | ||||
| }); | ||||
|
|
||||
| await page.screenshot({ | ||||
| path: path.join(OUTPUT_DIR, '02-dashboard.png'), | ||||
| fullPage: true | ||||
| }); | ||||
|
|
||||
| console.log('Screenshots captured successfully!'); | ||||
|
|
||||
| } catch (error) { | ||||
| console.error('Screenshot capture failed:', error); | ||||
|
|
||||
| // Capture error state if page exists | ||||
| if (page) { | ||||
| try { | ||||
| await page.screenshot({ | ||||
| path: path.join(OUTPUT_DIR, '99-error-state.png'), | ||||
| fullPage: true | ||||
| }); | ||||
| fs.writeFileSync(path.join(OUTPUT_DIR, 'error-page.html'), await page.content()); | ||||
| } catch (innerError) { | ||||
| console.error('Failed to capture error state:', innerError); | ||||
| } | ||||
| } | ||||
|
|
||||
| // Rethrow error to fail the workflow | ||||
| throw error; | ||||
| } finally { | ||||
| if (browser) { | ||||
| await browser.close(); | ||||
| } | ||||
| } | ||||
| })(); | ||||
|
|
||||
| // Helper function to find first visible element from a list of selectors | ||||
| async function findVisibleElement(page, selectors) { | ||||
| for (const selector of selectors) { | ||||
| try { | ||||
| const element = await page.waitForSelector(selector, { | ||||
| state: 'visible', | ||||
| timeout: 15000 // 15s per selector | ||||
| }); | ||||
| if (element) return element; | ||||
| } catch (e) { | ||||
| // Continue to next selector | ||||
| } | ||||
| } | ||||
| return null; | ||||
| } | ||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[prettier] reported by reviewdog 🐶