首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coded UI Testing VS2012 -如何从正在运行的进程中获取退出代码?

Coded UI Testing VS2012 -如何从正在运行的进程中获取退出代码?
EN

Stack Overflow用户
提问于 2014-02-11 17:52:19
回答 1查看 372关注 0票数 0

我正在运行一个编码的UI测试,它需要执行6个阶段。每个阶段都通过按兼容按钮来运行。我使用:System.Diagnostics.Process.Start()启动应用程序,对其运行编码的UI测试;

运行编码的UI测试的TestMethod:

代码语言:javascript
复制
/// </summary>
        [TestMethod]
        public void CodedUITestMethod1()
        {
              System.Diagnostics.Process.Start(<Path of the application>);
              `enter code here`
        }

在TestMethod中,我想从正在运行的进程中捕获退出代码或异常,因为如果6个阶段中的一个失败,我想停止这个自动化测试。

我该怎么做呢?

Evh671。

EN

回答 1

Stack Overflow用户

发布于 2014-02-11 21:34:08

代码语言:javascript
复制
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = <Path of the application>;
p.Start();

//or
//var p = System.Diagnostics.Process.Start(<Path of the application>);

...Do UI testing here...

p.WaitForExit();
if (p.ExitCode != 0)
{
    throw new System.Exception("Something something");
}

p.ErrorDataReceived事件可能用于捕获异常。不过,我没有使用它的经验。

代码语言:javascript
复制
void p_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
    if (Playback.IsSessionStarted)
    {
        Playback.StopSession();
    }
    throw new System.Exception("Something something");
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21698376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档