binzunu1909 / ui-test-selenium

Testing on Web API server about School Management
1 stars 0 forks source link

[Apply Method Chainning to Code] #13

Open binzunu1909 opened 1 year ago

binzunu1909 commented 1 year ago

I. Define:

Method chaining is a programming technique that allows multiple methods calls to be chained together in a single line of code. It involves invoking methods on an object one after another, where each method call returns the object itself or another object that has additional methods to be called.

In method chaining, the return type of each method is typically the same as the type of the object on which the method is called. This enables subsequent method calls to be chained directly on the result of the previous method call, without the need for intermediate variables.

II. Example:

public class TestSelenium {
    private WebDriver driver;

    public TestSelenium navigateTo(String url) {
        driver.get(url);
        return this;
    }

    public TestSelenium performLogin(String username, String password) {
        return this;
    }

    public static void main(String[] args) {
        TestSelenium test = new TestSelenium();
        test.navigateTo("https://example.com").performLogin("username", "password");
    }
}