在哪里可以找到TestContext.AddResultFile()?

时间:2019-05-03 10:26:59

标签: c# .net-core azure-devops selenium-chromedriver mstest

我在引用AddResultFile()包/命名空间中的TestContext类上引用the documented method Microsoft.VisualStudio.TestTools.UnitTesting时遇到麻烦。

这是我的包裹清单:

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.46.0" />
<PackageReference Include="specflow" Version="3.0.199" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.0.199" />
<PackageReference Include="SpecFlow.MsTest" Version="3.0.199" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0-beta4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0-beta4" />

这是我的测试(步骤定义-它是SpecFlow)类的一部分(部分):

using System;
using System.IO;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using TechTalk.SpecFlow;
using XunitTestLib.Drivers;
using XunitTestLib.Helpers;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace XunitTestLib.StepDefinitions
{
    [Binding]
    public class BrowserSteps : BrowserDriver
    {
        public IWebElement CurrentElement { get; set; }
        public TestContext TestContext { get; set; }

        public BrowserSteps(TestContext tcontext)
        {
            this.TestContext = tcontext;
        }

        [Given(@"I navigate to (.*)")]
        [When(@"I navigate to (.*)")]
        [Then(@"I navigate to (.*)")]
        public void INavigateTo_(string url)
        {
            Browser.Navigate().GoToUrl(url);
        }

        // ***Numerous methods for specflow/selenium-based testing***

        [Given(@"I take a screenshot")]
        [When(@"I take a screenshot")]
        [Then(@"I take a screenshot")]
        public void ITakeAScreenshot()
        {
            var sep = Path.DirectorySeparatorChar;

            var time = DateTime.Now.ToString("yyyy-MM-dd_HH_mm_SS_") + DateTime.Now.Ticks;

            var path = $@"{Directory.GetCurrentDirectory()}{sep}{time}.png";

            Browser
                .GetScreenshot()
                .SaveAsFile(path);

            TestContext.AddResultFile(path); // THIS METHOD NOT FOUND
        }
    }
}

如何查找和使用AddResultFile()方法?我以为我缺少参考...?

1 个答案:

答案 0 :(得分:1)

MSTest.TestFramework软件包中存在一个错误,报告如下: https://github.com/Microsoft/testfx/issues/394

从今天起4天前,通过拉取请求解决了该问题:

https://github.com/Microsoft/testfx/pull/609

但是我看不到过去2.0.0-beta4的过去23天中nuget版本的任何更新,并且此后没有任何版本。 https://www.nuget.org/packages/MSTest.TestFramework/

中间修订是使用此处的最新信息直到此修订有新更新

https://dotnet.myget.org/F/mstestv2/api/v3/index.json

尤其是,您应该将适配器和框架nuget软件包更新为以下版本: https://dotnet.myget.org/feed/mstestv2/package/nuget/MSTest.TestAdapter/2.0.0-build-20190430-01 https://dotnet.myget.org/feed/mstestv2/package/nuget/MSTest.TestFramework/2.0.0-build-20190430-01