【发布时间】:2018-03-19 06:00:24
【问题描述】:
我正在为 ASP.NET Web 应用程序编写 GUI 测试,但 Selenium 似乎无法连接到本地主机。每次我运行测试用例时,它都会加载 chrome 浏览器,但我收到错误“ERR_CONNECTION_REFUSED”。我可以连接到本地主机来进行开发,而不是测试。
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
【问题讨论】:
标签: c# asp.net selenium testing localhost