java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;

拟墨画扇 提交于 2021-01-29 05:30:28

问题


When I try to create a RemoteWebDriver in 3.11, I see this error below. This worked fine up through 3.10. I've reverted to 3.10 for now.

I tried adding in the gson jar from google, but I still see same error. Anyone else see this? I'm running one selenium server as hub, and then running a node against it with webdriver for ff or chrome, same issue.

com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;

java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
at org.openqa.selenium.json.Json.(Json.java:47)
at org.openqa.selenium.logging.profiler.HttpProfilerLogEntry.constructMessage(HttpProfilerLogEntry.java:37)
at org.openqa.selenium.logging.profiler.HttpProfilerLogEntry.(HttpProfilerLogEntry.java:29)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:135)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:132)
at oracle.ojet.automation.test.selenium.WebDriverManager._buildRemoteWebDriver(WebDriverManager.java:573)

回答1:


This error message...

java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;

...implies that the JVM was unable to find the method setLenient()Lcom/google/gson/GsonBuilder.


Reason

Release Notes of Selenium v3.10.0 clearly mentions:

  • Migrate Selenium Grid to reduce exporting GSON and Apache HttpClient as much to public APIs.

Further, Release Notes of Selenium v3.12.0 clearly mentions:

  • Remove GSON from how we coerce JSON to Java types.
  • Clean up the internals of Selenium's JSON handling, including deprecating places where GSON leaks from our APIs.

Finally, Release Notes of Selenium v3.13.0 clearly mentions:

  • Introduced our own JSON parser and outputter, allowing GSON to be removed from our dependencies.

Solution

To get rid of the warning and errors upgrade to Selenium v3.14.0, where Release Notes clearly mentions:

  • Completely removed the GSON dependency. We now use reflection to try and find the class.


来源:https://stackoverflow.com/questions/51819550/java-lang-nosuchmethoderror-com-google-gson-gsonbuilder-setlenientlcom-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!