??ASP.NET MVC????е?????????????
???????????? ???????[ 2014/8/7 11:18:59 ] ??????????????? .NET
???????????????
???????ASP.NET MVC?????????????????????Controller????? -- -- ???Stephen Walther?д?????????Web Server??View???е????????????????????????????á?????????????????????????HTML????????ж? -- -- ????????????????????????????????????????????????????????ViewEngine???????????????????????ViewEngine????????????????????????????????????????????????????????????......?????????????????Щ"????"???????????????????????????????????????????嶯???
?????????????????????????????????????????????в??С??????????????????????????????WatiN???????????????????棬?????DOM?????????????????????......???????????????????????????????????????????????????????????????????????????????????????????ó????????????????μ???????????????????"????"????????й???????????????????????????????????λ???????????????????????????????????????????
?????????????????????????????ù淶?????ASP.NET MVC???????????????????????View????????ViewData?е?????????????????????????????HttpContext??????????????????й???ViewData????????????????С???????????????ASP.NET MVC????????????б?????????ViewsSharedLogOnUserControl.ascx?????????this.User???????????????????????????????Page????????????????HttpContext????????????????????????????????????????"???"?????????????????????????????????????????????
Lightweight Test Automation Framework
????????????????????ASP.NET Team????Lightweight Test Automation Framework?????????LTAF??????????????????????CodePlex???????Feb Update?汾???????????????WatiN??Selenium???????????????????ó????д?????????????Щ???棨????DOM????????????"????????"??????LTAF??????????????
???????????????????????У???????????????е? -- -- ???δ?????????????????????
??????????????????????????У??????????????????????????????С?
???????????????????????????????????????WatiN??Selenium???????????д????????????д???檔????ζ??????????????????????????????????????С??????????£???????????????????ж?????????????????????????????????????????????п?????????????????????????????"???л?"??????????????????????????LTAF???????????????????????????????????????????"????"???????????ж?????????????
?????????κ????????????????LTAF????Щ??????????????????????????????????磺
????????LTAF?????????????????Frame?У???????????window.top??????????frame????????????
????????LTAF??????????JavaScript??????DOM??????ζ???κλ???????????е??????????alert????????????????????????????????
????????????????????????????????????????????????????????д????????getTop???????滻??????windows.top?????????ɡ??????????? -- -- ????????????alert??confirm????"???????????"???????????????????????飬???ο??????JavaScript???/????????????????????Ч?????????????
????LTAF???????÷????ο???Release Note?????????????????????????????????LTAF?????ЩС?????????????????????????????????????????Щ?????????????~UnitViewDriverPage.aspx???β?????ЩJavaScript????
UnitView?????
?????????????д????????UnitView???????????????????????????????????????????????????????????????м????????????磺
[WebTestClass]
public class HomeTests
{
[WebTestMethod]
public void LoggedOnIndexTest()
{
var data = new TestViewData<IndexModel>
{
ControllerName = "Home"??
ActionName = "Index"??
Model = new IndexModel
{
Message = "Welcome guys!"??
Identity = new UserIdentity
{
IsAuthenticated = true??
Name = "Jeffrey Zhao"
}
}
};
HtmlPage page = new HtmlPage(TestViewData.GenerateHostUrl(data));
// Assert title
Assert.AreEqual("Home Page"?? page.Elements.Find("title"?? 0).GetInnerText());
// Assert head element
var mainContent = page.Elements.Find("main");
var head2 = mainContent.ChildElements.FindAll("h2").Single();
Assert.AreEqual(data.Model.Message?? head2.GetInnerText()?? "Message should be displayed.");
var loginTabInnerText = page.Elements.Find("logindisplay").GetInnerTextRecursively();
Assert.IsTrue(loginTabInnerText.Contains("Welcome")?? "'Welcome' missed.");
Assert.IsTrue(loginTabInnerText.Contains(data.Model.Identity.Name)?? "Login name missed.");
}
}
?????????Web Server????????????????????????????????????漰????????????????VS??????Web Server????????????????У???????????????????TestViewData????????????????????????????????????
Cotroller??Action??????????????????????Controller??Action????????????????????????????
View??Master????????????????????????????????????Controller??Action??????????
ViewData??Model??
????TestViewData.GenerateHostUrl???????data???????????????????URL???????URL?????????????????????
??????????????UnitView??????????????????????UnitView???????????????????г???????UnitView?????????????????
??Tests????????·??????????????bin????????????????????????????????????????????????????á?
??~UnitView???????????????????£???????????????????????????????????????????????????UnitView????????
??~UnitViewWeb.config???????MvcApp.Tests.dll???????????????????????????
UnitView??????
????UnitView???????????????????????TestViewData????????????????????????????TestViewData<TModel>?????TestViewData????????????Model?????????????????????????
????????TestViewData?????Щ?????????
public class TestViewData
{
static TestViewData()
{
PersistentProvider = new InProcPersistentProvider();
}
public static IPersistentProvider PersistentProvider { get; set; }
public static string GenerateHostUrl(TestViewData data)
{
var key = PersistentProvider.Save(data);
return ViewHostHandlerUrl + "?key=" + HttpUtility.UrlEncode(key);
}
private static string ViewHostHandlerUrl
{
get
{
return ConfigurationManager.AppSettings["UnitView_ViewHostHandlerUrl"]
?? "/UnitView/ViewHostHandler.ashx";
}
}
internal static TestViewData Load(string key)
{
return PersistentProvider.Load(key);
}
...
}
????GenerateHostUrl ?????????PersistentProvider ???????????????key ?????key ???????ViewHostHandlerUrl ??????????????????·??????????п???????????????????????????·?????????web.config ??AppSettings ???????????????????ɡ?
????PersistentProvider ?????IPersistentProvider ???????????ж?????Save/Load/Remove ??????????IPersistentProvider ?????????????????InProcPersistentProvider ??????TestViewData ?????????е??????????????????????UnitView ???LTAF ???У?LTAF ???????????????????????????????????????????????WatiN ?????????????????????????????IPersistentProvider ?????????????????????FilePersistentProvider ????TestViewData ???л????????????У??????????????????????????
???????????????????????UnitView.Engine.ViewHostHandler ??
public class ViewHostHandler : IHttpHandler
{
private HttpContext Context { get; set; }
public void ProcessRequest(HttpContext context)
{
this.Context = context;
ControllerContext controllerContext = new ControllerContext(
new HttpContextWrapper(context)??
this.Data.RouteData??
new MockController());
new ViewResult
{
MasterName = this.Data.MasterName??
ViewName = this.Data.ViewName??
TempData = this.Data.TempData??
ViewData = this.Data.ViewData??
}.ExecuteResult(controllerContext);
}
private string Key
{
get
{
string key = this.Context.Request.QueryString["key"];
if (String.IsNullOrEmpty(key))
{
throw new ArgumentNullException("key");
}
return key;
}
}
private TestViewData m_data;
private TestViewData Data
{
get
{
if (this.m_data == null)
{
this.m_data = TestViewData.Load(this.Key);
if (this.m_data == null)
{
throw new ArgumentNullException("Cannot retrieve the data.");
}
}
return this.m_data;
}
}
public bool IsReusable { get { return false; } }
}
???????????ProcessRequest ?????????TestViewData ??????????Щ??????????ViewResult ?????????????ExecuteResult ?????????????????????ExecuteRequest ?????????????????????????ControllerContext ???????ζ????????????????Controller ?????HttpContext ????????????п????????????????????????????????????????“ ???” ????????ViewData ?л???????????????Controller ??HttpContext ??????????????????
??????????????????????????“ ???” ???????????HttpContext ?????л?????????Mock ???HttpContext ????????????????????????л????????Mock ?????????????Mock ???HttpContext ??????????л????????????????????????????????????WatiN ??Selenium ???в?????????????????????????????£??????????????HttpContext ??????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11