Selenium无法连接到本地主机进行测试ASP.NET
问题描述:
我正在为ASP.NET Web应用程序编写GUI测试,但Selenium似乎无法连接到本地主机。每次运行测试用例时,都会加载chrome浏览器,但出现错误“ERR_CONNECTION_REFUSED”。我可以连接到本地主机开发很好,只是没有测试。Selenium无法连接到本地主机进行测试ASP.NET
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace MyApplication.Tests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void ButtonMenuDimensions_Chrome()
{
try
{
String url = "http://localhost:52956";
ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(url);
driver.Manage().Window.Maximize();
String actualHeight = driver.FindElement(By.Id("menu")).GetCssValue("height");
Console.WriteLine("Actual Height: " + actualHeight);
String expectedHeight = "450px";
String actualWidth = driver.FindElement(By.Id("menu")).GetCssValue("width");
String expectedWidth = "200px";
Assert.AreEqual(expectedHeight, actualHeight);
Assert.AreEqual(expectedWidth, actualWidth);
driver.Close();
driver.Dispose();
}
catch
{
Console.WriteLine("Error executing test case: Dimensions");
}
}
}
}
当我打通输出这个测试情况下,我越来越
Error executing test case: Dimensions
答
我怀疑你正在运行的应用程序在IIS Express,您将需要确保这是运行时的测试是通过在VS中运行/调试ASP网站。
如果您在不运行ASP网站的情况下点击了URL http://localhost:52956,您仍然可以点击它吗?
非常感谢!我想到测试可以自己启动IIS服务器。不幸的是,VS不允许你在网站运行/调试时运行测试,因此你必须加载两个不同的Visual Studio实例,一个启动服务器,另一个运行测试。 – JBurk94