【发布时间】:2018-11-07 14:29:41
【问题描述】:
我有一个非常简单的 Selenium c# 结构如下:
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");
}
}
}
当我运行每个测试单元时,每个测试单元都通过了。但是如果我运行所有测试单元(在这种情况下只有 2 个),它会失败并出现以下错误:
OpenQA.Selenium.WebDriverException:意外错误。 System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be because the target machine主动拒绝它127.0.0.1:57535
如何解决这个问题,以便我可以连续运行所有测试?
【问题讨论】:
-
好像你正在尝试连接到以下地址 127.0.0.1:57535 但它不可用
-
但是为什么它在第一次测试中起作用呢?然后第二次测试失败了?
标签: c# selenium nunit jetbrains-ide rider