c# - selenium - MSTest - 无法使用 testcontext 将结果文件(使用 testcontext.AddResultFile)添加到报告中

c# - selenium - MSTest - Unable to add a result file ( using testcontext.AddResultFile ) to the report using testcontext

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

当我 运行 将它作为几个测试中的一个测试时,一切都很好,结果在附件中。

但是当我 运行 并行测试时,即使测试失败,我也看不到带有附件的结果文件

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

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

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

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);

任何我出错的地方。我在谷歌搜索时看到了几个链接,他们提到这是一个已知问题。我可以做些什么来解决这个问题。

任何指点都会很有帮助。谢谢

我的 2 美分...

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

            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 的扩展。

有关此问题的原因,请参阅下面的 link。

https://connect.microsoft.com/VisualStudio/feedback/details/1062039/value-cannot-be-null-parameter-name-path-in-test-result-when-running-tests-in-parallel-and-adding-files-to-the-test-context-using-addresultfile