Illes
Illes

Reputation: 39

how to set up edgedriver correctly? getting the following error

I'm using NUnit and Selenium in C# to build a framework which contains running multiple testcases on several browsers. Microsoft Edge is also supported in this case. When I set up my tests chrome and firefox run correctly but edge gives the following error:

OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:55992/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive. ----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive. ----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host [2018. 06. 17. 17:08:22 Warning] at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.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 OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeOptions options) at OpenQA.Selenium.Edge.EdgeDriver..ctor() at SeleniumNUnit.Tests.WebDriverFactory.EdgeDriver() in C:\SeleniumNUnit - Copy\SeleniumNUnit.Tests\Class1.cs:line 70 at SeleniumNUnit.Tests.WebDriverFactory.WebDriver(BrowserType type) in C:\SeleniumNUnit - Copy\SeleniumNUnit.Tests\Class1.cs:line 50 at SeleniumNUnit.Tests.WebDriverFactory..ctor(BrowserType type) in C:\SeleniumNUnit - Copy\SeleniumNUnit.Tests\Class1.cs:line 24 at SeleniumNUnit.DemoTest..ctor(BrowserType browser) in C:\SeleniumNUnit - Copy\SeleniumNUnit\Class1.cs:line 12 --WebException at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) --IOException at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) --SocketException at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

I have tried to look up this specific error and the closest I got was that remote driver tries to send an HTTP request which in this case fails. Since Chrome and FF runs correctly I have no idea what goes wrong with Edge.

WebDriverFactory:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using System.IO;
using OpenQA.Selenium.Edge;
using System;

namespace SeleniumNUnit.Tests
{
    /// <summary>
    /// A static factory object for creating WebDriver instances
    /// </summary>
    public class WebDriverFactory
    {
        public static string path = "C:\\Drivers\\";
        public IWebDriver Driver;

    protected WebDriverFactory(BrowserType type)
    {
        Driver = WebDriver(type);
    }

    [OneTimeTearDown]
    public void TestFixtureTearnDown()
    {
        Driver.Quit();
    }

    /// <summary>
    /// Types of browser available for proxy examples.
    /// </summary>
    public enum BrowserType
    {
        IE,
        Chrome,
        Firefox,
    }

    public static IWebDriver WebDriver(BrowserType type)
    {
        IWebDriver driver = null;

        switch (type)
        {
            case BrowserType.IE:
                driver = EdgeDriver();
                break;
            case BrowserType.Firefox:
                driver = FirefoxDriver();
                break;
            case BrowserType.Chrome:
                driver = ChromeDriver();
                break;
        }

        return driver;
    }

    /// <summary>
    /// Creates Internet Explorer Driver instance.
    /// </summary>
    /// <returns>A new instance of IEDriverServer</returns>
    private static IWebDriver EdgeDriver()
    {
        new DriverManager().SetUpDriver("https://download.microsoft.com/download/F/8/A/F8AF50AB-3C3A-4BC4-8773-DC27B32988DD/MicrosoftWebDriver.exe", Path.Combine(path, "MicrosoftWebDriver.exe"), "MicrosoftWebDriver.exe");
        IWebDriver driver = new EdgeDriver();   
        return driver;
    }

    /// <summary>
    /// Creates Firefox Driver instance.
    /// </summary>
    /// <returns>A new instance of Firefox Driver</returns>
    private static IWebDriver FirefoxDriver()
    {
        new DriverManager().SetUpDriver(new FirefoxConfig());
        FirefoxOptions options = new FirefoxOptions();
        IWebDriver driver = new FirefoxDriver(options);
        return driver;
    }


    /// <summary>
    /// Creates Chrome Driver instance.
    /// </summary>
    /// <returns>A new instance of Chrome Driver</returns>
    private static IWebDriver ChromeDriver()
    {
        new DriverManager().SetUpDriver("https://chromedriver.storage.googleapis.com/2.40/chromedriver_win32.zip", Path.Combine(path, "chromedriver.exe"), "chromedriver.exe");
        ChromeOptions chromeOptions = new ChromeOptions();
        IWebDriver driver = new ChromeDriver(chromeOptions);
        return driver;
    }


}
}

TestCode:

using System;
using NUnit.Framework;
namespace SeleniumNUnit
{
    [TestFixture(SeleniumNUnit.Tests.WebDriverFactory.BrowserType.Chrome)]
    [TestFixture(SeleniumNUnit.Tests.WebDriverFactory.BrowserType.Firefox)]
    [TestFixture(SeleniumNUnit.Tests.WebDriverFactory.BrowserType.IE)]
    public class DemoTest : SeleniumNUnit.Tests.WebDriverFactory
    {
        public DemoTest(SeleniumNUnit.Tests.WebDriverFactory.BrowserType browser)
        : base(browser)
    {

    }

    [OneTimeSetUp]
    public void SetUpEnvironment()
    {
        Driver.Navigate().GoToUrl("http://google.com");

    }

    [Test]
    public void validateTitle()
    {
        Assert.That(Driver.Title.Contains("Google"));
    }

    [OneTimeTearDown]
    public void tearDown()
    {
        Driver.Quit();
        Driver.Dispose();
    }
}
}

Upvotes: 0

Views: 2809

Answers (1)

Kaisen-san
Kaisen-san

Reputation: 26

I was facing the same problem, but then I found this:

Selenium.WebDriver.MicrosoftDriver v17.17134.0 crash when running the test

Long story short, check your Windows version. If it is the 17134 version, so get the MicrosoftWebDriver 17134 version. However, if you are on 16299.xxx, then you have to use the 16299 version of MicrosoftWebDriver.

Upvotes: 1

Related Questions