我将硒和chromedriver升级到了最新版本。 这样做之后,使用相同的(仍然有效)DesiredCapabilities对象创建新的chromedriver实例时,出现以下警告:
WARNING: Attempt to convert JsonElement from GSON. This functionality is deprecated.
其他人是否有这个问题/知道如何解决/抑制它?
我应该注意,我运行了一个测试套件,它通过了OK,只是打印了此警告。
在MacOS和远程linux主机上本地运行它。
详细信息:
MacOS:
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'mac-lap-13', ip: '0.0.0.0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_162'
Linux:
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'Automation', ip: '0.0.0.0', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-25-generic', java.version: '1.8.0_111'
完整stackTrace:
Starting ChromeDriver 2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db) on port 46910
Only local connections are allowed.
Aug 09, 2018 3:52:54 PM org.openqa.selenium.json.JsonOutput lambda$new$11
WARNING: Attempt to convert JsonElement from GSON. This functionality is deprecated. Diagnostic stacktrace follows
org.openqa.selenium.json.JsonException: Stack trace to determine cause of warning
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'mac-lap-13', ip: '0.0.0.0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_162'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.json.JsonOutput.lambda$new$11(JsonOutput.java:129)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:300)
at org.openqa.selenium.json.JsonOutput.lambda$new$13(JsonOutput.java:139)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$20(JsonOutput.java:161)
at java.util.TreeMap.forEach(TreeMap.java:1005)
at java.util.Collections$UnmodifiableMap.forEach(Collections.java:1505)
at org.openqa.selenium.json.JsonOutput.lambda$new$21(JsonOutput.java:160)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$20(JsonOutput.java:161)
at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:65)
at org.openqa.selenium.json.JsonOutput.lambda$new$21(JsonOutput.java:160)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:239)
at org.openqa.selenium.json.Json.toJson(Json.java:42)
at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:99)
at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:93)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:174)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:142)
at com.d5.automation.uitester.webdriver.ClientReactTest.setUpForTests(ClientReactTest.java:227)
at com.d5.automation.uitester.webdriver.ClientReactTest.startWebDriver(ClientReactTest.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.Verifier$1.evaluate(Verifier.java:35)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.runner.JUnitCore.run(JUnitCore.java:105)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:62)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:49)
at com.d5.automation.uitester.CiCdTests.ciCdFrontEndTest(CiCdTests.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Aug 09, 2018 3:52:56 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
答案 0 :(得分:2)
如前所述,您已经将 Selenium 和 ChromeDriver 升级到了最新版本,即 Selenium v3.13.0 和 ChromeDriver v2.41 ,并使用(仍有效)DesiredCapabilities
类型的对象创建了一个新的 ChromeDriver 实例,是仍然有效。但是您一定已经看到弃用 警告,如下所示:
进一步执行代码块时,您将找到以下 INFO :
Aug 10, 2018 1:02:08 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 44262
Only local connections are allowed.
Aug 10, 2018 1:02:12 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Google
因此,根据最佳做法,您必须开始使用new ChromeOptions()
,如下所示:
package demo; //replace by your own package name
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class A_Chrome_Options_test {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
ChromeOptions opt = new ChromeOptions();
opt.merge(cap);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");
System.out.println(driver.getTitle());
driver.quit();
}
}
关于警告:
WARNING: Attempt to convert JsonElement from GSON. This functionality is deprecated. Diagnostic stacktrace follows
org.openqa.selenium.json.JsonException: Stack trace to determine cause of warning
Selenium v3.13.0 的发行说明明确提到:
- 介绍了我们自己的JSON解析器和输出器,允许将GSON从依赖项中删除。
因此您会看到错误。
要摆脱警告和错误,请升级到 Selenium v3.14.0 ,其中 Release Notes 明确提到:
- 完全删除了GSON依赖项。现在,我们使用反射来尝试找到类。
答案 1 :(得分:-1)
使用适用于Chrome WebDriver的org.seleniumhq.selenium最新版本和以下代码:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.merge(cap);
new ChromeDriver(chromeOptions);