在哪里可以找到TestContext.AddResultFile()? [英] Where do I find TestContext.AddResultFile()?

查看:78
本文介绍了在哪里可以找到TestContext.AddResultFile()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在引用记录在 Microsoft.VisualStudio.TestTools.UnitTesting 上的 TestContext 类上的 AddResultFile()方法>包/命名空间.

I am having trouble referencing the documented method AddResultFile() on the TestContext class, allegedly found in the Microsoft.VisualStudio.TestTools.UnitTesting package/namespace.

这是我的包裹清单:

<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)的一部分(部分):

This is (a part of) my test (step definition - it's SpecFlow) class:

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()方法?我以为我缺少参考...?

How do I find and use the AddResultFile() method? I assume I'm missing a reference...?

推荐答案

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

There was a bug in MSTest.TestFramework package reported here: https://github.com/Microsoft/testfx/issues/394

从今天开始的4天前,通过拉取请求即可解决该问题:

It is resolved 4 days ago from today in a pull request :

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

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

But I can not see any update in nuget version from last 23 days for version 2.0.0-beta4 and there is no version after that right now. https://www.nuget.org/packages/MSTest.TestFramework/

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

Intermediate fix is to use latest bits from here till there is new update with this fix:

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

In particular, you should update your adapter and framework nuget package to these versions: 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

更新09/2019 :MS测试框架的v2正式发布,其中包含有问题的方法.

Update 09/2019: the v2 of the MS Test Framework was officially released with the method in question included.

这篇关于在哪里可以找到TestContext.AddResultFile()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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