Skip to content

Commit 9d33c09

Browse files
committed
test(e2e): add Playwright E2E tests for Stripe checkout
- 8 tests: success flow, declined card, 3DS auth, form validation, error scenarios - Global setup/teardown for test Sales Invoice and Stripe Settings - Helper utilities for Stripe Card Element interaction - CI workflow for E2E tests with Stripe test keys
1 parent ad45dfa commit 9d33c09

8 files changed

Lines changed: 1708 additions & 0 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: E2E Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "payments/**"
7+
- "tests/e2e/**"
8+
- "playwright.config.js"
9+
- ".github/workflows/e2e-tests.yml"
10+
workflow_dispatch:
11+
inputs:
12+
debug:
13+
description: "Enable debug mode"
14+
required: false
15+
default: false
16+
type: boolean
17+
test_invoice_name:
18+
description: "Existing Sales Invoice name (leave empty to create dynamically)"
19+
required: false
20+
type: string
21+
test_payment_gateway:
22+
description: "Payment Gateway name"
23+
required: false
24+
default: "Stripe-Stripe"
25+
type: string
26+
27+
concurrency:
28+
group: e2e-${{ github.event.number || github.ref }}
29+
cancel-in-progress: true
30+
31+
jobs:
32+
stripe-e2e:
33+
name: Stripe E2E Tests
34+
runs-on: ubuntu-latest
35+
timeout-minutes: 30
36+
37+
# Only run if secrets are available (won't run on forks without secrets)
38+
if: ${{ github.event_name == 'workflow_dispatch' || github.repository == 'frappe/payments' || github.repository == 'nlvegan/payments' }}
39+
40+
services:
41+
mysql:
42+
image: mariadb:10.6
43+
env:
44+
MARIADB_ROOT_PASSWORD: "root"
45+
ports:
46+
- 3306:3306
47+
options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3
48+
49+
steps:
50+
- name: Clone Repository
51+
uses: actions/checkout@v4
52+
53+
- name: Setup Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: "3.14"
57+
58+
- name: Setup Node.js
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: 24
62+
cache: "npm"
63+
cache-dependency-path: package.json
64+
65+
- name: Cache pip
66+
uses: actions/cache@v4
67+
with:
68+
path: ~/.cache/pip
69+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
70+
restore-keys: |
71+
${{ runner.os }}-pip-
72+
73+
- name: Add Hosts Entry
74+
run: echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
75+
76+
- name: Setup Frappe Bench
77+
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
78+
env:
79+
FRAPPE_USER: frappe
80+
FRAPPE_BRANCH: develop
81+
82+
- name: Install Playwright
83+
run: |
84+
cd ${GITHUB_WORKSPACE}
85+
npm ci
86+
npx playwright install --with-deps chromium
87+
88+
- name: Start Frappe Server
89+
run: |
90+
cd ~/frappe-bench
91+
bench start &
92+
sleep 30
93+
env:
94+
CI: true
95+
96+
- name: Run Stripe E2E Tests
97+
run: |
98+
cd ${GITHUB_WORKSPACE}
99+
npx playwright test --project stripe-checkout
100+
env:
101+
CI: true
102+
# Secrets (sensitive credentials)
103+
STRIPE_TEST_SECRET_KEY: ${{ secrets.STRIPE_TEST_SECRET_KEY }}
104+
STRIPE_TEST_PUBLISHABLE_KEY: ${{ secrets.STRIPE_TEST_PUBLISHABLE_KEY }}
105+
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
106+
# Optional inputs for workflow_dispatch (leave empty for dynamic creation)
107+
TEST_INVOICE_NAME: ${{ inputs.test_invoice_name }}
108+
TEST_PAYMENT_GATEWAY: ${{ inputs.test_payment_gateway || 'Stripe-Stripe' }}
109+
# Fixed values
110+
TEST_SITE_URL: http://test_site:8000
111+
ADMIN_PASSWORD: admin
112+
PWDEBUG: ${{ inputs.debug && '1' || '0' }}
113+
114+
- name: Upload Test Report
115+
uses: actions/upload-artifact@v4
116+
if: always()
117+
with:
118+
name: playwright-report
119+
path: playwright-report/
120+
retention-days: 7
121+
122+
- name: Upload Test Results
123+
uses: actions/upload-artifact@v4
124+
if: failure()
125+
with:
126+
name: test-results
127+
path: test-results/
128+
retention-days: 7

playwright.config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Playwright Configuration for Stripe E2E Tests
3+
*
4+
* Run with: npx playwright test
5+
* Debug with: npx playwright test --debug
6+
*/
7+
8+
const { defineConfig, devices } = require("@playwright/test");
9+
10+
module.exports = defineConfig({
11+
testDir: "./tests/e2e",
12+
timeout: 60000,
13+
expect: {
14+
timeout: 10000,
15+
},
16+
fullyParallel: false, // Sequential to avoid DB conflicts in Frappe
17+
forbidOnly: !!process.env.CI,
18+
retries: process.env.CI ? 2 : 0,
19+
workers: 1, // Single worker to avoid database conflicts
20+
reporter: process.env.CI
21+
? [["github"], ["html", { open: "never" }]]
22+
: [["list"], ["html", { open: "on-failure" }]],
23+
24+
use: {
25+
baseURL: process.env.TEST_SITE_URL || "https://veg11.veganisme.org",
26+
trace: "retain-on-failure",
27+
screenshot: "only-on-failure",
28+
video: process.env.CI ? "retain-on-failure" : "off",
29+
actionTimeout: 15000,
30+
navigationTimeout: 30000,
31+
ignoreHTTPSErrors: true, // For self-signed/local certs
32+
},
33+
34+
projects: [
35+
{
36+
name: "stripe-checkout",
37+
testMatch: /stripe-checkout.*\.spec\.js/,
38+
use: { ...devices["Desktop Chrome"] },
39+
},
40+
],
41+
42+
globalSetup: "./tests/e2e/support/global-setup.js",
43+
globalTeardown: "./tests/e2e/support/global-teardown.js",
44+
45+
outputDir: "test-results/",
46+
});

