selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Support for Windows 10 in Platform (.net bindings)

Open bjharo opened this issue 11 years ago • 10 comments

Selenium 2.48.2 .NET Framework 4.5.2 Firefox 41 Windows 10

I've encountered an issue trying to run the Firefox driver locally when using Windows 10 and I think I've tracked it down to Platform.cs. Take a look at this snippet of code.

this.major = Environment.OSVersion.Version.Major;
            this.minor = Environment.OSVersion.Version.Minor;

            switch (Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                    if (this.major == 5)
                    {
                        this.platformTypeValue = PlatformType.XP;
                    }
                    else if (this.major == 6)
                    {
                        this.platformTypeValue = PlatformType.Vista;
                    }

                    break;

                // Thanks to a bug in Mono Mac and Linux will be treated the same  https://bugzilla.novell.com/show_bug.cgi?id=515570 but adding this in case
                case PlatformID.MacOSX:
                    this.platformTypeValue = PlatformType.Mac;
                    break;

                case PlatformID.Unix:
                    this.platformTypeValue = PlatformType.Unix;
                    break;
            }
        }

As you can see, when the PlatformID is Win32NT, it checks for major versions 5 and 6. Windows 10 has a major version of 10. When I run locally, I'm instantiating the firefox driver like this.

IWebDriver driver = new FirefoxDriver();

When I attempt to run a test, selenium seemingly is unable to find the Firefox executable. In an attempt to track down the issue, I downloaded the source for version 2.48.2 of selenium and build the dotnet bindings as is so I could get the debug symbols. Here is the stack trace.

System.ComponentModel.Win32Exception : The system cannot find the file specified TearDown : System.ApplicationException : Unable to retrieve the browser driver for the current thread.

at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)   
at OpenQA.Selenium.Firefox.Internal.Executable.LocateFirefoxBinaryFromPlatform() in   
c:\Users\bjharo\Documents\selenium\selenium-selenium-2.48.2\dotnet\src\webdriver\Firefox\Internal\Executable.cs:line 197 
at OpenQA.Selenium.Firefox.Internal.Executable..ctor(String userSpecifiedBinaryPath) in    
c:\Users\bjharo\Documents\selenium\selenium-selenium-2.48.2\dotnet\src\webdriver\Firefox\Internal\Executable.cs:line 63    
at OpenQA.Selenium.Firefox.FirefoxBinary..ctor(String pathToFirefoxBinary)    
in c:\Users\bjharo\Documents\selenium\selenium-selenium-2.48.2\dotnet\src\webdriver\Firefox\FirefoxBinary.cs:line 66    
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()    
in c:\Users\bjharo\Documents\selenium\selenium-selenium-2.48.2\dotnet\src\webdriver\Firefox\FirefoxDriver.cs:line 119    
at Automation.Ui.Interface.Browser.BrowserDriverFactory.GetSeleniumDriver()    
in C:\dev\CRM\Automation\Automation.Ui.Interface\Browser\BrowserDriverFactory.cs:line 125    
at Automation.Ui.Interface.Browser.BrowserDriverFactory.GetBrowser()    
in C:\dev\CRM\Automation\Automation.Ui.Interface\Browser\BrowserDriverFactory.cs:line 67    
at Automation.Ui.Tests.BaseUiTest.BaseUiTestSetup()    
in C:\dev\CRM\Automation\Automation.Ui.Tests\BaseUiTest.cs:line 71

Looking at where it is failing in Executable.cs at line 197, it appears to be executing a code block when current platform is not detected to be Windows so it's trying to find a file that does not exist. I debugged through the code at at the point where the FirefoxDriver should be instantiated, Platform.CurrentPlatforms show the current type as Platform.Any. That leads me to the conclusion that since Platform.cs does not take a major version of 10 in account, it is failing to detect Windows 10 as being Windows.

I tried to just specify the Firefox binary directly.

var ffbinary = new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
IWebDriver driver = new FirefoxDriver(ffbinary, new FirefoxProfile());

This works but it has a bad side effect. I cannot run more than one instance of Firefox at once. I see the following errors when I try to run 2 or more test threads at one time.

OpenQA.Selenium.WebDriverException : Unable to bind to locking port 7054 within 45000 milliseconds

My setup does work with other operating systems and Firefox. I can run multiple instance of Firefox at once using Selenium 2.48.2 on both OS X 10.11 and Windows Server 2012.

bjharo avatar Nov 23 '15 18:11 bjharo

possible ref #688

ddavison avatar Nov 23 '15 19:11 ddavison

Is there a better work-around than hardcoding the path or an ETA for this to be fixed and released? This is blocking all of our firefox/win10 automation.

joltcoder avatar Dec 11 '15 15:12 joltcoder

A workaround has already been committed in 6b496e6. The next release of the .NET bindings will contain it. There is no ETA for the release.

jimevans avatar Dec 11 '15 16:12 jimevans

My apologies if this is a dumb question, the workaround is to edit the selenium source and rebuild it locally? I guess I was asking if there was an already built binary that i could just put in the selenium lib folder under the packages folder... or something along those lines.

joltcoder avatar Dec 11 '15 18:12 joltcoder

No such binary exists at present, no. But on the other hand, I refuse to commit to a timetable that I don't know for certain that I can adhere to.

jimevans avatar Dec 11 '15 18:12 jimevans

I believe one way around this is to run the selenium server jar locally and then target it instead of directly creating a Firefox driver.

bjharo avatar Dec 11 '15 18:12 bjharo

I don't want you to commit to a date... i understand how that can bite you back. ;) Just wanted to make sure that i understood the process. Thanks for the quick replies!

joltcoder avatar Dec 11 '15 19:12 joltcoder

@bjharo Yes, but then you're no longer using the .NET bindings' implementation of FirefoxDriver; you're using the Java bindings' implementation.

jimevans avatar Dec 11 '15 19:12 jimevans

Is it possible to revisit this issue? The Java bindings have WIN8_1 and WIN10 enums in their Platform.java yet Platform.cs does not have the equivalent for PlatformType.

AndyUM357 avatar Apr 14 '16 20:04 AndyUM357

No, I'm sorry, we won't be revisiting this issue. The "platform" designation was never intended to yield full-fidelity information about Windows versions. It was originally intended to merely indicate whether the version of Windows utilized User Access Control, or UAC (Vista and above), or not (XP and below). It is unfortunate that the Java implementation has chosen to depart from this.

jimevans avatar Apr 14 '16 20:04 jimevans