Code: Select all
Code: Select all
Mit diesem Code:
Code: Select all
public abstract class PlaywrightTestBase : PageTest
{
private IBrowserContext _testContextInstance = null!;
protected IPage TestPage = null!;
protected virtual string? DeviceName => null;
[TestInitialize]
public async Task TestInitializeAsync()
{
//On mobile we start a new context, on desktop we use the default one
if (DeviceName != null)
{
var device = Playwright.Devices[DeviceName];
_testContextInstance = await Browser.NewContextAsync(device);
TestPage = await _testContextInstance.NewPageAsync();
}
else
{
_testContextInstance = Context;
TestPage = Page;
}
await _testContextInstance.Tracing.StartAsync(new()
{
Title = $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}",
Screenshots = true,
Snapshots = true,
Sources = true
});
}
[TestCleanup]
public async Task TestCleanupAsync()
{
var failed = new[]
{
UnitTestOutcome.Failed,
UnitTestOutcome.Error,
UnitTestOutcome.Timeout,
UnitTestOutcome.Aborted
}.Contains(TestContext.CurrentTestOutcome);
await _testContextInstance.Tracing.StopAsync(new()
{
Path = failed ? Path.Combine(
Environment.CurrentDirectory,
"playwright-traces",
$"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip"
) : null,
});
}
}
Der Typ „TestContext“ ist in einer Assembly definiert, auf die nicht verwiesen wird. Sie müssen einen Verweis auf die Assembly „Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a“ hinzufügen.
Ich verwende derzeit .net9.
Weiß jemand, wie man mit diesem Problem umgeht?
Mobile version