How to integrate Guice + Cucumber + WebDriver

Hello guys,

Today I am going to post about something that I have been studying. So, in this project you can have an idea of how to implement Dependency Injection using Guice, a Google framework which helps you to reduce the need of new in your Java code. I found only projects that have only the Guice + Cucumber integration or only the Guice + Page Objects, so I think this one might be a good example of how to integrate everything.

Also, the project contains Page Objects and a Driver Factory, so you will be able to include other browsers and implement each one’s singularity when creating the browser, and also you still have the good practices of the POM.

I’ve added comments along the code, but feel free to ask anything or even suggest improvements.

https://github.com/rafaelaazevedo/dog-lightning

5 thoughts on “How to integrate Guice + Cucumber + WebDriver

  1. Hi Rafaela,
    Thanks very much for the excellent article. Today I tried to implement it in a project and got the an error which took me a while to resolve. The error text is given below:
    java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap.of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)’

    This error was resolved by adding the latest version of Guava to the dependencies in my Maven POM file. The Guava dependency XML is given below. I hope this comment brings more traffic to your post. Keep up the great work. ❤

    com.google.guava
    guava
    31.1-jre

  2. Hi,
    Today I tried to implement your solution. All went smoothly other than just one problem caused by the Guava dependency. I added the latest version of Guava to my POM file, which fixed it. The exact error text is given below FYI & SEO:

    java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap.of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)’

Leave a reply to Sam Ganepola Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.