Playwright + Java · Lesson 5 of 38
Module 5: Methods
Try it yourself
Create a method formatUrl:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
public class NavigationHelper {
// Overloaded method without timeout:
public static void navigateTo(String path) {
navigateTo(path, 30000);
}
// Overloaded method with custom timeout:
public static void navigateTo(String path, int timeoutMs) {
System.out.println("Navigating to " + path + " with timeout " + timeoutMs);
}
}public: Accessible anywhere in the test framework.protected: Accessible within package and subclasses.private: Encapsulated inside the page or helper class.Methods encapsulate reusable test actions, locator strategies, and assertions. In this lesson, you will learn parameters, return types, method overloading, and access modifiers to design clean test helpers. Let's build reusable methods!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Static methods are great for stateless utilities (e.g. string formatting, date generators). Instance methods are needed when holding page state or browser instances.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.