run_stripe_e2e_tests.sh

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
3+
##############################################################################
4+
# Stripe E2E Test Runner
5+
#
6+
# Usage:
7+
# ./run_stripe_e2e_tests.sh [OPTIONS]
8+
#
9+
# Options:
10+
# --headed Run with visible browser (for debugging)
11+
# --debug Run in Playwright debug mode
12+
# --ci CI mode (headless, retry on failure)
13+
# --help Show this help message
14+
#
15+
# Environment Variables (required):
16+
# STRIPE_TEST_SECRET_KEY Stripe test secret key (sk_test_...)
17+
# STRIPE_TEST_PUBLISHABLE_KEY Stripe test publishable key (pk_test_...)
18+
#
19+
# Optional Environment Variables:
20+
# STRIPE_WEBHOOK_SECRET Webhook signing secret
21+
# TEST_SITE_URL Base URL (default: http://test_site:8000)
22+
# ADMIN_PASSWORD Admin password (default: admin)
23+
# NO_CLEANUP Set to 1 to skip teardown cleanup
24+
#
25+
##############################################################################
26+
27+
set -e
28+
29+
# Colors
30+
RED='\033[0;31m'
31+
GREEN='\033[0;32m'
32+
YELLOW='\033[1;33m'
33+
BLUE='\033[0;34m'
34+
NC='\033[0m'
35+
36+
# Script directory
37+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38+
39+
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
40+
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
41+
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
42+
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
43+
44+
show_help() {
45+
head -30 "$0" | tail -28 | sed 's/^# //' | sed 's/^#//'
46+
exit 0
47+
}
48+
49+
# Default options
50+
HEADED=""
51+
DEBUG=""
52+
CI_MODE=""
53+
54+
# Parse arguments
55+
while [[ $# -gt 0 ]]; do
56+
case $1 in
57+
--headed)
58+
HEADED="--headed"
59+
shift
60+
;;
61+
--debug)
62+
DEBUG="--debug"
63+
shift
64+
;;
65+
--ci)
66+
CI_MODE="1"
67+
export CI=1
68+
shift
69+
;;
70+
--help|-h)
71+
show_help
72+
;;
73+
*)
74+
log_error "Unknown option: $1"
75+
show_help
76+
;;
77+
esac
78+
done
79+
80+
# Check environment
81+
log_info "Checking environment..."
82+
83+
if [[ -z "$STRIPE_TEST_PUBLISHABLE_KEY" ]]; then
84+
log_warning "STRIPE_TEST_PUBLISHABLE_KEY not set - tests will be skipped"
85+
fi
86+
87+
if [[ -z "$STRIPE_TEST_SECRET_KEY" ]]; then
88+
log_warning "STRIPE_TEST_SECRET_KEY not set - tests will be skipped"
89+
fi
90+
91+
# Check for Node.js
92+
if ! command -v node &> /dev/null; then
93+
log_error "Node.js not found. Please install Node.js 18+"
94+
exit 1
95+
fi
96+
97+
# Check for npm/npx
98+
if ! command -v npx &> /dev/null; then
99+
log_error "npx not found. Please install npm"
100+
exit 1
101+
fi
102+
103+
# Install dependencies if needed
104+
cd "$SCRIPT_DIR"
105+
if [[ ! -d "node_modules" ]]; then
106+
log_info "Installing dependencies..."
107+
npm install
108+
fi
109+
110+
# Install Playwright browsers if needed
111+
if [[ ! -d "$HOME/.cache/ms-playwright" ]] && [[ ! -d "/ms-playwright" ]]; then
112+
log_info "Installing Playwright browsers..."
113+
npx playwright install chromium
114+
fi
115+
116+
# Build command
117+
CMD="npx playwright test --project stripe-checkout"
118+
119+
if [[ -n "$HEADED" ]]; then
120+
CMD="$CMD $HEADED"
121+
fi
122+
123+
if [[ -n "$DEBUG" ]]; then
124+
CMD="$CMD $DEBUG"
125+
fi
126+
127+
# Run tests
128+
log_info "Running Stripe E2E tests..."
129+
log_info "Command: $CMD"
130+
echo ""
131+
132+
$CMD
133+
134+
EXIT_CODE=$?
135+
136+
if [[ $EXIT_CODE -eq 0 ]]; then
137+
log_success "All tests passed!"
138+
else
139+
log_error "Tests failed with exit code $EXIT_CODE"
140+
log_info "Check playwright-report/index.html for details"
141+
fi
142+
143+
exit $EXIT_CODE

0 commit comments

Comments
 (0)