selenium icon indicating copy to clipboard operation
selenium copied to clipboard

PlatformNotSupportedException when using RemoteWebDriver in C# and .NET Core 2.0

Open blackbaud-KelbyStine opened this issue 9 years ago • 21 comments

Meta -

OS: Windows 10 Selenium Version: Selenium.WebDriver 3.6.0 C#, .NET Core 2.0 Browser: RemoteWebDriver -->

Browser Version: na

Expected Behavior -

Connects to RemoteWebDriver VM.

Actual Behavior - Throws this error:

System.PlatformNotSupportedException : Operation is not supported on this platform. at System.Net.SystemWebProxy.GetProxy(Uri destination) at System.Net.ServicePointManager.ProxyAddressIfNecessary(Uri& address, IWebProxy proxy) at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy) at System.Net.HttpWebRequest.get_ServicePoint() at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at MicroEdge.DonorCentral.Automation.Common.WebDriver.RemoteWebDriverConfiguration.CreateRemoteWebDriver() in C:\Users\Windows 10

Seems related to this error: https://github.com/Azure/azure-iot-sdk-csharp/issues/140

Steps to reproduce -

This is generic test that can reproduce this issue. Will require SL credentials to execute.

public class UnitTest1 { [Fact] public void Test1() { Uri bsuri = new Uri("http://ondemand.saucelabs.com:80/wd/hub"); IWebDriver driver; DesiredCapabilities caps = new DesiredCapabilities(); caps.SetCapability(CapabilityType.BrowserName, "chrome"); caps.SetCapability(CapabilityType.Version, "49"); caps.SetCapability(CapabilityType.Platform, "Windows 7"); caps.SetCapability("username", ""); caps.SetCapability("accessKey", ""); caps.SetCapability("name", "testing"); driver = new RemoteWebDriver(bsuri, caps);

driver.Navigate().GoToUrl("http://www.google.com"); Console.WriteLine(driver.Title); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("SauceLabs"); query.Submit(); Console.WriteLine(driver.Title);

driver.Quit(); } }

blackbaud-KelbyStine avatar Sep 27 '17 17:09 blackbaud-KelbyStine

Hi Is there a work around for this issue? Please let me know Thanks

eljivarughese avatar Oct 03 '17 03:10 eljivarughese

Hi, Experiencing exactly the same problem with dotnet core 2.0 and RemoteWebDriver 3.6.0. Thanks

DNIDNL avatar Oct 05 '17 13:10 DNIDNL

Also experiencing this issue.

A possible workaround is to create your own implementation of IHttpCommandExecutor, since this is where the exception is originating. Then you should be able to successfully use the RemoteWebDriver(IHttpCommandExecutor, ICapabilities) constructor.

nateswartz avatar Oct 05 '17 18:10 nateswartz

Same behaviour, .net core 2, mac os + rider eap - grid running in docker container.

c-mccutcheon avatar Oct 11 '17 21:10 c-mccutcheon

Has anyone figured out the workaround for this yet ? This is a showstopper for me :-(

.net core 2.0 - dockerized app running in container - with hub and nodes also dockerised.

Note if I run locally and use loopback address it works fine. But I need it to run in our CI pipeline.

TimJarvis avatar Oct 16 '17 21:10 TimJarvis

ok - I have a workaround for anyone interested....bit of a pain, but....

The main issue is that the .netcore SystemWebProxy class throws a PlatformNotSuppoorted exception on the GetProxy call.

To work around this, I modified one of the the RemoteWebDriver constructors and the HttpCommandExecutor constructor to take a IWebProxy param. I then replace the HttpRequest Proxy property with the passed in proxy and its all good. In my case all the proxy needed to do was to pass through the Uri - but this solution would also work if you need to construct a real proxy.

TimJarvis avatar Oct 17 '17 00:10 TimJarvis

@TimJarvis any chance you could share a snippet of that code? Cheers

richbayliss avatar Oct 17 '17 13:10 richbayliss

Folks, the CHANGELOG for the .NET bindings clearly state that .NET Core 2.0 support is experimental. I recognize folks are having challenges with it, but we’ve made no guarantees of stability yet for this. Thank you for your patience, as the .NET bindings’ maintainers are unpaid volunteers who do not work on Selenium anything close to full time.

jimevans avatar Oct 17 '17 14:10 jimevans

I also created a workaround, as it turned out there was a certain property on the ServicePoint object which was not implemented (when running on Mac OS, anyway) - I ended up following the suggestion from above, creating a custom IHttpCommandExecutor and using the alternate constructor, but with the offending line of code omitted as it wasn't really important to my tests. @TimJarvis workaround is potentially better :)

c-mccutcheon avatar Oct 17 '17 14:10 c-mccutcheon

@jimevans thanks for the effort Jim, it is appreciated. @TimJarvis @omgsarge if you share your snippets here then it might calm the masses while the team get a fix in place? Cheers guys.

richbayliss avatar Oct 17 '17 15:10 richbayliss

Sure...

In the RemoteWebDriver class, I added a IWebProxy param to one of the constructors public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout, IWebProxy proxy = null) : this(new HttpCommandExecutor(remoteAddress, commandTimeout, proxy), desiredCapabilities) { }

