在Selenium WebDriver使用Visual Studio 2013进行C#测试期间,未能在45000毫秒内启动套接字

在Selenium WebDriver使用Visual Studio 2013进行C#测试期间,未能在45000毫秒内启动套接字,c#,selenium-webdriver,visual-studio-2013,C#,Selenium Webdriver,Visual Studio 2013,我是硒测试新手,正在努力学习 运行测试时,我遇到一个错误OpenQA.Selenium.WebDriverException: 未能在45000毫秒内启动套接字` 这是我的示例代码: [TestClass] public class MyTest { IWebDriver driver; [TestMethod] public void VerifyTitle() { //Write Actual Test string title

我是硒测试新手,正在努力学习

运行测试时,我遇到一个错误
OpenQA.Selenium.WebDriverException:
未能在45000毫秒内启动套接字`

这是我的示例代码:

[TestClass]
public class MyTest
{
    IWebDriver driver;
    [TestMethod]
    public void VerifyTitle()
    {
        //Write Actual Test
        string title = driver.Title;
        Assert.AreEqual(title, "Done The deal");
    }
[TestInitialize]
public void Setup()
{
    //start browser and oprn url
    driver = new FirefoxDriver();
    driver.Navigate().GoToUrl("http://Donethedeal.com/");
}

[TestCleanup]
public void CleanupTest()
{
    //close browser
    driver.Quit();
}
}

我认为,我使用NuGet Package Manager安装了所有必要的库 我安装了
Selenium.WebDriver-Version 2.53.1
,而不是3.0.0 beta版,因为只有这个版本我才能启动Firefox浏览器。但是,我无法打开url,并且在执行此操作时出现了描述的错误


我遗漏了什么?

首先,您的错误出现在
IWebDriver
对象声明中。您正在
SetUp()
方法中本地声明对象。如果这样做,则对象的范围仅在方法内部。在方法之外,对象为null。因此,将声明移到所有方法之外(最好在顶部,如bellow)
下一个错误是您正在使用的属性。我必须在这里提到,我使用了
NUnit3TestAdapter
NUnit
中的
Nuget
。我没有找到你的属性,所以我添加了我的:)
在设置方法中,我在
清理[TearDown]

VerifyTitle
[Test]中使用了[SetUp]属性

查看下面的代码列表以了解更多详细信息

 IWebDriver driver = new FirefoxDriver();
    static void Main(string[] args)
    {
    }

    [Test]
    public void VerifyTitle()
    {
        //Write Actual Test
        string title = driver.Title;
        // Assert.AreEqual(title, "DoneThedeal");
        ////I wanted to keep it simple change it back if u wish
        if (title.Contains("DoneTheDeal"))
        {
            Console.WriteLine(title);
        }
        else
        {
            Console.WriteLine("Title not found");
        }

    }
    [SetUp]
    public void Setup()
    {
        //start browser and oprn url

        driver.Navigate().GoToUrl("http://Donethedeal.com/");
    }

    [TearDown]
    public void CleanupTest()
    {
        //close browser
        driver.Quit();
    }
}
**如果要查看控制台结果,请在文本资源管理器中查找“输出”