如何将图像附加到TRX(报告测试结果)文件? [英] How can I attach an image to TRX (Test Result Reported) File?

查看:105
本文介绍了如何将图像附加到TRX(报告测试结果)文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在发生错误时测试屏幕截图。

I would like to my test takes screenshot when an error occur.

我可以这样写:

TestContext.WriteLine("aaaaaaaaa");

但是如何将图像附加到.TRX文件?

But how can I attach an image to a .TRX file?

已报告测试结果(。 TRX)

推荐答案

控件和整个桌面的图像可以在编码的UI测试期间拍摄。它们被捕获为普通的 Image 对象,然后可以在测试中保存或进行其他操作。这些文件也可以附加到测试结果中。下面的代码对可以使用的代码给出了一些想法。

Images of controls and of the entire desktop can be taken during a Coded UI test. They are captured as normal Image objects and can then be saved or otherwise manipulated in the test. The files can also be attached to the test results. The code below gives some ideas on the code that can be used.

UITestControl ccc = this.UIMap.uiOne.uiTwo;
Image cccImage = ccc.CaptureImage();
cccImage.Save(@"C:\cccName.bmp");
TestContext.AddResultFile(@"C:\cccName.bmp");

Image desktopImage = UITestControl.Desktop.CaptureImage()
desktopImage.Save(@"C:\desktopImage.bmp");
TestContext.AddResultFile(@"C:\desktopImage.bmp");

...保存应该修改调用以为每个保存的图像赋予不同的名称。当测试由数据驱动时,这是特别必要的,否则将无法将图像与测试执行相关联。

The file name used in the ...Save call should be modified to give each saved image a different name. This is specially necessary when the tests are data driven, otherwise there will be no way of associating images with test executions.

这篇关于如何将图像附加到TRX(报告测试结果)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