尝试使用Nunit运行多个Selenium Webdriver测试失败
我想知道有没有人可以帮助我。 我在C#和Nunit中使用硒Webdriver,当我尝试运行多个测试时,出现以下错误:
OpenQA.Selenium.WebDriverException:意外的错误。 System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:由于目标计算机主动拒绝它而无法建立连接127.0.0.1:7055在System.Net.Sockets.Socket .DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)
当我将这些测试作为个体运行并传递正常时。
任何帮助或指针都会很棒。
以下是我的代码和我的驱动程序类的示例
驱动程序类
using System;
using System.Configuration;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
namespace SMT.Web.FunctionalTests.Drivers
{
public class Driver
{
private static IWebDriver _driver;
protected static IWebDriver GetWebDriver
{
get
{
if (_driver == null)
{
string driverConfig = ConfigurationManager.AppSettings["browser"];
if (!String.IsNullOrEmpty(driverConfig))
{
switch (ConfigurationManager.AppSettings["browser"])
{
case "Chrome":
_driver = new ChromeDriver();
ConfigureDriver();
break;
case "Firefox":
_driver = new FirefoxDriver();
ConfigureDriver();
break;
case "IE":
_driver = new InternetExplorerDriver();
ConfigureDriver();
break;
default:
Console.WriteLine("App.config key error");
Console.WriteLine("Defaulting to FireFox");
_driver = new FirefoxDriver();
ConfigureDriver();
break;
}
}
else
{
Console.WriteLine("* * * * DEFAULT MODE * * * *");
Console.WriteLine("Defaulting to Firefox");
_driver = new FirefoxDriver();
ConfigureDriver();
}
}
return _driver;
}
}
internal static void ConfigureDriver(string page = "")
{
string url = ConfigurationManager.AppSettings["URL"];
_driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
_driver.Manage().Cookies.DeleteAllCookies();
_driver.Manage().Window.Maximize();
_driver.Navigate().GoToUrl(string.Concat(url, page));
}
public static void Close()
{
_driver.Close();
}
}
}
测试类
public class LoginRegressionTests : Driver
{
public static IWebDriver WebDriver { get; set; }
public AjaxHelpers AjaxHelpers;
public DatabaseHelpers DatabaseHelpers;
[SetUp]
public void Setup()
{
DatabaseHelpers = new DatabaseHelpers();
DatabaseHelpers.DatabaseSetUpClearDown();
WebDriver = GetWebDriver;
AjaxHelpers = new AjaxHelpers(WebDriver);
}
[TearDown]
public void Teardown()
{
WebDriver.Close();
}
[Test]
public void LoginWithIncorrectUserNamePasswordTest()
{
// Create an Instance of Header Banner Page Object
var headerBannerPage = new HeaderBannerPage(WebDriver);
headerBannerPage.ClickSigninLink();
// Create an Instance of Login Page Object
var loginPage = new LoginPage(WebDriver);
loginPage.EnterCustomerUsername("someoneemail@email.com");
loginPage.EnterCustomerPassword("*&^%£$£");
loginPage.ClickLoginCustomerButton();
AjaxHelpers.WaitForAjax();
String usernameRequiredBorderBottom = WebDriver.FindElement(By.CssSelector("#login-username")).GetCssValue("border-bottom-color");
String usernameRequiredBorderLeft = WebDriver.FindElement(By.CssSelector("#login-username")).GetCssValue("border-left-color");
String usernameRequiredBorderRight = WebDriver.FindElement(By.CssSelector("#login-username")).GetCssValue("border-right-color");
String usernameRequiredBorderTop = WebDriver.FindElement(By.CssSelector("#login-username")).GetCssValue("border-top-color");
Assert.AreEqual(usernameRequiredBorderBottom, "rgba(181, 79, 80, 1)");
Assert.AreEqual(usernameRequiredBorderLeft, "rgba(181, 79, 80, 1)");
Assert.AreEqual(usernameRequiredBorderRight, "rgba(181, 79, 80, 1)");
Assert.AreEqual(usernameRequiredBorderTop, "rgba(181, 79, 80, 1)");
String passwordrequiredBorderBottom = WebDriver.FindElement(By.CssSelector("#login-password")).GetCssValue("border-bottom-color");
String passwordrequiredBorderLeft = WebDriver.FindElement(By.CssSelector("#login-password")).GetCssValue("border-left-color");
String passwordrequiredBorderRight = WebDriver.FindElement(By.CssSelector("#login-password")).GetCssValue("border-right-color");
String passwordrequiredBorderTop = WebDriver.FindElement(By.CssSelector("#login-password")).GetCssValue("border-top-color");
Assert.AreEqual(passwordrequiredBorderBottom, "rgba(181, 79, 80, 1)");
Assert.AreEqual(passwordrequiredBorderLeft, "rgba(181, 79, 80, 1)");
Assert.AreEqual(passwordrequiredBorderRight, "rgba(181, 79, 80, 1)");
Assert.AreEqual(passwordrequiredBorderTop, "rgba(181, 79, 80, 1)");
}
}
链接地址: http://www.djcxy.com/p/63417.html
上一篇: Attempting to run multiple Selenium Webdriver tests using Nunit fails
下一篇: How to run a parameterized Selenium test with NUnit on TeamCity?