Home > Back-end >  WebDriverManager throwing TypeNotPresentException
WebDriverManager throwing TypeNotPresentException

Time:02-17

I am trying to replace my local geckodriver.exe with WebDriverManager, but when i invoke

WebDriverManager.firefoxdriver().setup();

i get the following error

4391 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4704 [main] WARN io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present) ... trying again using latest driver stored in cache
4704 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4876 [main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present)
java.lang.TypeNotPresentException: Type com.google.gson.internal.LinkedTreeMap not present
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
    ...
    at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:825)
    at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:802)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:599)
    at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)

I am using the latest 5.0.3 WebDriverManager from maven

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
</dependency>

CodePudding user response:

Change the WebDriverManager scope to test in pom.xml as follows:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <scope>test</scope>
</dependency>

or change the scope to compile in pom.xml as follows:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <scope>compile</scope>
</dependency>

Additionally, you may need to add the slf4j dependency as follows:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>

As per Driver Management - Feature:

Although not mandatory, it is highly recommended to use a logger library to trace your application and tests. In the case of WebDriverManager, you will see the relevant steps of the driver management following its traces. See for example the following tutorial to use SLF4J and Logback. Also, you can see an example of a WebDriverManager test using logging here (this example uses this configuration file).


Reference

You can find a couple of relevant detailed discussion in:

CodePudding user response:

TypeNotPresentException is thrown when an application tries to access a type using a string representing the type's name, but no definition for the type with the specified name can be found.

It's pretty similar to ClassNotFoundException, but not checked during compilation.

But the root cause is:

com.google.gson.internal.LinkedTreeMap not present in the project classpath.

Try to add gson dependency to the project.

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.9.0</version>
</dependency>

  • Related