Playwright Tests #29
This file contains 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
name: Playwright Tests | |
'on': | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
targetBrowser: | |
description: Choose Target Browser | |
default: chrome | |
type: choice | |
options: | |
- firefox | |
- chrome | |
- microsoftedge | |
jobs: | |
Custom_Linux_Grid: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js env | |
uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Install dependencies | |
run: | | |
npm install | |
npm install playwright | |
npm install typescript ts-node @types/node | |
- name: Install Playwright Browsers | |
run: npx playwright install --with-deps | |
- name: Log Browser Version | |
run: > | |
if [ '${{ github.event.inputs.targetBrowser }}' == 'firefox' ]; then | |
BROWSER_VERSION=$(npx playwright show-browser firefox --version) | |
echo "Firefox Browser Version: $BROWSER_VERSION" | |
elif [ '${{ github.event.inputs.targetBrowser }}' == 'chrome' ]; then | |
BROWSER_VERSION=$(npx playwright show-browser chromium --version) | |
echo "Google Chrome Browser Version: $BROWSER_VERSION" | |
elif [ '${{ github.event.inputs.targetBrowser }}' == 'microsoftedge' | |
]; then | |
BROWSER_VERSION=$(npx playwright show-browser webkit --version) | |
echo "Microsoft Edge Browser Version: $BROWSER_VERSION" | |
else | |
echo "Browser not supported" | |
fi | |
- name: Compile TypeScript | |
run: npx tsc | |
- name: Run Playwright Tests with xvfb-run | |
run: > | |
# Check if Xvfb is needed (for headed mode) | |
if [ '${{ github.event.inputs.targetBrowser }}' == 'firefox' ] | |
|| | |
[ '${{ github.event.inputs.targetBrowser }}' == 'chrome' ] || | |
[ '${{ github.event.inputs.targetBrowser }}' == 'microsoftedge' ]; then | |
echo "Running tests with xvfb-run to simulate display" | |
xvfb-run -a npx playwright test --project="${{ github.event.inputs.targetBrowser || 'chromium' }}" | |
else | |
echo "Running tests headlessly" | |
npx playwright test --project="${{ github.event.inputs.targetBrowser || 'chromium' }}" | |
fi | |
- name: Upload Playwright Report as Pipeline Artifact | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Playwright_Report | |
path: playwright-report/ | |
- name: Upload Playwright Report HTML as Pipeline Artifact | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Playwright_Report_HTML | |
path: playwright-report/index.html |