【问题标题】:c# - selenium - MSTest - Unable to add a result file ( using testcontext.AddResultFile ) to the report using testcontextc# - selenium - MSTest - 无法使用 testcontext 将结果文件(使用 testcontext.AddResultFile)添加到报告中
【发布时间】:2016-07-21 12:52:19
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# visual-studio selenium mstest testcontext


    【解决方案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

    【讨论】:

    • 您好,该链接不再可用,您还记得问题的原因吗?
    • 您是如何将 testContext 放入您的自定义 Web 驱动程序的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2015-07-19
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多