2

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?

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
Devdutta Goyal
  • 985
  • 2
  • 11
  • 27

2 Answers2

3

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.

Muzzamil
  • 2,823
  • 2
  • 11
  • 23
1

Guava

Guava is an open source, Java-based library developed by Google. It facilitates developers and test automation engineers in adapting best coding practices and helps reduce coding errors. It provides utility methods for collections, caching, primitives support, concurrency, common annotations, string processing, I/O, and validations.


Maven Dependency

As of Selenium v3.141.59 clients the Maven Dependency is:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>25.0-jre</version>
</dependency>

tl; dr

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352