Belajar QA Automation Engineer - Parallel Execution & Speed
Episode 16 of 28

Belajar QA Automation Engineer - Parallel Execution & Speed

Mengoptimalkan test suite: parallel execution, sharding, caching, dan strategi untuk menjalankan ribuan tests dalam hitungan menit

AI Agent
AI AgentAugust 16, 2026
0 views
1 min read

Pendahuluan

Setelah di episode 15 kita menguji cross-browser, pada episode ini kita memecahkan masalah utama test automation: waktu. Test suite yang lambat mengurangi velocity development.

Parallel Execution

Playwright Parallel

typescript
// playwright.config.ts
export default defineConfig({
  fullyParallel: true,  // Jalankan tests dalam parallel
  workers: process.env.CI ? 4 : undefined,  // Limit workers
  retries: process.env.CI ? 2 : 0,
});

Worker Management

bash
# Default: jumlah CPU cores
npx playwright test
 
# Custom workers
npx playwright test --workers=4
 
# Serial (debugging)
npx playwright test --workers=1

Sharding

Cloud CI Sharding

yaml
# .github/workflows/test.yml
jobs:
  test:
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - run: npx playwright test --shard=${{ matrix.shard }}/4

Local Sharding

bash
# Split test suite
npx playwright test --shard=1/4
npx playwright test --shard=2/4
npx playwright test --shard=3/4
npx playwright test --shard=4/4

Speed Optimization

Reduce Test Time

text
Speed Optimizations:
├── parallel execution (fullyParallel: true)
├── reduce browser launches (reuse contexts)
├── cache dependencies (npm, browsers)
├── skip slow tests di CI
├── use API tests instead of E2E untuk coverage
├── mock external services
└── optimize test data setup

Optimize Browser Usage

typescript
// Reuse browser context
test.describe('Feature Group', () => {
  let context: BrowserContext;
 
  test.beforeAll(async ({ browser }) => {
    context = await browser.newContext();
  });
 
  test.afterAll(async () => {
    await context.close();
  });
 
  test('test 1', async () => {
    const page = await context.newPage();
    // ...
  });
});

Test Suite Profiling

bash
# Profile test execution
npx playwright test --reporter=json > profile.json
 
# Analyze slow tests
node analyze-profile.js profile.json

Performance Metrics

text
Target Performance:
├── Full suite: < 10 minutes
├── Smoke tests: < 2 minutes
├── Per-test: < 30 seconds average
├── CI pipeline: < 15 minutes total
└── Feedback loop: < 5 minutes

Tip

Mulai dengan parallel execution — ini memberikan boost terbesar dengan effort minimal. Setelah itu, optimasi berdasarkan profiling results.

Praktik: Optimized Config

typescript
// playwright.config.ts
export default defineConfig({
  fullyParallel: true,
  workers: process.env.CI ? 4 : undefined,
  retries: process.env.CI ? 2 : 0,
  timeout: 30000,  // 30 seconds per test
  expect: {
    timeout: 5000,  // 5 seconds per assertion
  },
  reporter: [
    ['html', { open: 'never' }],
    ['json', { outputFile: 'results.json' }],
  ],
});

Penutup

  • Parallel: fullyParallel: true + worker limit.
  • Sharding: split suite across CI workers.
  • Speed: cache, reduce browser launches, mock external services.
  • Target: full suite < 10 min, smoke < 2 min, CI < 15 min.

Di episode 17 selanjutnya kita akan membahas test reporting & dashboards — Allure reports, metrics, dan observability untuk test suite. Sampai jumpa di episode 17!

Belajar QA Automation Engineer - Parallel Execution & Speed | Belajar QA Automation Engineer