Chapter 28: Typed classes and access modifiers
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Typed classes and access modifiers
TypeScript classes support typed fields, constructors and visibility modifiers such as public and private. readonly prevents reassignment through the type system after initialization. These features help page objects expose actions while organizing internal state.
How it works
Step-by-step walkthrough
- Create a typed class
- Initialize a field
- Call a public method
Example
class Config {
constructor(private readonly browser: string) {}
describe(): string { return this.browser; }
}
console.log(new Config('chromium').describe());TypeScript private is not the same as JavaScript # runtime private fields.
✎ Your practice task
Try accessing browser directly from outside the class.
Knowledge check
Which modifier prevents normal reassignment after initialization?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.