Search code examples
javaseleniumselenium-webdriverwebdriver

What is the difference between build().perform() and perform()


Some articles suggest that now build() is included in perform() itself, while others suggest that build().perform() is used when multiple actions are to be chained together.


Solution

  • build() is included in perform(), you can see it in the source code

    public void perform() {
        build().perform();
    }
    

    The perform() inside the methods calls the perform() method in the inner class BuiltAction.

    Calling build().perform() in your code is actually calling build() twice, build().build().perform().

    build

    Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).

    performe

    A convenience method for performing the actions without calling build() first.

    This is little misleading (IMO), because build() is being called, even if implicitly.