问题
I am having trouble referencing the documented method AddResultFile()
on the TestContext
class, allegedly found in the Microsoft.VisualStudio.TestTools.UnitTesting
package/namespace.
This is my package list:
<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" />
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
}
}
}
How do I find and use the AddResultFile()
method? I assume I'm missing a reference...?
回答1:
There was a bug in MSTest.TestFramework
package reported here:
https://github.com/Microsoft/testfx/issues/394
It is resolved 4 days ago from today in a pull request :
https://github.com/Microsoft/testfx/pull/609
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
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
Update 09/2019: the v2 of the MS Test Framework was officially released with the method in question included.
来源:https://stackoverflow.com/questions/55967929/where-do-i-find-testcontext-addresultfile