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

标签 c# testing browser automated-tests coded-ui-tests

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

相关文章:

angular - 模块 '[object Object]' 导入的意外值 'DynamicTestModule'

java - 读取页面对象模型中的excel数据

css - 浏览器如何决定使用什么 : http or https (tinymce load of @font-face error)

javascript - 我可以在工作人员中使用 EventListeners 吗?

c# - 如何使用 C# 创建浏览器插件?

c# - 从 app.config 获取数据的最佳方式是什么?

c# - 更改 C# 操作/委托(delegate)目标 : hierarchical calls

c# - IIS 错误 502.5 上的 ASP.NET Core 1.0

mysql - 如何测试使用数据库(mysql)的 Go 代码?

c# - 无法使 httpErrors 工作