Lesson 4 of 9
Lesson 04 — Interfaces shape automation contracts
Title: Structuring payloads, credentials, and Page contracts
Description: Interfaces describe allowed keys on objects — fixtures, REST bodies, POM boundaries — without caring about runtime class mechanics yet.
Why it matters for QA: Teams serialize JSON constantly; typed interfaces mirror backend schemas so mocks stay trustworthy.
1. Basic interface
interface User {
email: string;
password: string;
}
const user: User = {
email: "test@mail.com",
password: "123456",
};
2. Missing fields fail compile-time
// Uncomment to watch TypeScript complain — password missing.
// const brokenUser: User = {
// email: "oops@mail.com",
// };
3. QA-centric interfaces
Login payloads:
interface LoginCredentials {
email: string;
password: string;
rememberMe?: boolean;
}
API persona responses:
interface UserResponse {
id: number;
name: string;
email: string;
}
4. Interfaces plus classes (implements)
Useful when multiple pages share lifecycle hooks:
interface OpensPage {
open(): Promise<void>;
}
class LoginPage implements OpensPage {
async open(): Promise<void> {
console.log("navigate → /login");
}
}
5. Practice
- Extend UserResponse interface Add a new optional field:
- avatarUrl?: string
- it is a link to the user’s avatar image
- it is optional (may be missing)
- Create BugTicket interface Create an interface with:
- title → bug name
- severity → bug level: "low", "medium", or "high"
- steps → list of steps to reproduce the bug (array of strings)
6. Stretch goal
Explore extends:
interface Admin extends UserResponse {
permissions: string[];
}
This is about when to avoid repeating code and when it’s actually better to keep things separate.