簡體   English   中英

使用“new EdgeOptions()”優於“DesiredCapabilities.edge()”錯誤通過Jenkins和Selenium啟動遠程Microsoft Edge瀏覽器

[英]Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()` error launching Remote Microsoft Edge browser through Jenkins and Selenium

我想通過在 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)

要使用Selenium而不是DesiredCapabilities()從Jenkins Job啟動遠程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);

您可以在如何將具有所需功能的Chrome驅動程序服務合並以使用xvfb進行無頭獲取中找到相關討論

使用新的 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM