Search code examples
javamavenseleniumguava

Why we need guava in selenium webdriver?


I created selenium web driver project with maven. I read somewhere we need to add guava dependency.

Can anybody why we need guava dependency with selenium?


Solution

  • This is the best information I can arrange.

    Summarize Answer:

    Selenium uses Guava libraries for Function and Predicates.

    Reference for above quote (Page-126) :

    https://books.google.de/books?id=PMNiDwAAQBAJ&pg=PA126&lpg=PA126&dq=selenium+and+guava&source=bl&ots=hxRq2Dq61Y&sig=ACfU3U3ro_HhI4cpejvSSSEvWYZMF99l9g&hl=en&sa=X&ved=2ahUKEwiO7oOP6PHmAhUCCewKHfnJDSs4ChDoATABegQIChAB#v=onepage&q&f=false

    Brief about Function and Predicates with example used in Selenium:

    Guava provides two basic "functional" interfaces:

    • Function, which has the single method B apply(A input). Instances of Function are generally expected to be referentially transparent -- no side effects -- and to be consistent with equals, that is, a.equals(b) implies that function.apply(a).equals(function.apply(b))

    Example:

    public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
            }
    

    here you can also check. Mainly used in Selenium Waits (except implicit).

    • Predicate, which has the single method boolean apply(T input). Instances of Predicate are generally expected to be side-effect-free and consistent with equals.

    Example:

    selenium filter with Predicate

    here you can find details of Function and Predicates on Guava official Documentation

    I hope it will help you.