TypeScript · @playwright/test
Fantasy sports with Playwright
Pick 11 players under a 100-credit budget with a 7-per-team cap and role minimums/maximums — every blocked + explains why — then choose captain and vice-captain, save, and see your leaderboard rank.
App under test
🏏 FantasyXI
- URL
- /apps/fantasy
- Login
- player11 / Play@123
- Budget
- 100 credits · 11 players
- Per team
- max 7
- Multipliers
- C 2× · VC 1.5×
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Account login
BeginnerUsername + password (fx-login-id, fx-password, fx-login). Teams and rank belong to the signed-in account; fx-logout signs out.
- 2
Counters
BeginnerEach pick updates players-selected, credits-left, count-IND/AUS and role-count-*.
- 3
Disabled with a reason
IntermediateWhen a rule blocks a player, pick-<id> is disabled and its title / block-<id> text says why.
- 4
Budget rule
IntermediatePick expensive players until “Not enough credits” appears.
- 5
Team cap
IntermediateAfter 7 IND players, every other IND pick is blocked.
- 6
Role limits
AdvancedRole max and “leave room for other roles' minimums” both block picks — test both.
- 7
Captain rules
IntermediateThe same player can't be both C and VC; projected-points recalculates with multipliers.
- 8
Countdown lock
Advancedlock-countdown-* ticks every second; the semi-final shows locked-m2 and a disabled button.
- 9
Leaderboard sort
Beginnersort-points toggles order and aria-sort; your team is highlighted with my-rank.
Sample Playwright suite
A working starting point that finds elements every way Playwright can — by role, label, text, id, name, CSS, XPath and data-testid — so you practice them all. Pick your language, switch to data-testid only to compare, or try your own in the Locator Playground.
import { test, expect } from '@playwright/test';
// playwright.config.ts → use: { baseURL: 'https://www.practiceqaautomation.com' }
// Locators in this suite: getByRole ×2 · getByLabel ×2 · CSS ×1 · XPath ×1 · getByTestId ×25
test('builds a valid XI and checks its rank', async ({ page }) => {
await page.goto('/apps/fantasy');
// Sign in first
await page.getByLabel('Username').fill('player11');
await page.locator('#fx-password').fill('Play@123');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByTestId('create-team-m1').click();
await page.getByTestId('role-wk').click();
await page.getByTestId('pick-ind-wk1').click();
await page.getByTestId('role-bat').click();
await page.getByTestId('pick-ind-b2').click();
await page.getByTestId('pick-ind-b4').click();
await page.getByTestId('pick-aus-b1').click();
await page.getByTestId('pick-aus-b4').click();
await page.getByTestId('role-ar').click();
await page.getByTestId('pick-ind-ar1').click();
await page.getByTestId('pick-aus-ar2').click();
await page.getByTestId('role-bowl').click();
await page.getByTestId('pick-ind-bo1').click();
await page.getByTestId('pick-ind-bo3').click();
await page.getByTestId('pick-aus-bo3').click();
await page.getByTestId('pick-ind-bo4').click();
await expect(page.getByTestId('players-selected')).toContainText('11/11');
await expect(page.getByTestId('credits-left')).toContainText('0.0');
await expect(page.getByTestId('count-IND')).toContainText('7');
await page.getByTestId('next-captain').click();
await page.getByTestId('captain-ind-ar1').click();
await page.getByTestId('vc-aus-b1').click();
await expect(page.getByTestId('projected-points')).toContainText('865');
await page.getByLabel('Team name').fill('Amir XI');
await page.locator('xpath=//button[normalize-space()="Save team"]').click();
await expect(page.getByTestId('team-points')).toContainText('865');
await page.getByRole('link', { name: 'Leaderboard' }).click();
await expect(page.getByTestId('my-rank')).toContainText('#6');
});