I have a very simple Selenium c# structure as follows:
using System;
using System.Timers;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ConsoleApplication2
{
internal class Program
{
IWebDriver driver = new ChromeDriver();
public static void Main(string[] args)
{
}
[SetUp]
public void Initialize()
{
driver.Navigate().GoToUrl("https://www.google.pt/");
Console.WriteLine("INITIALIZE complete");
}
[Test]
public void TestGoogleSearch()
{
IWebElement element = driver.FindElement(By.Name("q"));
element.SendKeys("ivo cunha");
Console.WriteLine("IVO complete");
}
[Test]
public void TestGoogleSearch2()
{
IWebElement element = driver.FindElement(By.Name("q"));
element.SendKeys("adam o'brien");
Console.WriteLine("ADAM complete");
}
[TearDown]
public void CleanUp()
{
System.Threading.Thread.Sleep(2500);
driver.Close();
driver.Quit();
driver.Dispose();
Console.WriteLine("CLEANUP complete");
}
}
}
When I run each test unit, each passes. But if I run all test units (just 2 in this case), it fails with the following error:
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:57535
How can I fix this so that I can run all tests at in a series?