How can I attach an image to TRX (Test Result Reported) File?

↘锁芯ラ 提交于 2019-12-12 04:17:17

问题


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

I can write like this:

TestContext.WriteLine("aaaaaaaaa");

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

Test Result Reported (.TRX)


回答1:


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.



来源:https://stackoverflow.com/questions/33696792/how-can-i-attach-an-image-to-trx-test-result-reported-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!