I also added the IWebProxy Param to the HttpCommandExecutor and stored it locally public HttpCommandExecutor(Uri addressOfRemoteServer, TimeSpan timeout, IWebProxy proxy = null) : this(addressOfRemoteServer, timeout, true) { this.proxy = proxy; }

Then in the MakeHttpRequest method I assign the passed in WebProxy to the HttpWebRequest object

          'HttpWebRequest request = HttpWebRequest.Create(requestInfo.FullUri) as HttpWebRequest;
          if(this.proxy != null)
          {
              request.Proxy = this.proxy;
          }

....`

Then, when I create an instance of the RemoteWebDriver I simply pass in a custom proxy class - In my case the proxy just passes through the Uri as there is no proxy required, but you could also pass in any custom proxy that supports IWebProxy interface.

(for copmpleteness, this is my proxy class)

`public class PassThroughProxy : IWebProxy
{
    public ICredentials Credentials { get; set; }

    public Uri GetProxy(Uri destination)
    {
        return destination;
    }

    public bool IsBypassed(Uri host)
    {
        return false;
    }
}`

Cheers Tim.

TimJarvis avatar Oct 17 '17 21:10 TimJarvis

Thanks @TimJarvis

richbayliss avatar Oct 19 '17 09:10 richbayliss

Hi, there is any fix? I have the same issue on Win10

NeroMancini avatar Oct 23 '17 22:10 NeroMancini

Awesome @TimJarvis

DNIDNL avatar Oct 24 '17 08:10 DNIDNL

Thanks @TimJarvis

quickskape avatar Nov 07 '17 17:11 quickskape

@TimJarvis Hello, Sorry for bothering you. I have tried your suggestion. Pulled down webdriver repository. Made changes that you provided in the comments then rebuild the solution. But it looks like this workaround doesn't work, I am getting the following exception: "Message: OpenQA.Selenium.WebDriverException : Unexpected error. Unknown command" image

SergiusZurawski avatar Nov 30 '17 15:11 SergiusZurawski

Sorry @SergiusZurawski but that error looks to be unrelated. You will just need to debug.

Cheers Tim.

TimJarvis avatar Dec 10 '17 23:12 TimJarvis

This may be the wrong place to ask this, but I just started building a brand new framework in C# (being a new language to me, normally coding in Java)...Is there something I can do to avoid this problem? Like rolling back to .Net core 1.1 or the likes?

Or will I have to wait until this is fixed in order to use things like Grid? Pardon the ineptitude on my part, but I ask out of ignorance and not being able to find the solution anywhere..I mean besides making the custom fix mr. TimJarvis made

Thank you!

drhat avatar Dec 14 '17 09:12 drhat

Anybody know a way around this without having to a) modify the source code of the library or b) revert back to using the full .NET framework?

ghost avatar Feb 15 '18 12:02 ghost

@elsyms I was able to successfully work around it using the following method:

  1. Define a custom ICommandExecutor in my project. In my case, the body of HttpCommandExecutor.cs from the WebDriver project worked, I simply had to copy-paste it into a new file in my project and make a minor change. The source can be found here. To avoid confusion, I changed the name to NetCoreHttpCommandExecutor. The one change I had to make was to remove the following line: request.ServicePoint.ConnectionLimit = 2000; from the MakeHttpRequest method (it should be approx line 156). Trying to run when this line was included resulted in a PlatformNotSupportedException.
  2. In my test I initialize it with the following:
var executor = new NetCoreHttpCommandExecutor(new Uri(seleniumGridUrl), new TimeSpan(0, 0, 0, 20));
var capabilities = new ChromeOptions().ToCapabilities();
Driver = new RemoteWebDriver(executor, capabilities);

I have been running with this workaround in place for several months and have not observed any obvious issues.

nateswartz avatar Feb 15 '18 13:02 nateswartz