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

时间:2016-07-19 05:39:51

标签: c# visual-studio selenium mstest testcontext

我正在使用MSTest - C# - Selenium来运行一系列测试。如果步骤失败并且希望使用trx文件上传(附加)

,我会截取屏幕截图

当我将它作为几个测试的单个测试运行并且结果与附件一起时,一切都很好。

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

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

我出错的任何指针。我在google搜索时看到了几个链接,他们提到这是一个已知的问题。我能做些什么来解决这个问题。

任何指针都会非常有用。感谢

1 个答案:

答案 0 :(得分:1)

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

请参阅以下链接以了解此问题的原因。

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

相关问题