Код: Выделить всё
Код: Выделить всё
Имеет этот код:
Код: Выделить всё
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,
});
}
}
Тип TestContext определен в сборке, на которую нет ссылок. Вы должны добавить ссылку на сборку «Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a».
В настоящее время я использую .net9.
Весь файл проекта выглядит следующим образом:
Код: Выделить всё
net9.0
latest
enable
enable
true
Exe
true
true
PreserveNewest
true
PreserveNewest
PreserveNewest
true
PreserveNewest
PreserveNewest
PreserveNewest
true
PreserveNewest
PreserveNewest
PreserveNewest
PreserveNewest
PreserveNewest
Подробнее здесь: https://stackoverflow.com/questions/798 ... ight-tests
Мобильная версия