CodedUI :浏览器在完成测试时关闭,而不保留以测试进一步的步骤
本文关键字:测试 保留 进一步 浏览器 CodedUI | 更新日期: 2023-09-27 18:37:22
我正在开发一个CodedUI项目来检查Web解决方案。
在那里,当我测试启动站点(如启动 Web URL)时,我面临着在完成测试时关闭浏览器的问题,它不允许使用相同的浏览器实例进行进一步测试,除非我在运行测试之前手动打开浏览器 (IE) 的实例。
任何人都可以帮助我解决这个问题,我找不到合适的解决方案。我什至浏览了MSDN中的文章,其中我发布了有关此问题的评论,因为我到目前为止尝试了各种代码片段。
(MSDN : http://blogs.msdn.com/b/visualstudioalm/archive/2012/11/08/using-same-applicationundertest-browserwindow-across-multiple-tests.aspx)
下面提供了我的编写代码。
---
-- common.cs
[TestMethod]
public void LoadLocalHost()
{
this.UIMap.LoadLocalHost();
}
---
-- UIMap.Designer.cs
public void LoadLocalHost()
{
this.UIMsnInternetExplorerWindow.LaunchUrl(new System.Uri("http://localhost:5500/"));
Console.WriteLine(UIMsnInternetExplorerWindow.CloseOnPlaybackCleanup);
UIMsnInternetExplorerWindow.CloseOnPlaybackCleanup = false;
}
非常感谢一些可以提供帮助的人。
如果在类 Initialize 方法而不是测试初始化方法中启动浏览器,并且不在测试或测试清理中关闭它,则它应该在测试期间保持打开状态,前提是它们都在同一测试类中执行。
[ClassInitialize]
public void classInitialize()
{
// Do some stuff, including launch the browser
// This is executed once per class.
}
[TestInitialize]
public void testInitialize()
{
// This is where you'd get the test back to a specific
// state, like bring your browser back to a home page or something.
// It would be executed at the beginning of each test.
}
....
[TestMethod]
public void myFirstTest()
{
// Do some more stuff specific to your test.
}
[TestMethod]
public void mySecondTest()
{
// Do things after the last test.
}
....
[ClassCleanup]
public void classCleanup()
{
// Finalize everything and close the browser.
}