Selenium web driver does not work after the first test run and TestFixtureTearDown

I have several functional tests written as a NUnit test that are independent of each other and work fine when I run them one at a time. But if I select all the tests and run them right away, my web driver variable will fail after it performs the very first test. If I take the TestFixtureTearDown method, all tests will run, but I will have many open browsers. I have already tried using the Quit () and Close () methods inside TearDown. How can I write a TearDown method that closes the browser after each test run, but does not break the entire test? I desperately need your help, so please offer anything that might work, I'm open to try. This is the error I get after a test run.

AFT.AministratorPageTest("firefox").SuperAdminAssignsPermissionsOfAdmin-catalyst:
  OpenQA.Selenium.WebDriverException : Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:7055
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
TearDown : System.InvalidOperationException : No process is associated with this object.

This is my abstract class where all my other tests inherit from

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support;


namespace BusinessLayer
{
    [TestFixture("ie")]
    [TestFixture("firefox")]
     public abstract class BaseTest 
    {
        public IWebDriver browser { get; set; }
        public String driverName;

        /// <summary>
        /// Required No Argument Constructor
        /// </summary>
        public BaseTest()
        { }

        /// <summary>
        /// Constructor to allow for TestFixture parameterization
        /// </summary>
        /// <param name="name"></param>
        public BaseTest(string name)
        { 
            this.driverName = name; 
        }

        /// <summary>
        /// Loads Browser into the TestFixture
        /// </summary>
        [TestFixtureSetUp]
        public void CreateDriver()
        {
            if (driverName != null)
            {
                this.browser = (IWebDriver)Browser.GetBrowser(driverName);
            }
            else
            {
                throw new Exception("DriverName cannot be null");
            }
        }

        /// <summary>
        /// Insures browser is destroyed at conclusion of test
        /// </summary>
        [TestFixtureTearDown]
        public void FlushBrowser()
        {
            browser.Quit();
            browser = null;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OpenQA.Selenium;
using NUnit.Framework;
using BusinessLayer;
using BusinessLayer.Pages;
using System.Threading;


namespace Pegged_AFT
{
    class ScreeningProcessTests : BaseTest
    {
        public ScreeningProcessTests()
            : base()
        { }

        public ScreeningProcessTests(string name)
            : base(name)
        { }

       [Test]
        public void TestHappyPathToRegistration()
        {
            User user = new User().GetCandidate();

            Components components = new Components(
                    browser: Browser.GetBrowser(driverName),
                    client: new Client("test"),
                    user: user,
                    credentials: new Credentials(user.emailAddress, user.password)
                    );

            AddUserPage addUser = new AddUserPage(components);
            addUser.AddUser(user);

            Screening screening = new Screening(components);
            screening.Registration();

            screening.InitPage(new TestPage(components));
            Assert.AreEqual(screening.testPage.TryToFindElement(By.Id("ctl00_ContentPlaceHolder1_lblSectionName")).Text, "Candidate Registration");

        }
}

- , - , -, -. , .

+5
1

- . "Browser.GetBrowser(driverName)" ( ), , . . , Tore down . Browser.GetBrowser(driverName) IWebDriver SetUp NUnit, .

+8

All Articles