Code N Solve ๐: CI/CD ํ๊ฒฝ์์ Playwright ๋ฌธ์ ํด๊ฒฐํ๊ธฐ: ์ค์น ์ค๋ฅ ๋ถ์ ๋ฐ ํด๊ฒฐ ๋ฐฉ์
Gatsby๋ฅผ ์ฌ์ฉํด ๋ธ๋ก๊ทธ๋ฅผ ๋ฐฐํฌํ ๋, Playwright ์ค์น์ ๊ด๋ จํด ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค.
์ด๋ป๊ฒ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋์ง ๋จ๊ณ๋ณ๋ก ์ดํด๋ณด์.
Playwright๋? ๐ญ
Playwright2๋ Microsoft๊ฐ ๊ฐ๋ฐํ ์คํ์์ค E2E(End-to-End) ํ ์คํธ ์๋ํ ๋๊ตฌ๋ค. Chromium, Firefox, WebKit ์ธ ๊ฐ์ง ๋ธ๋ผ์ฐ์ ์์ง์ ๋จ์ผ API๋ก ์ ์ดํ ์ ์์ด, ์น ์ ํ๋ฆฌ์ผ์ด์ ์ ๋์์ ์ค์ ๋ธ๋ผ์ฐ์ ํ๊ฒฝ๊ณผ ๋์ผํ๊ฒ ๊ฒ์ฆํ ์ ์๋ค.
Playwright vs Selenium
๋ ๋๊ตฌ ๋ชจ๋ ๋ธ๋ผ์ฐ์ ์๋ํ ๋ชฉ์ ์ผ๋ก ์ฐ์ด์ง๋ง, ์ค๊ณ ์ฒ ํ๊ณผ ์ฌ์ฉ ๋ฐฉ์์์ ์ฐจ์ด๊ฐ ์๋ค.
| ํญ๋ชฉ | Playwright | Selenium |
|---|---|---|
| ๊ฐ๋ฐ์ฌ | Microsoft | ThoughtWorks (์คํ์์ค) |
| ๋ธ๋ผ์ฐ์ ์ง์ | Chromium, Firefox, WebKit | Chrome, Firefox, Safari, Edge ๋ฑ |
| API ์คํ์ผ | async/await ๊ธฐ๋ฐ, ์ง๊ด์ | ๋ณต์กํ WebDriver ํ๋กํ ์ฝ |
| ์๋ ๋๊ธฐ | ๋ด์ฅ (Auto-waiting) | ๋ช ์์ ๋๊ธฐ ํ์ |
| ๋คํธ์ํฌ ๊ฐ๋ก์ฑ๊ธฐ | ๊ธฐ๋ณธ ์ง์ | ๋ณ๋ ํ๋ก์ ํ์ |
| ๋ณ๋ ฌ ์คํ | ๊ธฐ๋ณธ ์ง์ | ์ค์ ๋ณต์ก |
| ์ค์น | npm ํ๋๋ก ๋ธ๋ผ์ฐ์ ํฌํจ | ๋๋ผ์ด๋ฒ ๋ณ๋ ์ค์น ํ์ |
| CI/CD ํตํฉ | ๋งค์ฐ ๊ฐํธ | ์๋์ ์ผ๋ก ๋ณต์ก |
ํนํ Playwright๋ Auto-waiting ๊ธฐ๋ฅ ๋๋ถ์ "์์๊ฐ ๋ํ๋ ๋๊น์ง ๊ธฐ๋ค๋ ค๋ผ"์ ๊ฐ์ ์ฝ๋๋ฅผ ๋ช
์์ ์ผ๋ก ์์ฑํ์ง ์์๋ ๋๋ค.
Selenium์์๋ WebDriverWait์ด๋ time.sleep()์ ์์ฃผ ์จ์ผ ํ๋ ๋ถ๋ถ์ด Playwright์์๋ ์๋์ผ๋ก ์ฒ๋ฆฌ๋๋ค.
Playwright๊ฐ ์ง์ํ๋ ๊ฒ๋ค
- ๋ฉํฐ ๋ธ๋ผ์ฐ์ : Chromium(Chrome/Edge), Firefox, WebKit(Safari)
- ๋ฉํฐ ์ธ์ด API: JavaScript/TypeScript, Python, Java, .NET
- ์คํฌ๋ฆฐ์ท ๋ฐ ๋์์ ๋ นํ: ํ ์คํธ ์คํจ ์ ์๋ ์บก์ฒ
- ๋คํธ์ํฌ ๋ชจํน: API ์๋ต์ ๊ฐ์ง๋ก ๋์ฒดํ๋ ๊ธฐ๋ฅ
- ๋ชจ๋ฐ์ผ ์๋ฎฌ๋ ์ด์ : ์ค๋งํธํฐ ํด์๋ ๋ฐ User-Agent ์๋ฎฌ๋ ์ด์
- ์ปดํฌ๋ํธ ํ ์คํธ: React, Vue, Svelte ์ปดํฌ๋ํธ ๋จ์ ํ ์คํธ
CI/CD ํ๊ฒฝ์์ Playwright๊ฐ ํ์ํ ์ด์
1. E2E ํ ์คํธ ์๋ํ
์ฝ๋๋ฅผ pushํ ๋๋ง๋ค "์ค์ ๋ธ๋ผ์ฐ์ ์์ ํ์ด์ง๊ฐ ์ ๋๋ก ์ด๋ฆฌ๋๊ฐ"๋ฅผ ํ์ธํด์ผ ํ๋ค. ๋จ์ ํ ์คํธ(Unit Test)๊ฐ ํจ์ ํ๋ํ๋๋ฅผ ๊ฒ์ฆํ๋ค๋ฉด, E2E ํ ์คํธ๋ ์ฌ์ฉ์๊ฐ ๊ฒฝํํ๋ ์ ์ฒด ํ๋ฆ์ ๊ฒ์ฆํ๋ค.
์๋ฅผ ๋ค์ด ๋ก๊ทธ์ธ โ ๋ฐ์ดํฐ ์กฐํ โ ๋ก๊ทธ์์ ์๋๋ฆฌ์ค๋ฅผ Playwright๋ก ์์ฑํ๋ฉด, CI ํ์ดํ๋ผ์ธ์ด ์คํ๋ ๋๋ง๋ค ์ด ํ๋ฆ ์ ์ฒด๋ฅผ ์๋์ผ๋ก ๊ฒ์ฆํ ์ ์๋ค.
2. Mermaid ๋ค์ด์ด๊ทธ๋จ ๋ ๋๋ง (Gatsby/์ ์ ์ฌ์ดํธ)
Gatsby๋ Next.js ๊ธฐ๋ฐ ๋ธ๋ก๊ทธ์์ Mermaid ๋ค์ด์ด๊ทธ๋จ์ PNG๋ก ๋ณํํ๋ ๊ฒฝ์ฐ Playwright๋ฅผ ์ฌ์ฉํ๋ค. Mermaid๋ JavaScript๋ก ๋ ๋๋ง๋๋ฏ๋ก, ์๋ฒ์ฌ์ด๋์์ ์ด๋ฏธ์ง๋ก ๋ณํํ๋ ค๋ฉด ์ค์ ๋ธ๋ผ์ฐ์ ๊ฐ ํ์ํ๋ค. Playwright๊ฐ headless ๋ธ๋ผ์ฐ์ ๋ก Mermaid๋ฅผ ๋ ๋๋งํ๊ณ ์คํฌ๋ฆฐ์ท์ ์ฐ์ด PNG๋ก ์ ์ฅํ๋ ๋ฐฉ์์ผ๋ก ๋์ํ๋ค.
3. ์๊ฐ์ ํ๊ท ํ ์คํธ(Visual Regression Testing)
UI ๋ณ๊ฒฝ ์ฌํญ์ด ์๋ํ์ง ์์ ๋ ์ด์์ ๊นจ์ง์ ์ ๋ฐํ๋์ง ์คํฌ๋ฆฐ์ท์ ๋น๊ตํด ๊ฒ์ฆํ ์ ์๋ค.
CI/CD ์ ์ฒด ํ๋ฆ
๋ฐ์ ๊ฐ๋ฅํ ์ค๋ฅ ์ ํ ์ ์ฒด ์ ๋ฆฌ
์ค๋ฅ 1: browserType.launch: Executable doesn't exist (๊ธฐ๋ณธ ๊ฒฝ๋ก ๋ฌธ์ )
๊ฐ์ฅ ํํ๊ฒ ๋ง์ฃผ์น๋ ์ค๋ฅ๋ค.1
Error: Failed to launch chromium because executable doesn't exist
browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium-1124/chrome-linux/chrome
Error: browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium-1124/chrome-linux/chrome์์ธ
npm ci๋ก ํจํค์ง๋ฅผ ์ค์นํ ๋ Playwright ํจํค์ง ์์ฒด๋ ์ค์น๋์ง๋ง, ๋ธ๋ผ์ฐ์ ๋ฐ์ด๋๋ฆฌ๋ ๋ณ๋๋ก ์ค์นํด์ผ ํ๋ค.npx playwright install์ ์คํํ์ง ์์๊ฑฐ๋, ์คํํ๋๋ผ๋ ์ค์น ๊ฒฝ๋ก๊ฐ ๋ฌ๋ผ ์คํ ์์ ์ ์ฐพ์ง ๋ชปํ๋ ๊ฒฝ์ฐ ๋ฐ์ํ๋ค.- ๊ถํ ๋ฌธ์ : ๊ธฐ๋ณธ ๊ฒฝ๋ก์ ๋ํ ์ฐ๊ธฐ ๊ถํ์ด ์๋ ๊ฒฝ์ฐ.
ํด๊ฒฐ ๋ฐฉ๋ฒ
ํ๊ฒฝ ๋ณ์๋ก ์ค์น ๊ฒฝ๋ก๋ฅผ ๋ช ์์ ์ผ๋ก ์ง์ ํ๋ค.
- name: Set Playwright Browsers Path
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/ms-playwright" >> $GITHUB_ENV
- name: Check Playwright Browsers Path
run: echo "Playwright Browsers Path ---> ${{ env.PLAYWRIGHT_BROWSERS_PATH }}"
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium--with-deps ํ๋๊ทธ๋ฅผ ์ถ๊ฐํ๋ฉด ๋ธ๋ผ์ฐ์ ์คํ์ ํ์ํ ์์คํ
์์กด์ฑ(libglib, libgtk ๋ฑ)๋ ํจ๊ป ์ค์น๋๋ค.
์ค๋ฅ 2: ๋ฒ์ ๋ถ์ผ์น ์ค๋ฅ (playwright vs playwright-core)
Error: browserType.launch:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Looks like Playwright Test or Playwright was just updated to 1.40.0. โ
โ Please update docker image or install new browsers: โ
โ โ
โ npx playwright install โ
โ โ
โ <3 Playwright Team โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ์์ธ
playwright์ playwright-core๋ ๋ณ๊ฐ์ npm ํจํค์ง๋ค.
์ด๋ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ playwright-core๋ฅผ ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉํ๋๋ฐ, ๊ทธ ๋ฒ์ ์ด ์ง์ ์ค์นํ playwright ๋ฒ์ ๊ณผ ๋ค๋ฅผ ๊ฒฝ์ฐ ์ถฉ๋์ด ๋ฐ์ํ๋ค.
playwright: ๋ธ๋ผ์ฐ์ ๋ฐ์ด๋๋ฆฌ ํฌํจ + ํ ์คํธ ๋ฌ๋ ํฌํจplaywright-core: ๋ธ๋ผ์ฐ์ ๋ฐ์ด๋๋ฆฌ ๋ฏธํฌํจ (๋ณ๋ ์ค์น ํ์)
node_modules/
playwright/ # ๋ฒ์ 1.40.0
playwright-core/ # ๋ฒ์ 1.38.0 โ ๋ฒ์ ๋ถ์ผ์น!ํด๊ฒฐ ๋ฐฉ๋ฒ
package.json์์ ๋ฒ์ ์ ํต์ผํ๋ค.
{
"dependencies": {
"playwright": "1.40.0",
"playwright-core": "1.40.0"
}
}๋๋ npm ls playwright-core๋ก ์ด๋ค ํจํค์ง๊ฐ ์์กดํ๊ณ ์๋์ง ํ์ธํ ๋ค ํด๋น ํจํค์ง๋ ์
๋ฐ์ดํธํ๋ค.
npm ls playwright-core
# ์ถ๋ ฅ ์์:
# my-project@1.0.0
# โโโ @playwright/test@1.38.0
# โโโ playwright-core@1.38.0์ค๋ฅ 3: ์์กด์ฑ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋๋ฝ ์ค๋ฅ
Error: Failed to launch chromium because executable doesn't exist at ...
โโ Tip: Run playwright install --with-deps to install missing browsers and dependencies. โ
โ Missing libraries: โ
โ libgtk-3.so.0: not found โ
โ libnss3.so: not found โ
โ libnspr4.so: not found โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ์์ธ
Chromium์ ์คํํ๋ ค๋ฉด ์์คํ
์ ์ฌ๋ฌ ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค์น๋์ด ์์ด์ผ ํ๋ค.
GitHub Actions์ ubuntu-latest ์ด๋ฏธ์ง๋ ์ต์ ์ค์น ์ํ๋ก ์์ํ๊ธฐ ๋๋ฌธ์ ์ด๋ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ๋น ์ ธ ์๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค.
์ฃผ์ ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ:
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ | ์ฉ๋ |
|---|---|
libgtk-3.so.0 |
GTK UI ํดํท (Chromium UI ๋ ๋๋ง) |
libnss3.so |
Network Security Services (TLS/SSL) |
libnspr4.so |
Netscape Portable Runtime |
libasound2.so |
ALSA ์ค๋์ค (headless์์๋ ํ์) |
libgbm.so.1 |
GPU Buffer Management |
ํด๊ฒฐ ๋ฐฉ๋ฒ
- name: Install Playwright with system deps
run: npx playwright install --with-deps--with-deps๊ฐ ๊ฐ์ฅ ๊ฐ๋จํ ํด๊ฒฐ์ฑ
์ด๋ค. ํ์ํ ๋ชจ๋ ์์คํ
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์๋์ผ๋ก apt-get์ผ๋ก ์ค์นํด์ค๋ค.
ํน์ ๋ธ๋ผ์ฐ์ ๋ง ํ์ํ๋ค๋ฉด:
- name: Install Chromium only
run: npx playwright install --with-deps chromium์ค๋ฅ 4: ์บ์ ๋ฌธ์ ๋ก ์ธํ ์ค๋ฅ
Error: browserType.launch: Browser closed unexpectedly!
TROUBLESHOOTING: https://playwright.dev/docs/troubleshooting
at BrowserType.launch (node_modules/playwright-core/lib/server/browserType.js:90:13)๋๋ ๋ธ๋ผ์ฐ์ ๊ฐ ์คํ์ ๋์ง๋ง ์ฆ์ ํฌ๋์๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ.
์์ธ
- Playwright ๋ฒ์ ์ด ์ ๋ฐ์ดํธ๋์๋๋ฐ, ์ด์ ๋ฒ์ ์ ๋ธ๋ผ์ฐ์ ๋ฐ์ด๋๋ฆฌ๊ฐ ์บ์์ ๋จ์ ์๋ ๊ฒฝ์ฐ
- ๋ค์ด๋ก๋ ๋์ค ๋คํธ์ํฌ ์ค๋ฅ๋ก ์บ์ ํ์ผ์ด ์์๋ ๊ฒฝ์ฐ
ํด๊ฒฐ ๋ฐฉ๋ฒ
์บ์ ํค์ Playwright ๋ฒ์ ์ ํฌํจ์์ผ ๋ฒ์ ์ด ๋ฐ๋๋ฉด ์๋์ผ๋ก ์๋ก ๋ฐ๋๋ก ํ๋ค.
- name: Cache Playwright browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-depshashFiles('**/package-lock.json')์ ํค๋ก ์ฌ์ฉํ๋ฉด, package-lock.json์ด ๋ณ๊ฒฝ๋ ๋(์ฆ Playwright ๋ฒ์ ์ด ๋ฐ๋ ๋)๋ง๋ค ์๋ก์ด ์บ์๋ฅผ ์์ฑํ๋ค.
GitHub Actions ์บ์ ์ ๋ต
๋งค๋ฒ Playwright ๋ธ๋ผ์ฐ์ ๋ฅผ ์๋ก ๋ค์ด๋ก๋ํ๋ฉด CI ์คํ ์๊ฐ์ด ๊ธธ์ด์ง๋ค.
actions/cache๋ฅผ ์ฌ์ฉํด ๋ธ๋ผ์ฐ์ ๋ฅผ ์บ์ฑํ๋ฉด ์ด๋ฅผ ํฌ๊ฒ ์ค์ผ ์ ์๋ค.
์บ์ฑ ์๋ฆฌ
์บ์ ํจ๊ณผ
| ์ํฉ | ์์ ์๊ฐ |
|---|---|
| ์บ์ ์์ (์ต์ด ์คํ) | 3~5๋ถ (๋ธ๋ผ์ฐ์ ๋ค์ด๋ก๋) |
| ์บ์ HIT | 20~40์ด (๋ณต์๋ง) |
์ฌ๋ฐ๋ฅธ GitHub Actions Workflow ์ ์ฒด ์์
name: CI - E2E Test with Playwright
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
# 1. ์ฝ๋ ์ฒดํฌ์์
- name: Checkout repository
uses: actions/checkout@v4
# 2. Node.js ์ค์
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
# 3. ์์กด์ฑ ์ค์น
- name: Install dependencies
run: npm ci
# 4. Playwright ๋ธ๋ผ์ฐ์ ์บ์ ํ์ธ
- name: Cache Playwright browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-
# 5. Playwright ์ค์น ๊ฒฝ๋ก ํ๊ฒฝ ๋ณ์ ์ค์
- name: Set Playwright browsers path
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/ms-playwright" >> $GITHUB_ENV
# 6. ์บ์ MISS์ผ ๋๋ง ๋ธ๋ผ์ฐ์ ์ค์น
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
# 7. ์ค์น ๊ฒฝ๋ก ๊ฒ์ฆ
- name: Verify Playwright installation
run: |
echo "Playwright version: $(npx playwright --version)"
echo "Browsers path: $PLAYWRIGHT_BROWSERS_PATH"
ls -la $PLAYWRIGHT_BROWSERS_PATH || echo "Path not found"
# 8. E2E ํ
์คํธ ์คํ
- name: Run Playwright tests
run: npx playwright test
env:
CI: true
# 9. ํ
์คํธ ์คํจ ์ ๋ฆฌํฌํธ ์
๋ก๋ (์ ํ์ฌํญ)
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 7์ฃผ์ ํฌ์ธํธ ์ค๋ช
npm install๊ณผ ๋ฌ๋ฆฌ npm ci๋:
package-lock.json์ ๊ณ ์ ๋ ๋ฒ์ ๋ง ์ค์น (๋ฒ์ ๋๋ฆฌํํธ ๋ฐฉ์ง)node_modules๋ฅผ ๋จผ์ ์ญ์ ํ ์ฌ์ค์น (ํด๋ฆฐ ํ๊ฒฝ ๋ณด์ฅ)package-lock.json์ ์์ ํ์ง ์์
CI ํ๊ฒฝ์์๋ ํญ์ npm ci๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
if: steps.playwright-cache.outputs.cache-hit != 'true'
์บ์๊ฐ ์ด๋ฏธ ์์ผ๋ฉด ๋ธ๋ผ์ฐ์ ์ค์น ๋จ๊ณ๋ฅผ ๊ฑด๋๋ด๋ค.
๋จ, --with-deps๋ ์์คํ
์์กด์ฑ๋ ์ค์นํ๋ฏ๋ก, ์บ์๊ฐ ์๋๋ผ๋ ์์คํ
๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ ์ ์๋ค.
์์ ํ๊ฒ ํ๋ ค๋ฉด:
- name: Install system dependencies (even if browser cache hit)
run: npx playwright install-deps chromium
- name: Install Playwright Browsers (if no cache)
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install chromiumDocker ํ๊ฒฝ์์ Playwright ์คํ
๋ก์ปฌ ๊ฐ๋ฐ ํ๊ฒฝ์ด๋ Docker ๊ธฐ๋ฐ CI์์ Playwright๋ฅผ ์คํํ ๋๋ ๋ณ๋ ์ค์ ์ด ํ์ํ๋ค.
Dockerfile ์์ฑ
# Playwright ๊ณต์ ์ด๋ฏธ์ง ์ฌ์ฉ (๋ธ๋ผ์ฐ์ ๊ฐ ๋ฏธ๋ฆฌ ์ค์น๋์ด ์์)
FROM mcr.microsoft.com/playwright:v1.40.0-jammy
WORKDIR /app
# ์์กด์ฑ ์ค์น
COPY package*.json ./
RUN npm ci
# ์์ค ์ฝ๋ ๋ณต์ฌ
COPY . .
# ํ
์คํธ ์คํ
CMD ["npx", "playwright", "test"]Playwright ๊ณต์ Docker ์ด๋ฏธ์ง(mcr.microsoft.com/playwright)๋ฅผ ์ฌ์ฉํ๋ฉด ๋ธ๋ผ์ฐ์ ์ ๋ชจ๋ ์์คํ
์์กด์ฑ์ด ๋ฏธ๋ฆฌ ์ค์น๋์ด ์์ด ๋ณ๋ ์ค์น ๊ณผ์ ์ด ํ์ ์๋ค.
docker-compose๋ก ๋ก์ปฌ ํ ์คํธ
# docker-compose.yml
version: '3.8'
services:
playwright-test:
image: mcr.microsoft.com/playwright:v1.40.0-jammy
volumes:
- .:/app
- /app/node_modules
working_dir: /app
command: npx playwright test
environment:
- CI=true์คํ:
docker-compose run --rm playwright-test์ปค์คํ Node.js ์ด๋ฏธ์ง์์ ์ค์น
๊ณต์ ์ด๋ฏธ์ง ๋์ ์ผ๋ฐ Node.js ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ:
FROM node:20-slim
# Playwright๊ฐ ํ์ํ ์์คํ
ํจํค์ง ์ค์น
RUN apt-get update && apt-get install -y \
libglib2.0-0 \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxcb1 \
libxkbcommon0 \
libx11-6 \
libxcomposite1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libpango-1.0-0 \
libcairo2 \
libasound2 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm ci
RUN npx playwright install chromium
COPY . .
CMD ["npx", "playwright", "test"]๋๋ฒ๊น ํ
PWDEBUG ํ๊ฒฝ ๋ณ์
PWDEBUG=1 npx playwright testPWDEBUG=1์ ์ค์ ํ๋ฉด Playwright Inspector๊ฐ ์ด๋ฆฐ๋ค.
- ํ ์คํธ ์คํ์ ๋จ๊ณ๋ณ๋ก ์ผ์ ์ ์งํ ์ ์๋ค.
- ๊ฐ ์ก์ ์ ์ ๋ฉ์ถฐ์ ๋ธ๋ผ์ฐ์ ์ํ๋ฅผ ํ์ธํ ์ ์๋ค.
- ์ ๋ ํฐ๋ฅผ ์ง์ ์ํํด๋ณผ ์ ์๋ค.
# ํน์ ํ
์คํธ๋ง ๋๋ฒ๊น
PWDEBUG=1 npx playwright test --grep "๋ก๊ทธ์ธ ํ
์คํธ"--headed ์ต์
CI๊ฐ ์๋ ๋ก์ปฌ ํ๊ฒฝ์์ ํ ์คํธ๋ฅผ ์๊ฐ์ ์ผ๋ก ํ์ธํ ๋ ์ฌ์ฉํ๋ค.
# headless ๋์ ์ค์ ๋ธ๋ผ์ฐ์ ์ฐฝ์ ๋์์ ์คํ
npx playwright test --headed
# ์ฒ์ฒํ ์คํ (๊ฐ ์ก์
์ฌ์ด์ 500ms ๋๊ธฐ)
npx playwright test --headed --slow-mo=500์คํฌ๋ฆฐ์ท ๋ฐ ๋น๋์ค ๋ นํ
playwright.config.ts์์ ์คํจ ์ ์๋์ผ๋ก ์ฆ๊ฑฐ๋ฅผ ๋จ๊ธธ ์ ์๋ค:
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
// ํ
์คํธ ์คํจ ์ ์คํฌ๋ฆฐ์ท ์บก์ฒ
screenshot: 'only-on-failure',
// ํ
์คํธ ์คํจ ์ ๋น๋์ค ๋
นํ
video: 'retain-on-failure',
// ํ
์คํธ ์คํจ ์ trace ์ ์ฅ (์ฌํ ๊ฐ๋ฅ)
trace: 'on-first-retry',
},
retries: process.env.CI ? 2 : 0,
});--reporter ์ต์
์ผ๋ก ์์ธ ๋ก๊ทธ ํ์ธ
# HTML ๋ฆฌํฌํธ ์์ฑ (๋ธ๋ผ์ฐ์ ์์ ์ด ์ ์๋ UI)
npx playwright test --reporter=html
# ๋ฆฌํฌํธ ์ด๊ธฐ
npx playwright show-report์์ฃผ ํ๋ ์ค์ ์ ๋ฆฌ
1. install ์์ด ํ
์คํธ ์คํ
# ์๋ชป๋ ์
- run: npm ci
- run: npx playwright test # ๋ธ๋ผ์ฐ์ ๊ฐ ์์ด์ ์คํจ!
# ์ฌ๋ฐ๋ฅธ ์
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx playwright test2. sudo์ ํจ๊ป ์ค์น ํ ์ผ๋ฐ ์ฌ์ฉ์๋ก ์คํ
# ์๋ชป๋ ์ โ root๋ก ์ค์นํ๋ฉด /root/.cache์ ์ ์ฅ๋จ
sudo npx playwright install
# ์ดํ ์ผ๋ฐ ์ฌ์ฉ์๋ก ์คํํ๋ฉด /home/runner/.cache์์ ์ฐพ์ผ๋ฏ๋ก ์คํจ
npx playwright testํ๊ฒฝ ๋ณ์๋ก ๊ฒฝ๋ก๋ฅผ ๋ช
์ํ๊ฑฐ๋, sudo ์์ด ์ค์นํ๋ ๊ฒ์ด ๋ง๋ค.
3. CI์ CD ํ์ดํ๋ผ์ธ ๋ถ๋ฆฌ ์ ์บ์ ๋ฏธ๊ณต์
GitHub Actions์์ CI job๊ณผ CD job์ด ๋ถ๋ฆฌ๋์ด ์์ผ๋ฉด ์บ์๊ฐ ๊ณต์ ๋์ง ์๋๋ค. ๊ฐ job์์ ๋ ๋ฆฝ์ ์ผ๋ก Playwright๋ฅผ ์ค์นํด์ผ ํ๋ค.
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npx playwright install --with-deps chromium
- run: npx playwright test
deploy:
needs: test
runs-on: ubuntu-latest
steps:
# deploy job๋ Playwright๊ฐ ํ์ํ๋ค๋ฉด ์ฌ๊ธฐ์๋ ์ค์น
- run: npx playwright install --with-deps chromium4. playwright.config.ts ์์ด ์คํ
Playwright๋ ๊ธฐ๋ณธ ์ค์ ํ์ผ ์์ด๋ ์คํ๋์ง๋ง, ์๋ชป๋ ๊ธฐ๋ณธ๊ฐ์ ์ฌ์ฉํ ์ ์๋ค.
ํ๋ก์ ํธ ๋ฃจํธ์ playwright.config.ts๋ฅผ ํญ์ ๋ช
์์ ์ผ๋ก ์์ฑํ๋ ๊ฒ์ด ์ข๋ค.
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI, // CI์์ test.only ์ฌ์ฉ ๊ธ์ง
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
webServer: {
command: 'npm run start',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});5. ๋ก์ปฌ .env๋ฅผ CI์์ ์ค์ ์ ํจ
ํ ์คํธ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ฝ๋ ๊ฒฝ์ฐ, CI์์๋ ํด๋น ๊ฐ์ GitHub Secrets๋ก ์ค์ ํด์ผ ํ๋ค.
- name: Run Playwright tests
run: npx playwright test
env:
BASE_URL: ${{ secrets.TEST_BASE_URL }}
API_KEY: ${{ secrets.TEST_API_KEY }}์ต์ข ๋ฌธ์ ๋ถ์ ๋ฐ ํด๊ฒฐ ์์ฝ
๋ฌธ์ ๋ฐ์ ๋ฐฐ๊ฒฝ
- ๋ก์ปฌ ํ๊ฒฝ์์๋ ์ ์์ ์ผ๋ก ์๋ํ๋ Gatsby ๋ธ๋ก๊ทธ๊ฐ CI/CD ํ์ดํ๋ผ์ธ์์ Playwright ๋ธ๋ผ์ฐ์ ์ค์น ์ค๋ฅ๋ก ์ธํ ๋น๋ ์คํจ๊ฐ ๋ฐ์ํ๋ค.
- ํนํ, Playwright ์ค์น ํ, ๋ธ๋ผ์ฐ์ ์คํํ ๋ ๊ฒฝ๋ก๊ฐ ์ ๋๋ก ์ค์ ๋์ง ์์ ๋ฐ์ํ์๋ค.1
Error: Failed to launch chromium because executable doesn't exist
browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium-1124/chrome-linux/chrome์์ธ ๋ถ์
- ๊ถํ ๋ฌธ์ : Playwright ๋ธ๋ผ์ฐ์ ์ค์น ์ค ๊ถํ์ด ๊ฑฐ๋ถ๋จ.
sudo npx playwright install์ ์๋ํ์ผ๋ ์ฌ์ ํ ๋ฌธ์ ๋ฐ์. - ์ค์น ๊ฒฝ๋ก ๋ฌธ์ : Playwright์ ๊ธฐ๋ณธ ์ค์น ๊ฒฝ๋ก์ ๋ํ ๊ถํ ๋ฌธ์ ๋ก ๋ธ๋ผ์ฐ์ ๊ฐ ์ค์น๋์ง ์์๊ฑฐ๋, ์ค์น๋ ์์น์์ ์คํ๋์ง ์์.
ํด๊ฒฐ ๋ฐฉ๋ฒ
- ์ค์น ๊ฒฝ๋ก ์์ : Playwright ๋ธ๋ผ์ฐ์ ์ ์ค์น ๊ฒฝ๋ก๋ฅผ
$HOME/.cache/ms-playwright๋ก ๋ณ๊ฒฝํ๊ณ , ์ด ๊ฒฝ๋ก๋ฅผ ํ๊ฒฝ ๋ณ์๋ก ์ค์ . - ์บ์ ๋ฌดํจํ: ์์๋์๊ฑฐ๋ ์ถฉ๋์ด ๋ฐ์ํ ์ ์๋ ์บ์๋ฅผ ๋ฌดํจํํ๊ณ , ์ ์บ์ ์์ฑ.
- ์ค์น ๊ฒฝ๋ก ๊ฒ์ฆ: ์ค์น ํ ํด๋น ๊ฒฝ๋ก์ ๋ธ๋ผ์ฐ์ ๊ฐ ์ ๋๋ก ์ค์น๋์๋์ง ํ์ธํ๋ ์ ์ฐจ ์ถ๊ฐ.
- name: Set Playwright Browsers Path
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/ms-playwright" >> $GITHUB_ENV
- name: Check Playwright Browsers Path
run: echo "Playwright Browsers Path ---> ${{ env.PLAYWRIGHT_BROWSERS_PATH }}"
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium๊ฒฐ๋ก
Playwright๋ ๊ฐ๋ ฅํ E2E ํ ์คํธ ๋๊ตฌ์ด์ง๋ง, CI/CD ํ๊ฒฝ์์ ์ฒ์ ์ค์ ํ ๋ ๋ธ๋ผ์ฐ์ ์ค์น ๊ฒฝ๋ก ๋ฌธ์ ๋ก ์ด๋ ค์์ ๊ฒช๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค.
ํต์ฌ ์ฒดํฌ๋ฆฌ์คํธ:
npm ci๋ก ์์กด์ฑ ์ค์น ํ ๋ฐ๋์npx playwright install --with-deps๋ก ๋ธ๋ผ์ฐ์ ์ค์นPLAYWRIGHT_BROWSERS_PATHํ๊ฒฝ ๋ณ์๋ก ์ค์น ๊ฒฝ๋ก ๋ช ์actions/cache๋ก ๋ธ๋ผ์ฐ์ ์บ์ฑํ์ฌ CI ์๋ ๊ฐ์playwrightvsplaywright-core๋ฒ์ ํต์ผ ํ์ธ- ์คํจ ์ ์คํฌ๋ฆฐ์ท/trace ์ ์ฅ์ผ๋ก ๋๋ฒ๊น ํธ์์ฑ ํ๋ณด
- Docker ํ๊ฒฝ์์๋ Playwright ๊ณต์ ์ด๋ฏธ์ง ํ์ฉ
์ด๋ฌํ ์ค์ ์ ๊ฐ์ถ๋ฉด ๋ก์ปฌ ํ๊ฒฝ๊ณผ CI/CD ํ๊ฒฝ ๋ชจ๋์์ ์์ ์ ์ธ ํ ์คํธ ์คํ์ด ๊ฐ๋ฅํ๋ค.
