gpt4 book ai didi

c# - 编码UI : The Browser gets closed as finish testing without keeping for testing further steps

转载 作者:行者123 更新时间:2023-11-28 20:55:00 24 4
gpt4 key购买 nike

我正在开发一个 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.
}

关于c# - 编码UI : The Browser gets closed as finish testing without keeping for testing further steps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com