Skip to content

Commit 514c6d9

Browse files
committed
feat(e2e): add playwright navigation test suite and configuration
1 parent c86887e commit 514c6d9

File tree

5 files changed

+893
-4
lines changed

5 files changed

+893
-4
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
"test": "yarn run lint-scss && yarn run lint-python && yarn run test-python",
1717
"test-python": "python3 -m unittest discover tests",
1818
"test-js": "jest --env=jsdom",
19-
"test-marketo": "python3 -m unittest tests.test_marketo"
19+
"test-marketo": "python3 -m unittest tests.test_marketo",
20+
"test-e2e": "playwright test",
21+
"test-e2e-forms": "playwright test --project=forms",
22+
"test-e2e-navigation": "playwright test --project=navigation",
23+
"test-e2e-navigation-headed": "playwright test --project=navigation --headed",
24+
"test-e2e-navigation-debug": "playwright test --project=navigation --debug"
2025
},
2126
"dependencies": {
2227
"@canonical/cookie-policy": "^3.7.3",

playwright.config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dotenv.config({
1414
* See https://playwright.dev/docs/test-configuration.
1515
*/
1616
export default defineConfig({
17-
testDir: path.join(__dirname, "tests/playwright/tests/forms"),
17+
testDir: path.join(__dirname, "tests/playwright/tests"),
1818
/* Run tests in files in parallel */
1919
fullyParallel: true,
2020
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -38,8 +38,13 @@ export default defineConfig({
3838
/* Configure projects for major browsers */
3939
projects: [
4040
{
41-
name: 'checkout',
42-
testMatch: "*.spec.ts",
41+
name: 'forms',
42+
testMatch: "forms/*.spec.ts",
43+
use: { ...devices['Desktop Chrome']},
44+
},
45+
{
46+
name: 'navigation',
47+
testMatch: "navigation/*.spec.ts",
4348
use: { ...devices['Desktop Chrome']},
4449
},
4550
],

scripts/test-navigation.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
3+
# Navigation E2E Test Runner Script
4+
# Usage: ./scripts/test-navigation.sh [options]
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
# Default values
15+
HEADED=false
16+
DEBUG=false
17+
REPORTER="list"
18+
GREP=""
19+
BROWSER="chromium"
20+
21+
# Function to display usage
22+
usage() {
23+
echo "Usage: $0 [OPTIONS]"
24+
echo ""
25+
echo "Options:"
26+
echo " -h, --headed Run tests in headed mode (show browser)"
27+
echo " -d, --debug Run tests in debug mode"
28+
echo " -r, --reporter TYPE Test reporter (list, html, json, junit)"
29+
echo " -g, --grep PATTERN Run only tests matching pattern"
30+
echo " -b, --browser NAME Browser to use (chromium, firefox, webkit)"
31+
echo " --help Show this help message"
32+
echo ""
33+
echo "Examples:"
34+
echo " $0 # Run all navigation tests"
35+
echo " $0 --headed # Run with browser UI visible"
36+
echo " $0 --grep \"Primary Navigation\" # Run only primary navigation tests"
37+
echo " $0 --reporter html # Generate HTML report"
38+
echo " $0 --debug --grep \"dropdown\" # Debug dropdown tests"
39+
}
40+
41+
# Parse command line arguments
42+
while [[ $# -gt 0 ]]; do
43+
case $1 in
44+
-h|--headed)
45+
HEADED=true
46+
shift
47+
;;
48+
-d|--debug)
49+
DEBUG=true
50+
shift
51+
;;
52+
-r|--reporter)
53+
REPORTER="$2"
54+
shift 2
55+
;;
56+
-g|--grep)
57+
GREP="$2"
58+
shift 2
59+
;;
60+
-b|--browser)
61+
BROWSER="$2"
62+
shift 2
63+
;;
64+
--help)
65+
usage
66+
exit 0
67+
;;
68+
*)
69+
echo -e "${RED}Unknown option: $1${NC}"
70+
usage
71+
exit 1
72+
;;
73+
esac
74+
done
75+
76+
# Build the playwright command
77+
PLAYWRIGHT_CMD="npx playwright test --project=navigation"
78+
79+
if [ "$HEADED" = true ]; then
80+
PLAYWRIGHT_CMD="$PLAYWRIGHT_CMD --headed"
81+
fi
82+
83+
if [ "$DEBUG" = true ]; then
84+
PLAYWRIGHT_CMD="$PLAYWRIGHT_CMD --debug"
85+
fi
86+
87+
if [ -n "$GREP" ]; then
88+
PLAYWRIGHT_CMD="$PLAYWRIGHT_CMD --grep \"$GREP\""
89+
fi
90+
91+
if [ "$REPORTER" != "list" ]; then
92+
PLAYWRIGHT_CMD="$PLAYWRIGHT_CMD --reporter=$REPORTER"
93+
fi
94+
95+
# Add browser selection
96+
PLAYWRIGHT_CMD="$PLAYWRIGHT_CMD --browser=$BROWSER"
97+
98+
echo -e "${YELLOW}Running Navigation E2E Tests...${NC}"
99+
echo -e "${YELLOW}Command: $PLAYWRIGHT_CMD${NC}"
100+
echo ""
101+
102+
# Check if the server is running
103+
if ! curl -s http://localhost:8002 > /dev/null 2>&1; then
104+
echo -e "${RED}Warning: Development server not detected at http://localhost:8002${NC}"
105+
echo -e "${YELLOW}Make sure to start the development server before running tests:${NC}"
106+
echo " python3 app.py"
107+
echo ""
108+
fi
109+
110+
# Run the tests
111+
eval $PLAYWRIGHT_CMD
112+
113+
# Check exit code
114+
if [ $? -eq 0 ]; then
115+
echo -e "${GREEN}✅ Navigation tests completed successfully!${NC}"
116+
117+
if [ "$REPORTER" = "html" ]; then
118+
echo -e "${YELLOW}📊 HTML report generated. Open playwright-report/index.html to view results.${NC}"
119+
fi
120+
else
121+
echo -e "${RED}❌ Navigation tests failed!${NC}"
122+
exit 1
123+
fi

0 commit comments

Comments
 (0)