vishal gupta
vishal gupta

Reputation: 41

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

There is one website which I am suppose to test in the remote edge browser by using Selenium in Java. But there is nowhere I can find the code for remote edge browser. Whereas locally I can open the edge browser and test.

The Browser version :- Microsoft Edge 41.16299.1004.0 Microsoft EdgeHTML 16.16299 The Driver version :- Version: 5.16299 | Microsoft Edge version supported: 16.16299

And there is no version issue as It's working with local edge browser.

As of now I have code to test the website by opening the edge browser locally from Selenium in Java. And this is working fine.

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

And for Remote Edge browser, I am having the below code, which is not working.

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

When running for the Remote Edge Browser using remoteWebDriver for Edge. getting below error.

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)

Upvotes: 1

Views: 11082

Answers (2)

Ranjit
Ranjit

Reputation: 145

Try This with the new 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();

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193108

To launch Remote Microsoft Edge Browser from Jenkins Job using Selenium instead of using DesiredCapabilities() you need to use EdgeOptions() as follows:

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

You can find a relevant discussion in How to Merge Chrome driver service with desired capabilities for headless using xvfb?

Upvotes: 0

Related Questions