在 TestInitialize 中清除缓存,因此一旦任何测试开始,第一步就是清除缓存然后继续测试。
#region Additional test attributes
//Use TestInitialize to run code before running each test
[TestInitialize()]
public void MyTestInitialize()
{
// First launch your browser...
this.UIMap.LaunchBrowserParams.Url = Config.WebServer;
this.UIMap.LaunchBrowser();
// This will clear your cache and cookies
BrowserWindow.ClearCache();
BrowserWindow.ClearCookies();
}
//Use TestCleanup to run code after each test has run
[TestCleanup()]
public void MyTestCleanup()
{
// Since you're concerned about failed tests not clearing cache at the end
// I wouldn't bother with clearing the cache at the MyTestCleanup step.
this.UIMap.CloseBrowser();
}
#endregion
编辑:我编辑了 TestInitialize 以首先启动浏览器。在 ClearCache 和 ClearCookies 执行任何操作之前,必须打开浏览器。