java 使用“new EdgeOptions()”优于“DesiredCapabilities”,edge()`通过Jenkins和Selenium启动远程Microsoft Edge浏览器时出错

1mrurvl1  于 2023-04-28  发布在  Java
关注(0)|答案(2)|浏览(130)

有一个网站,我应该在远程边缘浏览器中使用Java中的Selenium进行测试。但是我在任何地方都找不到远程边缘浏览器的代码。而在本地,我可以打开边缘浏览器并进行测试。
浏览器版本:- Microsoft Edge 41。16299.1004.0 Microsoft 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)
lnlaulya

lnlaulya1#

要使用Selenium而不是使用DesiredCapabilities()从Jenkins Job启动 Remote Microsoft Edge Browser,您需要使用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);

您可以在How to Merge Chrome driver service with desired capabilities for headless using xvfb?

wljmcqd8

wljmcqd82#

尝试使用新的DesiredCapabilities

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();

相关问题