Selenium webdriver NUnit不会连续运行Selenium Webdriver C测试

Selenium webdriver NUnit不会连续运行Selenium Webdriver C测试,selenium-webdriver,nunit,Selenium Webdriver,Nunit,Selenium Webdriver 2.48、C、NUnit 2.6.4、Chrome驱动程序 当我从NUnit测试运行程序运行测试时,如果单独运行,它们都会通过 如果我选择一个主标题节点,并选择Run,组中的第一个测试将运行,其余测试将失败 如果在每次测试结束时让测试夹具[TearDown]关闭驱动程序,则会发生以下错误: 无效操作异常:没有此类会话 如果我让测试夹具[TearDown]退出驱动程序,则会发生以下错误: 意外错误。System.Net.WebException:无法连接到远程

Selenium Webdriver 2.48、C、NUnit 2.6.4、Chrome驱动程序 当我从NUnit测试运行程序运行测试时,如果单独运行,它们都会通过

如果我选择一个主标题节点,并选择Run,组中的第一个测试将运行,其余测试将失败

如果在每次测试结束时让测试夹具[TearDown]关闭驱动程序,则会发生以下错误: 无效操作异常:没有此类会话

如果我让测试夹具[TearDown]退出驱动程序,则会发生以下错误: 意外错误。System.Net.WebException:无法连接到远程服务器-->System.Net.Sockets.SocketException:无法建立连接,因为目标计算机主动拒绝了它127.0.0.1:13806 在System.Net.Sockets.Socket.DoConnectEndPoint endPointSnapshot中,输入SocketAddress SocketAddress 在System.Net.ServicePoint.ConnectSocketInternalBoolean连接失败、套接字s4、套接字s6、套接字和套接字、IP地址和地址、ConnectSocketState状态、IAsyncResult asyncResult、异常和异常

使用driver.Quit或driver.Close都不会对结果产生任何影响-只有运行组中的第一个测试

我已经搜索过了,但没有找到解决办法。必须能够从最顶端的节点运行所有测试,而不必选择每个测试并单独运行它们。任何帮助都将不胜感激。谢谢迈克尔

下面是一个在一个类中有两个测试的示例。我已经从测试中删除了大多数方法,因为它们非常长

using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using NUnit.Framework;
using SiteCore.HousingRepairsLogic;

namespace SiteCore.HousingRepairsTests.DoorsAndWindowsTests
{
[TestFixture]
class DoorsTests
{
    private IWebDriver driver = new     ChromeDriver(@"C:\chromedriver_win32");

    [SetUp]
    public void setup()
    {
        HousingRepairsLogic.Utilities utilities = new Utilities(driver);
        utilities.NavigateToLogin();
    }

    [TearDown]

    public void teardown()
    {
        Utilities utilities = new Utilities(driver);
        utilities.CloseDriver();
    }


    [Test]

    public void LockRepair()
    {

        //Create Instance of the HomePage class
        HomePage homepage = new HomePage(driver);

        homepage.ClickHousingButton();
        homepage.RequestRepairButton();
        homepage.RequestRepairNowButton();
}
  [Test]

    public void ExternalWoodDoorFrameDamaged()
    {


        //Create Instance of the HomePage class
        HomePage homepage = new HomePage(driver);

        homepage.ClickHousingButton();
        homepage.RequestRepairButton();
        homepage.RequestRepairNowButton();

        //Create instance of TenancyPage class

        TenancyPage tenancy = new TenancyPage(driver);
        //proceed with login
        tenancy.ClickYesLoginButton();
        //enter username
        tenancy.EnterMyeAccountUserName();
        //enter password
        tenancy.EnterMyeAccountPassword();
        //click the login button
        tenancy.ClickLoginButton();
}
    }

当驱动程序声明为:

专用IWebDriver驱动程序=新建ChromeDriver@C:\chromedriver\u win32

然后,您的第一个测试运行,使用驱动程序,然后拆卸关闭它。下一个测试不再使用驱动程序。 您需要:在设置中重新初始化驱动程序,或者在夹具拆卸中关闭驱动程序

如果您选择在设置/拆卸中初始化并关闭,您将看到驱动程序为每个测试启动一个新的browsersession。这将确保您的测试彼此独立,但这将花费更多的运行时间


如果您想在所有测试中重复使用browsersession:将初始化和关闭移动到TestFixture Setup和TestFixture Teardown方法。

您可以添加代码吗?使用安装、拆卸和测试方法初始化感谢您的响应。我编辑了我的原始信息并添加了代码。谢谢,史蒂夫。问题现在解决了。我在每次测试中初始化驱动程序,并在测试结束时关闭驱动程序。