我正在运行一个编码的UI测试,它需要执行6个阶段。每个阶段都通过按兼容按钮来运行。我使用:System.Diagnostics.Process.Start()启动应用程序,对其运行编码的UI测试;
运行编码的UI测试的TestMethod:
/// </summary>
[TestMethod]
public void CodedUITestMethod1()
{
System.Diagnostics.Process.Start(<Path of the application>);
`enter code here`
}在TestMethod中,我想从正在运行的进程中捕获退出代码或异常,因为如果6个阶段中的一个失败,我想停止这个自动化测试。
我该怎么做呢?
Evh671。
发布于 2014-02-11 21:34:08
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事件可能用于捕获异常。不过,我没有使用它的经验。
void p_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (Playback.IsSessionStarted)
{
Playback.StopSession();
}
throw new System.Exception("Something something");
}https://stackoverflow.com/questions/21698376
复制相似问题