c#-硒-MSTest-无法使用testcontext将结果文件(使用testcontext.AddResultFile)添加到报表中 [英] c# - selenium - MSTest - Unable to add a result file ( using testcontext.AddResultFile ) to the report using testcontext

查看:216
本文介绍了c#-硒-MSTest-无法使用testcontext将结果文件(使用testcontext.AddResultFile)添加到报表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MSTest-C#-Selenium运行一组测试.如果存在失败的步骤,我正在截屏,并希望将其与trx文件一起上传(附加)

I am using MSTest - C# - Selenium to run a suite of tests. I am taking a screenshot if there is a failed step and wish to upload ( attach ) it with the trx file,

当我将其作为几个测试中的一个测试运行时,一切都很好,并且结果与附件一起出现.

All is good when I run it as a single test of a couple of tests and the results are with the attachment.

但是当我在Parallel中运行测试时,即使测试失败,我也无法看到带有附件的结果文件

But when I run the tests in Parallel, I am not able to see the result file with the attachment even though the test is FAILED

我在trx文件中得到了以下内容

I get the below in the trx file

TestContext消息: 值不能为空. 参数名称:路径

TestContext Messages: Value cannot be null. Parameter name: path

我用于将文件附加到trx文件的代码是

The code I am using to attach the file to the trx file is

Screenshot screenShot = ((ITakesScreenshot)driver).GetScreenshot();
string fileName = fullFilePath + "Screenshot_" + driver.testContext.TestName + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss")+".png";
screenShot.SaveAsFile((fileName), ImageFormat.Png);                
driver.testContext.AddResultFile(fileName);

我要去哪里的任何指针.在谷歌搜索时,我看到了几个链接,他们提到这是一个已知问题.有什么我可以做的事情来解决这个问题.

Any pointers where I am going wrong. I saw a couple of links while googling and they mention this is a known issue. Is there something I can do as a work around to circumvent this issue.

任何指针都将非常有帮助.谢谢

Any pointers will be very helpful. Thanks

推荐答案

我的2美分...

下面的代码解决了这个问题...

The below code solved the issue...

            Directory.CreateDirectory(MyWebDriver.testContext.TestResultsDirectory);
            Screenshot screenShot = ((ITakesScreenshot)MyWebDriver).GetScreenshot();
            string fileName = MyWebDriver.testContext.TestResultsDirectory+"\\Screenshot_" + MyWebDriver.testContext.TestName + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss")+".png";
            screenShot.SaveAsFile((fileName), ImageFormat.Png);                

请注意,MyWebDriver是针对我的项目需求量身定制的Selenium WebDriver的扩展.

Please note that MyWebDriver is an extension of Selenium WebDriver tailored for my project requirements.

有关此问题的原因,请参考以下链接.

Refer the below link for the cause of this issue.

查看全文

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