使用 `new EdgeOptions()` 优于通过 Jenkins 和 Selenium 启动远程 Microsoft Edge 浏览器的 `DesiredCapability.edge()` 错误

问题描述 投票:0回答:2

我打算使用 Java 中的 Selenium 在远程边缘浏览器中测试一个网站。但我无法找到远程边缘浏览器的代码。而在本地,我可以打开边缘浏览器并进行测试。

浏览器版本:- 微软边缘41.16299.1004.0 微软EdgeHTML 16.16299 驱动程序版本:- 版本:5.16299 |支持的 Microsoft Edge 版本:16.16299

并且不存在版本问题,因为它与本地边缘浏览器一起使用。

到目前为止,我已经有了通过 Java 中的 Selenium 在本地打开边缘浏览器来测试网站的代码。而且工作正常

System.setProperty( "webdriver.edge.driver",
System.getProperty("user.dir")+"/MicrosoftWebDriver.exe" );
HashMap<String, Object> edgePrefs = new HashMap<String, Object>();
edgePrefs.put("profile.default_content_settings.popups", 0);
EdgeOptions options = new EdgeOptions();
options.setCapability("prefs", edgePrefs);
options.setCapability("useAutomationExtension", false);
WebDriver driver = new EdgeDriver(options);

对于远程边缘浏览器,我有以下代码,它不起作用

System.setProperty( "webdriver.edge.driver",  System.getProperty("user.dir")+"/MicrosoftWebDriver.exe" );
URL hubUrl = new URL("http://wiqaseleniumhub.fmr.com:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(hubUrl, DesiredCapabilities.edge());

使用 RemoteWebDriver for Edge 运行远程边缘浏览器时。低于错误。

Aug 07, 2019 4:50:14 PM org.openqa.selenium.remote.DesiredCapabilities edge
INFO: Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()`
FAILED: planTypesAndPlanTest
org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: MicrosoftEdge, platform: WINDOWS, version: }
Command duration or timeout: 1.13 seconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at Utils.Functionality.edgeDriver(Functionality.java:90)
    at Utils.Functionality.getDriver(Functionality.java:167)
    at Utils.Functionality.fieldConfigTesting(Functionality.java:666)
    at com.Automation.Test.AutomationMain.planTypesAndPlanTest(AutomationMain.java:211)
    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:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
java selenium jenkins selenium-webdriver microsoft-edge
2个回答
0
投票

要使用 Selenium 而不是使用 DesiredCapabilities() 从 Jenkins 作业启动

远程 Microsoft Edge 浏览器
,您需要使用
EdgeOptions()
,如下所示:

System.setProperty( "webdriver.edge.driver", System.getProperty("user.dir")+"/MicrosoftWebDriver.exe" );
EdgeOptions options = new EdgeOptions();
options.setCapability("useAutomationExtension", false);
URL hubUrl = new URL("http://wiqaseleniumhub.fmr.com:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(hubUrl, options);

您可以在如何使用 xvfb 将 Chrome 驱动程序服务与所需的 Headless 功能合并?

中找到相关讨论

0
投票

使用新的所需功能尝试此操作

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "MicrosoftEdge");
URL url=new URL("http://localhost:4444/wd/hub");
RemoteWebDriver driver =new RemoteWebDriver(url, capabilities);
driver.get("https://google.com/");
System.out.println("Title:: "+driver.getTitle());
driver.quit();
© www.soinside.com 2019 - 2024. All rights reserved.