简体   繁体   中英

Cannot start firefox browser instance for tests using Visual Studio, C#, Nunit and Selenium

I am having troubles trying to run simple UI test in Visual Studio (16.11.10) using C# and NUnit. I am using Selenium.Firefox.WebDriver version 0.27.0., Selenium.WebDriver and Selenium.Support both 4.1.0

Test:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace ClassLibrary2
{
    public class Class1
    {
        [Test]
        public static void TestBrowser()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "https://login.yahoo.com/";
            driver.Quit();
        }

    }
}

Running this test I am getting such error:

 TestBrowser
   Source: Class1.cs line 10
   Duration: 4,6 sec

  Message: 
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:59898/

  Stack Trace: 
DriverService.Start()
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
FirefoxDriver.ctor(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
FirefoxDriver.ctor(FirefoxOptions options)
FirefoxDriver.ctor()
Class1.TestBrowser() line 18

  Standard Output: 
Unable to connect to the remote server

All works fine using ChromeDriver. Thanks for your help.

Possibly Selenium.Firefox.WebDriver version 0.27.0 points to the older GeckoDriver of version0.27.0 . Hence you see the error.

The solution would be to upgrade to latest version of GeckoDriver ie version0.30.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM