5. Methods, Overloading & Access Modifiers

Method Design in Test Utilities

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);
}
}

Access Modifiers

- public: Accessible anywhere in the test framework. - protected: Accessible within package and subclasses. - private: Encapsulated inside the page or helper class. - default (package-private): Accessible inside the same package.

Task

  • Create a method formatUrl:
  • 1. Accept baseUrl (String) and path (String).
  • 2. If baseUrl ends with '/' and path starts with '/', remove one slash.
  • 3. Return the clean concatenated URL string.
πŸ’‘Common doubts
Did you like the problem?
Lesson 5 of 38
Java
Loading code editor…
Next