3.2Format 1: Live Coding Challenges
What to Expect
You are given a testing-related coding problem and 30-60 minutes to solve it while the interviewer watches. The problem usually involves one of:
- Writing a Page Object Model from scratch
- Building API test automation with assertions
- Debugging a failing test
- Parsing and validating test data
- Writing a utility function for test infrastructure
Sample Challenge: Build a Page Object Model
Prompt: "Here is a login page with a username field, password field, remember-me checkbox, and submit button. Write a Page Object and a test that verifies successful login, failed login with wrong password, and the remember-me functionality."
What a strong answer looks like (Playwright + TypeScript):
// login.page.ts
import { Page, Locator } from '@playwright/test';
export class LoginPage {
readonly page: Page;
readonly usernameInput: Locator;
readonly passwordInput: Locator;
readonly rememberMeCheckbox: Locator;
readonly submitButton: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
this.usernameInput = page.getByLabel('Username');
this.passwordInput = page.getByLabel('Password');
this.rememberMeCheckbox = page.getByLabel('Remember me');
this.submitButton = page.getByRole('button', { name: 'Sign in' });
this.errorMessage = page.getByRole('alert');
}
async goto() {
await this.page.goto('/login');
}
async login(username: string, password: string, rememberMe = false) {
await this.usernameInput.fill(username);
await this.passwordInput.fill(password);
if (rememberMe) {
await this.rememberMeCheckbox.check();
}
await this.submitButton.click();
}
}
// login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from './login.page';
test.describe('Login', () => {
let loginPage: LoginPage;
test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
await loginPage.goto();
});
test('successful login redirects to dashboard', async ({ page }) => {
await loginPage.login('validuser', 'validpass');
await expect(page).toHaveURL('/dashboard');
});
test('wrong password shows error message', async () => {
await loginPage.login('validuser', 'wrongpass');
await expect(loginPage.errorMessage).toBeVisible();
await expect(loginPage.errorMessage).toHaveText(
'Invalid username or password'
);
});
test('remember me persists session after browser restart', async ({
page,
context,
}) => {
await loginPage.login('validuser', 'validpass', true);
await expect(page).toHaveURL('/dashboard');
// Verify cookie is set with extended expiry
const cookies = await context.cookies();
const sessionCookie = cookies.find((c) => c.name === 'session');
expect(sessionCookie).toBeDefined();
expect(sessionCookie!.expires).toBeGreaterThan(Date.now() / 1000 + 86400);
});
});
What the interviewer evaluates:
- User-facing locator strategy (getByLabel, getByRole) rather than brittle CSS selectors
- Separation of page interactions from test assertions
- Meaningful test names that describe expected behavior
- Proper use of setup (beforeEach) and parameterization
- Edge case thinking (the remember-me test checks the cookie, not just the checkbox)
Sample Challenge: API Test Automation
Prompt: "Write tests for a REST API endpoint POST /api/users that creates a new user. The endpoint accepts {name, email, role} and returns the created user with an id. Test the happy path and at least 3 error cases."
import requests
import pytest
BASE_URL = "https://api.example.com"
class TestCreateUser:
def test_create_user_success(self):
payload = {"name": "Jane Doe", "email": "jane@example.com", "role": "tester"}
response = requests.post(f"{BASE_URL}/api/users", json=payload)
assert response.status_code == 201
data = response.json()
assert data["name"] == "Jane Doe"
assert data["email"] == "jane@example.com"
assert data["role"] == "tester"
assert "id" in data
assert isinstance(data["id"], int)
def test_create_user_missing_required_field(self):
payload = {"name": "Jane Doe"} # missing email and role
response = requests.post(f"{BASE_URL}/api/users", json=payload)
assert response.status_code == 400
assert "email" in response.json()["errors"]
def test_create_user_invalid_email(self):
payload = {"name": "Jane Doe", "email": "not-an-email", "role": "tester"}
response = requests.post(f"{BASE_URL}/api/users", json=payload)
assert response.status_code == 400
assert "email" in response.json()["errors"]
def test_create_user_duplicate_email(self, create_test_user):
payload = {"name": "Another Jane", "email": create_test_user["email"], "role": "tester"}
response = requests.post(f"{BASE_URL}/api/users", json=payload)
assert response.status_code == 409
def test_create_user_invalid_role(self):
payload = {"name": "Jane Doe", "email": "jane2@example.com", "role": "superadmin"}
response = requests.post(f"{BASE_URL}/api/users", json=payload)
assert response.status_code == 400
Sample Challenge: Debugging a Failing Test
Prompt: "This test passes locally but fails in CI. Find the bug."
def test_report_generation():
report = generate_report(start_date="2025-01-01", end_date="2025-01-31")
assert report.title == "Monthly Report - January 2025"
assert report.generated_at.date() == datetime.date.today()
What to identify: The test is brittle because datetime.date.today() returns a different value depending on when and where it runs. In CI, the timezone might differ from local, and if the test runs around midnight, the date could be off by one. The fix is to mock datetime.date.today() or assert within a time window rather than an exact date.