我正在ASP.NET MVC 5应用程序中自动执行测试,该应用程序需要以cookie集开始。
我尝试模拟响应属性更改,但无法更改BrowserWindowContext的响应。
还有其他人在处理这个问题吗?
[BeforeScenario("workitem[38419]")]
public void BeforeScenario()
{
if (ScenarioContext.Current.ScenarioInfo.Tags.Contains("workitem[38419][cookies]"))
{
var teste = ScenarioContext.Current;
var request = WebRequest.CreateHttp(new Uri(ConfigurationSettings.AppSettings.Get("Url")));
request.CookieContainer = new CookieContainer();
var response = (HttpWebResponse)request.GetResponse();
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
var keyValue = ConfigurationSettings.AppSettings.Get("cookie");
var cookie = new Cookie() {
Domain = request.RequestUri.Host.ToString(),
Name = keyValue.Split(';')[0],
Value = keyValue.Split(';')[1]
};
response.Cookies.Add(cookie);
}
}