diff --git a/src/Playwright.Nunit/Playwright.Nunit.csproj b/src/Playwright.Nunit/Playwright.Nunit.csproj
new file mode 100644
index 0000000000..1a762cf088
--- /dev/null
+++ b/src/Playwright.Nunit/Playwright.Nunit.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net10.0
+ Microsoft.Playwright.Nunit
+ Microsoft.Playwright.Nunit
+
+
+
+
+
+
+
+
+
diff --git a/src/Playwright.Nunit/PlaywrightTestAttribute.cs b/src/Playwright.Nunit/PlaywrightTestAttribute.cs
new file mode 100644
index 0000000000..4d37cc8298
--- /dev/null
+++ b/src/Playwright.Nunit/PlaywrightTestAttribute.cs
@@ -0,0 +1,75 @@
+using System;
+
+namespace Microsoft.Playwright.Nunit
+{
+ ///
+ /// Enables decorating test facts with information about the corresponding test in the upstream repository.
+ ///
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
+ public class PlaywrightTestAttribute : Attribute
+ {
+ ///
+ /// Gets the product based on the PRODUCT environment variable.
+ ///
+ public static string Product => string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PRODUCT"))
+ ? "CHROMIUM"
+ : Environment.GetEnvironmentVariable("PRODUCT");
+
+ ///
+ /// Gets a value indicating whether we are testing Chromium.
+ ///
+ public static bool IsChromium => Product.Equals("CHROMIUM", StringComparison.OrdinalIgnoreCase);
+
+ ///
+ /// Gets a value indicating whether we are testing Firefox.
+ ///
+ public static bool IsFirefox => Product.Equals("FIREFOX", StringComparison.OrdinalIgnoreCase);
+
+ ///
+ /// Gets a value indicating whether we are testing WebKit.
+ ///
+ public static bool IsWebkit => Product.Equals("WEBKIT", StringComparison.OrdinalIgnoreCase);
+
+ ///
+ /// Creates a new instance of the attribute.
+ ///
+ ///
+ ///
+ public PlaywrightTestAttribute(string fileName, string nameOfTest)
+ {
+ FileName = fileName;
+ TestName = nameOfTest;
+ }
+
+ ///
+ /// Creates a new instance of the attribute.
+ ///
+ ///
+ ///
+ ///
+ public PlaywrightTestAttribute(string fileName, string describe, string nameOfTest) : this(fileName, nameOfTest)
+ {
+ Describe = describe;
+ }
+
+ ///
+ /// The file name origin of the test.
+ ///
+ public string FileName { get; }
+
+ ///
+ /// Returns the trimmed file name.
+ ///
+ public string TrimmedName => FileName.Substring(0, FileName.IndexOf('.'));
+
+ ///
+ /// The name of the test, the decorated code is based on.
+ ///
+ public string TestName { get; }
+
+ ///
+ /// The describe of the test, the decorated code is based on, if one exists.
+ ///
+ public string Describe { get; }
+ }
+}
diff --git a/src/Playwright.Tests/Attributes/SkipBrowserAndPlatformFact.cs b/src/Playwright.Tests/Attributes/SkipBrowserAndPlatformFact.cs
index 092e9d1ef6..6eb6ec0ced 100644
--- a/src/Playwright.Tests/Attributes/SkipBrowserAndPlatformFact.cs
+++ b/src/Playwright.Tests/Attributes/SkipBrowserAndPlatformFact.cs
@@ -1,13 +1,25 @@
-using System.Runtime.InteropServices;
-using Xunit;
+using System;
+using NUnit.Framework;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using OSPlatform = System.Runtime.InteropServices.OSPlatform;
+using RuntimeInformation = System.Runtime.InteropServices.RuntimeInformation;
namespace Microsoft.Playwright.Tests.Attributes
{
///
/// Skip browsers and/or platforms
///
- public class SkipBrowserAndPlatformFact : FactAttribute
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
+ public class SkipBrowserAndPlatformFact : NUnitAttribute, IApplyToTest
{
+ private readonly bool _skipFirefox;
+ private readonly bool _skipChromium;
+ private readonly bool _skipWebkit;
+ private readonly bool _skipOSX;
+ private readonly bool _skipWindows;
+ private readonly bool _skipLinux;
+
///
/// Creates a new
///
@@ -25,14 +37,26 @@ public SkipBrowserAndPlatformFact(
bool skipWindows = false,
bool skipLinux = false)
{
- Timeout = TestConstants.DefaultTestTimeout;
+ _skipFirefox = skipFirefox;
+ _skipChromium = skipChromium;
+ _skipWebkit = skipWebkit;
+ _skipOSX = skipOSX;
+ _skipWindows = skipWindows;
+ _skipLinux = skipLinux;
+ }
- if (SkipBrowser(skipFirefox, skipChromium, skipWebkit) && SkipPlatform(skipOSX, skipWindows, skipLinux))
+ public void ApplyToTest(Test test)
+ {
+ if (ShouldSkip())
{
- Skip = "Skipped by browser/platform";
+ test.RunState = RunState.Ignored;
+ test.Properties.Set(PropertyNames.SkipReason, "Skipped by browser/platform");
}
}
+ private bool ShouldSkip()
+ => SkipBrowser(_skipFirefox, _skipChromium, _skipWebkit) && SkipPlatform(_skipOSX, _skipWindows, _skipLinux);
+
private static bool SkipPlatform(bool skipOSX, bool skipWindows, bool skipLinux)
=>
(
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpBaseTest.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpBaseTest.cs
index b927f3a7d0..8472e7c2f7 100644
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpBaseTest.cs
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpBaseTest.cs
@@ -1,25 +1,14 @@
-using System;
using System.IO;
-using System.Reflection;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Logging;
-using Microsoft.Playwright;
-using Microsoft.Playwright.Testing.Xunit;
-using Microsoft.Playwright.Tests.Helpers;
using Microsoft.Playwright.Tests.TestServer;
-using Microsoft.Playwright.Transport.Channels;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests.BaseTests
{
///
/// This base tests setup logging and http servers
///
- public class PlaywrightSharpBaseTest : IDisposable
+ public class PlaywrightSharpBaseTest
{
- private readonly XunitLoggerProvider _loggerProvider;
- private readonly ILogger _httpLogger;
-
internal IPlaywright Playwright => PlaywrightSharpBrowserLoaderFixture.Playwright;
internal string BaseDirectory { get; set; }
internal IBrowserType BrowserType => Playwright[TestConstants.Product];
@@ -27,7 +16,8 @@ public class PlaywrightSharpBaseTest : IDisposable
internal SimpleServer Server => PlaywrightSharpLoader.Server;
internal SimpleServer HttpsServer => PlaywrightSharpLoader.HttpsServer;
- internal PlaywrightSharpBaseTest(ITestOutputHelper output)
+ [SetUp]
+ public void BaseSetUp()
{
BaseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "workspace");
var dirInfo = new DirectoryInfo(BaseDirectory);
@@ -37,42 +27,8 @@ internal PlaywrightSharpBaseTest(ITestOutputHelper output)
dirInfo.Create();
}
- Initialize();
-
- _loggerProvider = new XunitLoggerProvider(output);
- _httpLogger = TestConstants.LoggerFactory.CreateLogger();
- TestConstants.LoggerFactory.AddProvider(_loggerProvider);
- Server.RequestReceived += Server_RequestReceived;
- HttpsServer.RequestReceived += Server_RequestReceived;
-
- output.WriteLine($"Running {GetDisplayName(output)}");
- }
-
- private void Server_RequestReceived(object sender, RequestReceivedEventArgs e)
- {
- _httpLogger.LogInformation($"Incoming request: {e.Request.Path}");
- }
-
- private static string GetDisplayName(ITestOutputHelper output)
- {
- var type = output.GetType();
- var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
- var test = (ITest)testMember.GetValue(output);
- return test.DisplayName;
- }
-
- internal void Initialize()
- {
Server.Reset();
HttpsServer.Reset();
}
-
- ///
- public virtual void Dispose()
- {
- Server.RequestReceived -= Server_RequestReceived;
- HttpsServer.RequestReceived -= Server_RequestReceived;
- _loggerProvider.Dispose();
- }
}
}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserBaseTest.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserBaseTest.cs
index 1132fd3668..8b7dd3e399 100644
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserBaseTest.cs
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserBaseTest.cs
@@ -1,19 +1,10 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Xunit;
-using Xunit.Abstractions;
-
namespace Microsoft.Playwright.Tests.BaseTests
{
///
- /// Based on , this base class also creates a new Browser
+ /// Based on , this base class also provides access to the Browser.
///
public class PlaywrightSharpBrowserBaseTest : PlaywrightSharpBaseTest
{
internal IBrowser Browser => PlaywrightSharpBrowserLoaderFixture.Browser;
-
- internal PlaywrightSharpBrowserBaseTest(ITestOutputHelper output) : base(output)
- {
- }
}
}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserContextBaseTest.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserContextBaseTest.cs
index 554a461c24..fc0b11eb69 100644
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserContextBaseTest.cs
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserContextBaseTest.cs
@@ -1,34 +1,26 @@
-using System;
-using System.IO;
using System.Threading.Tasks;
-using Microsoft.Playwright.Helpers;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests.BaseTests
{
///
- /// Based on , this calss creates a new
+ /// Based on , this class creates a new
///
- public class PlaywrightSharpBrowserContextBaseTest : PlaywrightSharpBrowserBaseTest, IAsyncLifetime
+ public class PlaywrightSharpBrowserContextBaseTest : PlaywrightSharpBrowserBaseTest
{
- internal PlaywrightSharpBrowserContextBaseTest(ITestOutputHelper output) : base(output)
- {
- }
-
internal IBrowserContext Context { get; set; }
- ///
- public virtual async Task DisposeAsync()
+ [SetUp]
+ public virtual async Task ContextSetUp()
{
- await Context.CloseAsync();
+ Context = await Browser.NewContextAsync();
+ Context.DefaultTimeout = TestConstants.DefaultPuppeteerTimeout;
}
- ///
- public virtual async Task InitializeAsync()
+ [TearDown]
+ public virtual async Task ContextTearDown()
{
- Context = await Browser.NewContextAsync();
- Context.DefaultTimeout = TestConstants.DefaultPuppeteerTimeout;
+ await Context.CloseAsync();
}
}
}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderCollection.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderCollection.cs
deleted file mode 100644
index 13fd06d05b..0000000000
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderCollection.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Xunit;
-
-namespace Microsoft.Playwright.Tests.BaseTests
-{
- /// This class has no code, and is never created. Its purpose is simply
- /// to be the place to apply [CollectionDefinition] and all the ICollectionFixture interfaces.
- /// Recipe from https://xunit.github.io/docs/shared-context.html#class-fixture
- [CollectionDefinition(TestConstants.TestFixtureBrowserCollectionName, DisableParallelization = true)]
- public class PlaywrightSharpBrowserLoaderCollection : ICollectionFixture
- {
- }
-}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderFixture.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderFixture.cs
index 5c94e810c8..535b808260 100644
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderFixture.cs
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpBrowserLoaderFixture.cs
@@ -1,25 +1,18 @@
using System;
using System.Threading.Tasks;
-using Xunit;
namespace Microsoft.Playwright.Tests.BaseTests
{
///
/// This class setup a single browser instance for tests.
///
- public class PlaywrightSharpBrowserLoaderFixture : IAsyncLifetime
+ public class PlaywrightSharpBrowserLoaderFixture
{
internal static IPlaywright Playwright { get; private set; }
internal static IBrowser Browser { get; private set; }
- ///
- public Task InitializeAsync() => LaunchBrowserAsync();
-
- ///
- public Task DisposeAsync() => ShutDownAsync();
-
- private static async Task LaunchBrowserAsync()
+ internal static async Task LaunchBrowserAsync()
{
try
{
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpPageBaseTest.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpPageBaseTest.cs
index e66b6b7388..c80a2f0f31 100644
--- a/src/Playwright.Tests/BaseTests/PlaywrightSharpPageBaseTest.cs
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpPageBaseTest.cs
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2020 Darío Kondratiuk
+ * Copyright (c) 2020 Dario Kondratiuk
* Copyright (c) 2020 Meir Blachman
* Modifications copyright (c) Microsoft Corporation.
*
@@ -23,31 +23,25 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-using System;
using System.Threading.Tasks;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests.BaseTests
{
///
- /// Based on , this class will create a new Page.
+ /// Based on , this class will create a new Page.
///
public class PlaywrightSharpPageBaseTest : PlaywrightSharpBrowserContextBaseTest
{
- internal PlaywrightSharpPageBaseTest(ITestOutputHelper output) : base(output)
- {
- }
-
///
/// Gets or sets the Page.
///
protected IPage Page { get; set; }
- ///
- public override async Task InitializeAsync()
+ ///
+ public override async Task ContextSetUp()
{
- await base.InitializeAsync();
+ await base.ContextSetUp();
Page = await Context.NewPageAsync();
}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightSharpSetUpFixture.cs b/src/Playwright.Tests/BaseTests/PlaywrightSharpSetUpFixture.cs
new file mode 100644
index 0000000000..672f523971
--- /dev/null
+++ b/src/Playwright.Tests/BaseTests/PlaywrightSharpSetUpFixture.cs
@@ -0,0 +1,25 @@
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+[assembly: NonParallelizable]
+
+namespace Microsoft.Playwright.Tests.BaseTests
+{
+ [SetUpFixture]
+ public class PlaywrightSharpSetUpFixture
+ {
+ [OneTimeSetUp]
+ public async Task GlobalSetUp()
+ {
+ await PlaywrightSharpLoader.SetupAsync();
+ await PlaywrightSharpBrowserLoaderFixture.LaunchBrowserAsync();
+ }
+
+ [OneTimeTearDown]
+ public async Task GlobalTearDown()
+ {
+ await PlaywrightSharpBrowserLoaderFixture.ShutDownAsync();
+ await PlaywrightSharpLoader.TeardownAsync();
+ }
+ }
+}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestAssemblyRunner.cs b/src/Playwright.Tests/BaseTests/PlaywrightXunitTestAssemblyRunner.cs
deleted file mode 100644
index f6bad556d8..0000000000
--- a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestAssemblyRunner.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Xunit;
-using Xunit.Abstractions;
-using Xunit.Sdk;
-
-namespace Microsoft.Playwright.Tests.BaseTests
-{
- ///
- public class PlaywrightXunitTestAssemblyRunner : XunitTestAssemblyRunner
- {
- ///
- public PlaywrightXunitTestAssemblyRunner(ITestAssembly testAssembly, IEnumerable testCases, IMessageSink diagnosticMessageSink, IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions) : base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions)
- {
- }
-
- ///
- protected override async Task AfterTestAssemblyStartingAsync()
- {
- await base.AfterTestAssemblyStartingAsync();
- await PlaywrightSharpLoader.SetupAsync();
- }
-
- ///
- protected override async Task BeforeTestAssemblyFinishedAsync()
- {
- await base.BeforeTestAssemblyFinishedAsync();
- await PlaywrightSharpLoader.TeardownAsync();
- }
- }
-}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFramework.cs b/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFramework.cs
deleted file mode 100644
index da80650bf5..0000000000
--- a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFramework.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System.Reflection;
-using Xunit;
-using Xunit.Abstractions;
-using Xunit.Sdk;
-
-[assembly: TestFramework("Microsoft.Playwright.Tests.BaseTests.PlaywrightXunitTestFramework", "Microsoft.Playwright.Tests")]
-[assembly: CollectionBehavior(DisableTestParallelization = true)]
-
-namespace Microsoft.Playwright.Tests.BaseTests
-{
- ///
- public class PlaywrightXunitTestFramework : XunitTestFramework
- {
- ///
- public PlaywrightXunitTestFramework(IMessageSink messageSink) : base(messageSink)
- {
- }
-
- ///
- protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
- => new PlaywrightXunitTestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink);
- }
-}
diff --git a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFrameworkExecutor.cs b/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFrameworkExecutor.cs
deleted file mode 100644
index 841e629466..0000000000
--- a/src/Playwright.Tests/BaseTests/PlaywrightXunitTestFrameworkExecutor.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Collections.Generic;
-using System.Reflection;
-using Xunit.Abstractions;
-using Xunit.Sdk;
-
-namespace Microsoft.Playwright.Tests.BaseTests
-{
- ///
- public class PlaywrightXunitTestFrameworkExecutor : XunitTestFrameworkExecutor
- {
- ///
- public PlaywrightXunitTestFrameworkExecutor(AssemblyName assemblyName, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink) : base(assemblyName, sourceInformationProvider, diagnosticMessageSink)
- {
- }
-
- ///
- protected override void RunTestCases(IEnumerable testCases, IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions)
- {
- using (var assemblyRunner = new PlaywrightXunitTestAssemblyRunner(TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink, executionOptions))
- {
- assemblyRunner.RunAsync();
- }
- }
- }
-}
diff --git a/src/Playwright.Tests/BeforeUnloadTests.cs b/src/Playwright.Tests/BeforeUnloadTests.cs
index a16fe6c81e..9be351dc9b 100644
--- a/src/Playwright.Tests/BeforeUnloadTests.cs
+++ b/src/Playwright.Tests/BeforeUnloadTests.cs
@@ -1,22 +1,13 @@
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BeforeUnloadTests : PlaywrightSharpPageBaseTest
- {
- ///
- public BeforeUnloadTests(ITestOutputHelper output) : base(output)
- {
- }
-
-
- [PlaywrightTest("beforeunload.spec.ts", "should run beforeunload if asked for")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("beforeunload.spec.ts", "should run beforeunload if asked for")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldRunBeforeunloadIfAskedFor()
{
var newPage = await Context.NewPageAsync();
@@ -28,19 +19,19 @@ public async Task ShouldRunBeforeunloadIfAskedFor()
var dialogTask = newPage.WaitForEventAsync(PageEvent.Dialog);
var pageClosingTask = newPage.CloseAsync(true);
var dialog = await dialogTask;
- Assert.Equal(DialogType.BeforeUnload, dialog.Type);
- Assert.Empty(dialog.DefaultValue);
+ Assert.That(dialog.Type, Is.EqualTo(DialogType.BeforeUnload));
+ Assert.That(dialog.DefaultValue, Is.Empty);
if (TestConstants.IsChromium)
{
- Assert.Empty(dialog.Message);
+ Assert.That(dialog.Message, Is.Empty);
}
else if (TestConstants.IsWebKit)
{
- Assert.Equal("Leave?", dialog.Message);
+ Assert.That(dialog.Message, Is.EqualTo("Leave?"));
}
else
{
- Assert.Equal("This page is asking you to confirm that you want to leave - data you have entered may not be saved.", dialog.Message);
+ Assert.That(dialog.Message, Is.EqualTo("This page is asking you to confirm that you want to leave - data you have entered may not be saved."));
}
await dialog.AcceptAsync();
@@ -48,7 +39,7 @@ public async Task ShouldRunBeforeunloadIfAskedFor()
}
[PlaywrightTest("beforeunload.spec.ts", "should *not* run beforeunload by default")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotRunBeforeunloadByDefault()
{
var newPage = await Context.NewPageAsync();
diff --git a/src/Playwright.Tests/BrowserContextAddCookiesTests.cs b/src/Playwright.Tests/BrowserContextAddCookiesTests.cs
index 302f24c64e..9d96604bd9 100644
--- a/src/Playwright.Tests/BrowserContextAddCookiesTests.cs
+++ b/src/Playwright.Tests/BrowserContextAddCookiesTests.cs
@@ -2,23 +2,15 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextAddCookiesTests : PlaywrightSharpPageBaseTest
- {
- ///
- public BrowserContextAddCookiesTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-add-cookies.spec.ts", "should work")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-add-cookies.spec.ts", "should work")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWork()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -28,22 +20,22 @@ public async Task ShouldWork()
Name = "password",
Value = "123456"
} });
- Assert.Equal("password=123456", await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.EqualTo("password=123456"));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should roundtrip cookie")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldRoundtripCookie()
{
await Page.GoToAsync(TestConstants.EmptyPage);
- Assert.Equal("username=John Doe", await Page.EvaluateAsync(@"timestamp => {
+ Assert.That(await Page.EvaluateAsync(@"timestamp => {
const date = new Date(timestamp);
document.cookie = `username=John Doe;expires=${date.toUTCString()}`;
return document.cookie;
- }", new DateTime(2038, 1, 1)));
+ }", new DateTime(2038, 1, 1)), Is.EqualTo("username=John Doe"));
var cookies = await Context.GetCookiesAsync();
await Context.ClearCookiesAsync();
- Assert.Empty(await Context.GetCookiesAsync());
+ Assert.That(await Context.GetCookiesAsync(), Is.Empty);
await Context.AddCookiesAsync(cookies.Select(c => new Cookie()
{
Domain = c.Domain,
@@ -56,11 +48,11 @@ public async Task ShouldRoundtripCookie()
Value = c.Value
}));
var newCookies = await Context.GetCookiesAsync();
- Assert.Equal(cookies, newCookies);
+ Assert.That(newCookies, Is.EqualTo(cookies));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should send cookie header")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSendCookieHeader()
{
string cookie = string.Empty;
@@ -79,11 +71,11 @@ await Context.AddCookiesAsync(new Cookie
var page = await Context.NewPageAsync();
await Page.GoToAsync(TestConstants.EmptyPage);
- Assert.Equal("cookie=value", cookie);
+ Assert.That(cookie, Is.EqualTo("cookie=value"));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should isolate cookies in browser contexts")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateCookiesInBrowserContexts()
{
await using var anotherContext = await Browser.NewContextAsync();
@@ -104,16 +96,16 @@ await anotherContext.AddCookiesAsync(new Cookie
var cookies1 = await Context.GetCookiesAsync();
var cookies2 = await anotherContext.GetCookiesAsync();
- Assert.Single(cookies1);
- Assert.Single(cookies2);
- Assert.Equal("isolatecookie", cookies1.ElementAt(0).Name);
- Assert.Equal("page1value", cookies1.ElementAt(0).Value);
- Assert.Equal("isolatecookie", cookies2.ElementAt(0).Name);
- Assert.Equal("page2value", cookies2.ElementAt(0).Value);
+ Assert.That(cookies1, Has.Count.EqualTo(1));
+ Assert.That(cookies2, Has.Count.EqualTo(1));
+ Assert.That(cookies1.ElementAt(0).Name, Is.EqualTo("isolatecookie"));
+ Assert.That(cookies1.ElementAt(0).Value, Is.EqualTo("page1value"));
+ Assert.That(cookies2.ElementAt(0).Name, Is.EqualTo("isolatecookie"));
+ Assert.That(cookies2.ElementAt(0).Value, Is.EqualTo("page2value"));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should isolate session cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateSessionCookies()
{
Server.SetRoute("/setcookie.html", context =>
@@ -132,11 +124,11 @@ public async Task ShouldIsolateSessionCookies()
page = await context2.NewPageAsync();
await page.GoToAsync(TestConstants.EmptyPage);
var cookies = await context2.GetCookiesAsync();
- Assert.Empty(cookies);
+ Assert.That(cookies, Is.Empty);
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should isolate persistent cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolatePersistentCookies()
{
Server.SetRoute("/setcookie.html", context =>
@@ -155,14 +147,14 @@ await TaskUtils.WhenAll(
page2.GoToAsync(TestConstants.EmptyPage));
var (cookies1, cookies2) = await TaskUtils.WhenAll(Context.GetCookiesAsync(), context2.GetCookiesAsync());
- Assert.Single(cookies1);
- Assert.Equal("persistent", cookies1.First().Name);
- Assert.Equal("persistent-value", cookies1.First().Value);
- Assert.Empty(cookies2);
+ Assert.That(cookies1, Has.Count.EqualTo(1));
+ Assert.That(cookies1.First().Name, Is.EqualTo("persistent"));
+ Assert.That(cookies1.First().Value, Is.EqualTo("persistent-value"));
+ Assert.That(cookies2, Is.Empty);
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should isolate send cookie header")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateSendCookieHeader()
{
string cookie = string.Empty;
@@ -181,16 +173,16 @@ await Context.AddCookiesAsync(new Cookie
var page = await Context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/empty.html");
- Assert.Equal("sendcookie=value", cookie);
+ Assert.That(cookie, Is.EqualTo("sendcookie=value"));
var context = await Browser.NewContextAsync();
page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.EmptyPage);
- Assert.Empty(cookie);
+ Assert.That(cookie, Is.Empty);
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should isolate cookies between launches")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateCookiesBetweenLaunches()
{
await using (var browser1 = await Playwright[TestConstants.Product].LaunchDefaultAsync())
@@ -210,12 +202,12 @@ await Context.AddCookiesAsync(new Cookie
{
var context1 = await Browser.NewContextAsync();
var cookies = await context1.GetCookiesAsync();
- Assert.Empty(cookies);
+ Assert.That(cookies, Is.Empty);
}
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set multiple cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSetMultipleCookies()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -235,21 +227,18 @@ await Context.AddCookiesAsync(
}
);
- Assert.Equal(
- new[]
+ Assert.That(await Page.EvaluateAsync(@"() => {
+ const cookies = document.cookie.split(';');
+ return cookies.map(cookie => cookie.trim()).sort();
+ }"), Is.EqualTo(new[]
{
"multiple-1=123456",
"multiple-2=bar"
- },
- await Page.EvaluateAsync(@"() => {
- const cookies = document.cookie.split(';');
- return cookies.map(cookie => cookie.trim()).sort();
- }")
- );
+ }));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should have |expires| set to |-1| for session cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldHaveExpiresSetToMinus1ForSessionCookies()
{
await Context.AddCookiesAsync(new Cookie
@@ -261,11 +250,11 @@ await Context.AddCookiesAsync(new Cookie
var cookies = await Context.GetCookiesAsync();
- Assert.Equal(-1, cookies.ElementAt(0).Expires);
+ Assert.That(cookies.ElementAt(0).Expires, Is.EqualTo(-1));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set cookie with reasonable defaults")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSetCookieWithReasonableDefaults()
{
await Context.AddCookiesAsync(new Cookie
@@ -275,19 +264,20 @@ await Context.AddCookiesAsync(new Cookie
Value = "123456"
});
- var cookie = Assert.Single(await Context.GetCookiesAsync());
- Assert.Equal("defaults", cookie.Name);
- Assert.Equal("123456", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(-1, cookie.Expires);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(await Context.GetCookiesAsync(), Has.Count.EqualTo(1));
+ var cookie = (await Context.GetCookiesAsync()).Single();
+ Assert.That(cookie.Name, Is.EqualTo("defaults"));
+ Assert.That(cookie.Value, Is.EqualTo("123456"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(cookie.Expires, Is.EqualTo(-1));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set a cookie with a path")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSetACookieWithAPath()
{
await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
@@ -298,30 +288,31 @@ await Context.AddCookiesAsync(new Cookie
Name = "gridcookie",
Value = "GRID"
});
- var cookie = Assert.Single(await Context.GetCookiesAsync());
- Assert.Equal("gridcookie", cookie.Name);
- Assert.Equal("GRID", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/grid.html", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
-
- Assert.Equal("gridcookie=GRID", await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Context.GetCookiesAsync(), Has.Count.EqualTo(1));
+ var cookie = (await Context.GetCookiesAsync()).Single();
+ Assert.That(cookie.Name, Is.EqualTo("gridcookie"));
+ Assert.That(cookie.Value, Is.EqualTo("GRID"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/grid.html"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
+
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.EqualTo("gridcookie=GRID"));
await Page.GoToAsync(TestConstants.EmptyPage);
- Assert.Empty(await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.Empty);
await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
- Assert.Equal("gridcookie=GRID", await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.EqualTo("gridcookie=GRID"));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should not set a cookie with blank page URL")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotSetACookieWithBlankPageURL()
{
await Page.GoToAsync(TestConstants.AboutBlank);
- var exception = await Assert.ThrowsAsync(async ()
+ var exception = Assert.ThrowsAsync(async ()
=> await Context.AddCookiesAsync(
new Cookie
{
@@ -335,15 +326,15 @@ public async Task ShouldNotSetACookieWithBlankPageURL()
Name = "example-cookie-blank",
Value = "best"
}));
- Assert.Equal("Blank page can not have cookie \"example-cookie-blank\"", exception.Message);
+ Assert.That(exception.Message, Is.EqualTo("Blank page can not have cookie \"example-cookie-blank\""));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should not set a cookie on a data URL page")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotSetACookieOnADataURLPage()
{
await Page.GoToAsync("data:,Hello%2C%20World!");
- var exception = await Assert.ThrowsAnyAsync(async ()
+ var exception = Assert.CatchAsync(async ()
=> await Context.AddCookiesAsync(
new Cookie
{
@@ -352,11 +343,11 @@ public async Task ShouldNotSetACookieOnADataURLPage()
Value = "best"
}));
- Assert.Equal("Data URL page can not have cookie \"example-cookie\"", exception.Message);
+ Assert.That(exception.Message, Is.EqualTo("Data URL page can not have cookie \"example-cookie\""));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should default to setting secure cookie for HTTPS websites")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldDefaultToSettingSecureCookieForHttpsWebsites()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -368,12 +359,13 @@ await Context.AddCookiesAsync(new Cookie
Name = "foo",
Value = "bar"
});
- var cookie = Assert.Single(await Context.GetCookiesAsync(secureUrl));
- Assert.True(cookie.Secure);
+ Assert.That(await Context.GetCookiesAsync(secureUrl), Has.Count.EqualTo(1));
+ var cookie = (await Context.GetCookiesAsync(secureUrl)).Single();
+ Assert.That(cookie.Secure, Is.True);
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should be able to set unsecure cookie for HTTP website")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBeAbleToSetUnsecureCookieForHttpWebSite()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -385,30 +377,32 @@ await Context.AddCookiesAsync(new Cookie
Name = "foo",
Value = "bar"
});
- var cookie = Assert.Single(await Context.GetCookiesAsync(SecureUrl));
- Assert.False(cookie.Secure);
+ Assert.That(await Context.GetCookiesAsync(SecureUrl), Has.Count.EqualTo(1));
+ var cookie = (await Context.GetCookiesAsync(SecureUrl)).Single();
+ Assert.That(cookie.Secure, Is.False);
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set a cookie on a different domain")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSetACookieOnADifferentDomain()
{
await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
await Context.AddCookiesAsync(new Cookie { Name = "example-cookie", Value = "best", Url = "https://www.example.com" });
- Assert.Equal(string.Empty, await Page.EvaluateAsync("document.cookie"));
- var cookie = Assert.Single(await Context.GetCookiesAsync("https://www.example.com"));
- Assert.Equal("example-cookie", cookie.Name);
- Assert.Equal("best", cookie.Value);
- Assert.Equal("www.example.com", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.True(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.EqualTo(string.Empty));
+ Assert.That(await Context.GetCookiesAsync("https://www.example.com"), Has.Count.EqualTo(1));
+ var cookie = (await Context.GetCookiesAsync("https://www.example.com")).Single();
+ Assert.That(cookie.Name, Is.EqualTo("example-cookie"));
+ Assert.That(cookie.Value, Is.EqualTo("best"));
+ Assert.That(cookie.Domain, Is.EqualTo("www.example.com"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.True);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set cookies for a frame")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldSetCookiesForAFrame()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -430,11 +424,11 @@ await Page.EvaluateAsync(@"src => {
return promise;
}", TestConstants.ServerUrl + "/grid.html");
- Assert.Equal("frame-cookie=value", await Page.FirstChildFrame().EvaluateAsync("document.cookie"));
+ Assert.That(await Page.FirstChildFrame().EvaluateAsync("document.cookie"), Is.EqualTo("frame-cookie=value"));
}
[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should(not) block third party cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotBlockThirdPartyCookies()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -456,20 +450,20 @@ await Page.EvaluateAsync(@"src => {
if (allowsThirdPart)
{
- Assert.Single(cookies);
+ Assert.That(cookies, Has.Count.EqualTo(1));
var cookie = cookies.First();
- Assert.Equal("127.0.0.1", cookie.Domain);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.Equal("username", cookie.Name);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
- Assert.False(cookie.Secure);
- Assert.Equal("John Doe", cookie.Value);
+ Assert.That(cookie.Domain, Is.EqualTo("127.0.0.1"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Name, Is.EqualTo("username"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.Value, Is.EqualTo("John Doe"));
}
else
{
- Assert.Empty(cookies);
+ Assert.That(cookies, Is.Empty);
}
}
}
diff --git a/src/Playwright.Tests/BrowserContextBasicTests.cs b/src/Playwright.Tests/BrowserContextBasicTests.cs
index b5baf835d7..a7e757b671 100644
--- a/src/Playwright.Tests/BrowserContextBasicTests.cs
+++ b/src/Playwright.Tests/BrowserContextBasicTests.cs
@@ -3,39 +3,31 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.Attributes;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextBasicTests : PlaywrightSharpBrowserBaseTest
- {
- ///
- public BrowserContextBasicTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-basic.spec.ts", "should create new context")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-basic.spec.ts", "should create new context")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldCreateNewContext()
{
await using var browser = await BrowserType.LaunchDefaultAsync();
- Assert.Empty(browser.Contexts);
+ Assert.That(browser.Contexts, Is.Empty);
await using var context = await browser.NewContextAsync();
- Assert.Single(browser.Contexts);
- Assert.Contains(context, browser.Contexts);
- Assert.Same(browser, context.Browser);
+ Assert.That(browser.Contexts, Has.Count.EqualTo(1));
+ Assert.That(browser.Contexts, Does.Contain(context));
+ Assert.That(context.Browser, Is.SameAs(browser));
await context.CloseAsync();
- Assert.Empty(browser.Contexts);
- Assert.Same(browser, context.Browser);
+ Assert.That(browser.Contexts, Is.Empty);
+ Assert.That(context.Browser, Is.SameAs(browser));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "window.open should use parent tab context")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task WindowOpenShouldUseParentTabContext()
{
await using var context = await Browser.NewContextAsync();
@@ -49,20 +41,20 @@ public async Task WindowOpenShouldUseParentTabContext()
page.EvaluateAsync("url => window.open(url)", TestConstants.EmptyPage)
);
- Assert.Same(context, popupTarget.Context);
+ Assert.That(popupTarget.Context, Is.SameAs(context));
await context.CloseAsync();
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should isolate localStorage and cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateLocalStorageAndCookies()
{
// Create two incognito contexts.
await using var browser = await BrowserType.LaunchDefaultAsync();
var context1 = await browser.NewContextAsync();
var context2 = await browser.NewContextAsync();
- Assert.Empty(context1.Pages);
- Assert.Empty(context2.Pages);
+ Assert.That(context1.Pages, Is.Empty);
+ Assert.That(context2.Pages, Is.Empty);
// Create a page in first incognito context.
var page1 = await context1.NewPageAsync();
@@ -72,8 +64,8 @@ await page1.EvaluateAsync(@"() => {
document.cookie = 'name=page1';
}");
- Assert.Single(context1.Pages);
- Assert.Empty(context2.Pages);
+ Assert.That(context1.Pages, Has.Count.EqualTo(1));
+ Assert.That(context2.Pages, Is.Empty);
// Create a page in second incognito context.
var page2 = await context2.NewPageAsync();
@@ -83,24 +75,24 @@ await page2.EvaluateAsync(@"() => {
document.cookie = 'name=page2';
}");
- Assert.Single(context1.Pages);
- Assert.Equal(page1, context1.Pages.FirstOrDefault());
- Assert.Single(context2.Pages);
- Assert.Equal(page2, context2.Pages.FirstOrDefault());
+ Assert.That(context1.Pages, Has.Count.EqualTo(1));
+ Assert.That(context1.Pages.FirstOrDefault(), Is.EqualTo(page1));
+ Assert.That(context2.Pages, Has.Count.EqualTo(1));
+ Assert.That(context2.Pages.FirstOrDefault(), Is.EqualTo(page2));
// Make sure pages don't share localstorage or cookies.
- Assert.Equal("page1", await page1.EvaluateAsync("() => localStorage.getItem('name')"));
- Assert.Equal("name=page1", await page1.EvaluateAsync("() => document.cookie"));
- Assert.Equal("page2", await page2.EvaluateAsync("() => localStorage.getItem('name')"));
- Assert.Equal("name=page2", await page2.EvaluateAsync("() => document.cookie"));
+ Assert.That(await page1.EvaluateAsync("() => localStorage.getItem('name')"), Is.EqualTo("page1"));
+ Assert.That(await page1.EvaluateAsync("() => document.cookie"), Is.EqualTo("name=page1"));
+ Assert.That(await page2.EvaluateAsync("() => localStorage.getItem('name')"), Is.EqualTo("page2"));
+ Assert.That(await page2.EvaluateAsync("() => document.cookie"), Is.EqualTo("name=page2"));
// Cleanup contexts.
await TaskUtils.WhenAll(context1.CloseAsync(), context2.CloseAsync());
- Assert.Empty(browser.Contexts);
+ Assert.That(browser.Contexts, Is.Empty);
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should propagate default viewport to the page")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldPropagateDefaultViewportToThePage()
{
await using var context = await Browser.NewContextAsync(new BrowserContextOptions
@@ -117,7 +109,7 @@ public async Task ShouldPropagateDefaultViewportToThePage()
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should make a copy of default viewport")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldMakeACopyOfDefaultViewport()
{
var viewport = new ViewportSize
@@ -136,7 +128,7 @@ public async Task ShouldMakeACopyOfDefaultViewport()
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should respect deviceScaleFactor")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldRespectDeviceScaleFactor()
{
await using var context = await Browser.NewContextAsync(new BrowserContextOptions
@@ -145,35 +137,35 @@ public async Task ShouldRespectDeviceScaleFactor()
});
var page = await context.NewPageAsync();
- Assert.Equal(3, await page.EvaluateAsync("window.devicePixelRatio"));
+ Assert.That(await page.EvaluateAsync("window.devicePixelRatio"), Is.EqualTo(3));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should not allow deviceScaleFactor with null viewport")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotAllowDeviceScaleFactorWithViewportDisabled()
{
- var exception = await Assert.ThrowsAsync(() => Browser.NewContextAsync(new BrowserContextOptions
+ var exception = Assert.ThrowsAsync(() => Browser.NewContextAsync(new BrowserContextOptions
{
Viewport = ViewportSize.NoViewport,
DeviceScaleFactor = 3,
}));
- Assert.Equal("\"deviceScaleFactor\" option is not supported with null \"viewport\"", exception.Message);
+ Assert.That(exception.Message, Is.EqualTo("\"deviceScaleFactor\" option is not supported with null \"viewport\""));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should not allow isMobile with null viewport")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotAllowIsMobileWithViewportDisabled()
{
- var exception = await Assert.ThrowsAsync(() => Browser.NewContextAsync(new BrowserContextOptions
+ var exception = Assert.ThrowsAsync(() => Browser.NewContextAsync(new BrowserContextOptions
{
Viewport = ViewportSize.NoViewport,
IsMobile = true,
}));
- Assert.Equal("\"isMobile\" option is not supported with null \"viewport\"", exception.Message);
+ Assert.That(exception.Message, Is.EqualTo("\"isMobile\" option is not supported with null \"viewport\""));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "close() should work for empty context")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task CloseShouldWorkForEmptyContext()
{
var context = await Browser.NewContextAsync();
@@ -181,18 +173,18 @@ public async Task CloseShouldWorkForEmptyContext()
}
[PlaywrightTest("browsercontext-basic.spec.ts", "close() should abort waitForEvent")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task CloseShouldAbortWaitForEvent()
{
var context = await Browser.NewContextAsync();
var waitTask = context.WaitForEventAsync(ContextEvent.Page);
await context.CloseAsync();
- var exception = await Assert.ThrowsAsync(() => waitTask);
- Assert.Equal("Context closed", exception.Message);
+ var exception = Assert.ThrowsAsync(() => waitTask);
+ Assert.That(exception.Message, Is.EqualTo("Context closed"));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should not report frameless pages on error")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldNotReportFramelessPagesOnError()
{
var context = await Browser.NewContextAsync();
@@ -211,13 +203,13 @@ public async Task ShouldNotReportFramelessPagesOnError()
if (popup != null)
{
- Assert.True(popup.IsClosed);
- Assert.NotNull(popup.MainFrame);
+ Assert.That(popup.IsClosed, Is.True);
+ Assert.That(popup.MainFrame, Is.Not.Null);
}
}
[PlaywrightTest("browsercontext-basic.spec.ts", "close() should be callable twice")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task CloseShouldBeCallableTwice()
{
var context = await Browser.NewContextAsync();
@@ -226,34 +218,34 @@ public async Task CloseShouldBeCallableTwice()
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should return all of the pages")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldReturnAllOfThePages()
{
await using var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();
var second = await context.NewPageAsync();
- Assert.Equal(2, context.Pages.Count);
- Assert.Contains(page, context.Pages);
- Assert.Contains(second, context.Pages);
+ Assert.That(context.Pages.Count, Is.EqualTo(2));
+ Assert.That(context.Pages, Does.Contain(page));
+ Assert.That(context.Pages, Does.Contain(second));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "BrowserContext.pages()", "should close all belonging pages once closing context")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldCloseAllBelongingPagesOnceClosingContext()
{
await using var context = await Browser.NewContextAsync();
await context.NewPageAsync();
- Assert.Single(context.Pages);
+ Assert.That(context.Pages, Has.Count.EqualTo(1));
await context.CloseAsync();
- Assert.Empty(context.Pages);
+ Assert.That(context.Pages, Is.Empty);
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should disable javascript")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldDisableJavascript()
{
await using (var context = await Browser.NewContextAsync(javaScriptEnabled: false))
@@ -261,23 +253,21 @@ public async Task ShouldDisableJavascript()
var page = await context.NewPageAsync();
await page.GoToAsync("data:text/html, ");
- var exception = await Assert.ThrowsAnyAsync(async () => await page.EvaluateAsync("something"));
+ var exception = Assert.CatchAsync(async () => await page.EvaluateAsync("something"));
- Assert.Contains(
- TestConstants.IsWebKit ? "Can\'t find variable: something" : "something is not defined",
- exception.Message);
+ Assert.That(exception.Message, Does.Contain(TestConstants.IsWebKit ? "Can\'t find variable: something" : "something is not defined"));
}
await using (var context = await Browser.NewContextAsync())
{
var page = await context.NewPageAsync();
await page.GoToAsync("data:text/html, ");
- Assert.Equal("forbidden", await page.EvaluateAsync("something"));
+ Assert.That(await page.EvaluateAsync("something"), Is.EqualTo("forbidden"));
}
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should be able to navigate after disabling javascript")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBeAbleToNavigateAfterDisablingJavascript()
{
await using var context = await Browser.NewContextAsync(javaScriptEnabled: false);
@@ -286,15 +276,15 @@ public async Task ShouldBeAbleToNavigateAfterDisablingJavascript()
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should work with offline option")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWorkWithOfflineOption()
{
await using var context = await Browser.NewContextAsync(new BrowserContextOptions { Offline = true });
var page = await context.NewPageAsync();
- await Assert.ThrowsAsync(() => page.GoToAsync(TestConstants.EmptyPage));
+ Assert.ThrowsAsync(() => page.GoToAsync(TestConstants.EmptyPage));
await context.SetOfflineAsync(false);
var response = await page.GoToAsync(TestConstants.EmptyPage);
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
[PlaywrightTest("browsercontext-basic.spec.ts", "should emulate navigator.onLine")]
@@ -303,11 +293,11 @@ public async Task ShouldEmulateNavigatorOnLine()
{
await using var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();
- Assert.True(await page.EvaluateAsync("() => window.navigator.onLine"));
+ Assert.That(await page.EvaluateAsync("() => window.navigator.onLine"), Is.True);
await context.SetOfflineAsync(true);
- Assert.False(await page.EvaluateAsync("() => window.navigator.onLine"));
+ Assert.That(await page.EvaluateAsync("() => window.navigator.onLine"), Is.False);
await context.SetOfflineAsync(false);
- Assert.True(await page.EvaluateAsync("() => window.navigator.onLine"));
+ Assert.That(await page.EvaluateAsync("() => window.navigator.onLine"), Is.True);
}
}
}
diff --git a/src/Playwright.Tests/BrowserContextCSPTests.cs b/src/Playwright.Tests/BrowserContextCSPTests.cs
index 7d4c8de8ca..ebab151355 100644
--- a/src/Playwright.Tests/BrowserContextCSPTests.cs
+++ b/src/Playwright.Tests/BrowserContextCSPTests.cs
@@ -1,21 +1,13 @@
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextCSPTests : PlaywrightSharpBrowserBaseTest
- {
- ///
- public BrowserContextCSPTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-csp.spec.ts", "should bypass CSP meta tag")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-csp.spec.ts", "should bypass CSP meta tag")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBypassCSPMetatag()
{
// Make sure CSP prohibits addScriptTag.
@@ -24,7 +16,7 @@ public async Task ShouldBypassCSPMetatag()
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/csp.html");
await page.AddScriptTagAsync(content: "window.__injected = 42;").ContinueWith(_ => Task.CompletedTask);
- Assert.Null(await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.Null);
}
// By-pass CSP and try one more time.
await using (var context = await Browser.NewContextAsync(bypassCSP: true))
@@ -32,12 +24,12 @@ public async Task ShouldBypassCSPMetatag()
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/csp.html");
await page.AddScriptTagAsync(content: "window.__injected = 42;");
- Assert.Equal(42, await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.EqualTo(42));
}
}
[PlaywrightTest("browsercontext-csp.spec.ts", "should bypass CSP header")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBypassCSPHeader()
{
// Make sure CSP prohibits addScriptTag.
@@ -48,7 +40,7 @@ public async Task ShouldBypassCSPHeader()
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.EmptyPage);
await page.AddScriptTagAsync(content: "window.__injected = 42;").ContinueWith(_ => Task.CompletedTask);
- Assert.Null(await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.Null);
}
// By-pass CSP and try one more time.
@@ -57,27 +49,27 @@ public async Task ShouldBypassCSPHeader()
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.EmptyPage);
await page.AddScriptTagAsync(content: "window.__injected = 42;");
- Assert.Equal(42, await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.EqualTo(42));
}
}
[PlaywrightTest("browsercontext-csp.spec.ts", "should bypass after cross-process navigation")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBypassAfterCrossProcessNavigation()
{
await using var context = await Browser.NewContextAsync(bypassCSP: true);
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/csp.html");
await page.AddScriptTagAsync(content: "window.__injected = 42;");
- Assert.Equal(42, await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.EqualTo(42));
await page.GoToAsync(TestConstants.CrossProcessUrl + "/csp.html");
await page.AddScriptTagAsync(content: "window.__injected = 42;");
- Assert.Equal(42, await page.EvaluateAsync("window.__injected"));
+ Assert.That(await page.EvaluateAsync("window.__injected"), Is.EqualTo(42));
}
[PlaywrightTest("browsercontext-csp.spec.ts", "should bypass CSP in iframes as well")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBypassCSPInIframesAsWell()
{
await using (var context = await Browser.NewContextAsync())
@@ -88,7 +80,7 @@ public async Task ShouldBypassCSPInIframesAsWell()
// Make sure CSP prohibits addScriptTag in an iframe.
var frame = await FrameUtils.AttachFrameAsync(page, "frame1", TestConstants.ServerUrl + "/csp.html");
await frame.AddScriptTagAsync(content: "window.__injected = 42;").ContinueWith(_ => Task.CompletedTask);
- Assert.Null(await frame.EvaluateAsync("() => window.__injected"));
+ Assert.That(await frame.EvaluateAsync("() => window.__injected"), Is.Null);
}
// By-pass CSP and try one more time.
@@ -100,7 +92,7 @@ public async Task ShouldBypassCSPInIframesAsWell()
// Make sure CSP prohibits addScriptTag in an iframe.
var frame = await FrameUtils.AttachFrameAsync(page, "frame1", TestConstants.ServerUrl + "/csp.html");
await frame.AddScriptTagAsync(content: "window.__injected = 42;").ContinueWith(_ => Task.CompletedTask);
- Assert.Equal(42, await frame.EvaluateAsync("() => window.__injected"));
+ Assert.That(await frame.EvaluateAsync("() => window.__injected"), Is.EqualTo(42));
}
}
diff --git a/src/Playwright.Tests/BrowserContextClearCookiesTests.cs b/src/Playwright.Tests/BrowserContextClearCookiesTests.cs
index 840ae93b8f..6bbd628b55 100644
--- a/src/Playwright.Tests/BrowserContextClearCookiesTests.cs
+++ b/src/Playwright.Tests/BrowserContextClearCookiesTests.cs
@@ -1,21 +1,13 @@
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextClearCookiesTests : PlaywrightSharpPageBaseTest
- {
- ///
- public BrowserContextClearCookiesTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-clearcookies.spec.ts", "should clear cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-clearcookies.spec.ts", "should clear cookies")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldClearCookes()
{
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -25,15 +17,15 @@ await Context.AddCookiesAsync(new Cookie
Name = "cookie1",
Value = "1"
});
- Assert.Equal("cookie1=1", await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.EqualTo("cookie1=1"));
await Context.ClearCookiesAsync();
- Assert.Empty(await Context.GetCookiesAsync());
+ Assert.That(await Context.GetCookiesAsync(), Is.Empty);
await Page.ReloadAsync();
- Assert.Empty(await Page.EvaluateAsync("document.cookie"));
+ Assert.That(await Page.EvaluateAsync("document.cookie"), Is.Empty);
}
[PlaywrightTest("browsercontext-clearcookies.spec.ts", "should isolate cookies when clearing")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldIsolateWhenClearing()
{
await using var anotherContext = await Browser.NewContextAsync();
@@ -51,16 +43,16 @@ await anotherContext.AddCookiesAsync(new Cookie
Url = TestConstants.EmptyPage
});
- Assert.Single(await Context.GetCookiesAsync());
- Assert.Single(await anotherContext.GetCookiesAsync());
+ Assert.That(await Context.GetCookiesAsync(), Has.Count.EqualTo(1));
+ Assert.That(await anotherContext.GetCookiesAsync(), Has.Count.EqualTo(1));
await Context.ClearCookiesAsync();
- Assert.Empty((await Context.GetCookiesAsync()));
- Assert.Single((await anotherContext.GetCookiesAsync()));
+ Assert.That((await Context.GetCookiesAsync()), Is.Empty);
+ Assert.That((await anotherContext.GetCookiesAsync()), Has.Count.EqualTo(1));
await anotherContext.ClearCookiesAsync();
- Assert.Empty(await Context.GetCookiesAsync());
- Assert.Empty(await anotherContext.GetCookiesAsync());
+ Assert.That(await Context.GetCookiesAsync(), Is.Empty);
+ Assert.That(await anotherContext.GetCookiesAsync(), Is.Empty);
}
}
}
diff --git a/src/Playwright.Tests/BrowserContextCookiesTests.cs b/src/Playwright.Tests/BrowserContextCookiesTests.cs
index 4567322665..4ed6e6e68a 100644
--- a/src/Playwright.Tests/BrowserContextCookiesTests.cs
+++ b/src/Playwright.Tests/BrowserContextCookiesTests.cs
@@ -1,73 +1,65 @@
using System;
using System.Linq;
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.Attributes;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextCookiesTests : PlaywrightSharpPageBaseTest
- {
- ///
- public BrowserContextCookiesTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-cookies.spec.ts", "should return no cookies in pristine browser context")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-cookies.spec.ts", "should return no cookies in pristine browser context")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldReturnNoCookiesInPristineBrowserContext()
- => Assert.Empty(await Context.GetCookiesAsync());
+ => Assert.That(await Context.GetCookiesAsync(), Is.Empty);
[PlaywrightTest("browsercontext-cookies.spec.ts", "should get a cookie")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldGetACookie()
{
await Page.GoToAsync(TestConstants.EmptyPage);
- Assert.Equal("username=John Doe", await Page.EvaluateAsync(@"() => {
+ Assert.That(await Page.EvaluateAsync(@"() => {
document.cookie = 'username=John Doe';
return document.cookie;
- }"));
+ }"), Is.EqualTo("username=John Doe"));
var cookie = (await Page.Context.GetCookiesAsync()).Single();
- Assert.Equal("username", cookie.Name);
- Assert.Equal("John Doe", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(-1, cookie.Expires);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("username"));
+ Assert.That(cookie.Value, Is.EqualTo("John Doe"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(cookie.Expires, Is.EqualTo(-1));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
[PlaywrightTest("browsercontext-cookies.spec.ts", "should get a non-session cookie")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldGetANonSessionCookie()
{
await Page.GoToAsync(TestConstants.EmptyPage);
var date = new DateTime(2038, 1, 1);
- Assert.Equal("username=John Doe", await Page.EvaluateAsync(@"timestamp => {
+ Assert.That(await Page.EvaluateAsync(@"timestamp => {
const date = new Date(timestamp);
document.cookie = `username=John Doe;expires=${date.toUTCString()}`;
return document.cookie;
- }", date));
+ }", date), Is.EqualTo("username=John Doe"));
var cookie = (await Page.Context.GetCookiesAsync()).Single();
- Assert.Equal("username", cookie.Name);
- Assert.Equal("John Doe", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(new DateTimeOffset(date).ToUnixTimeSeconds(), cookie.Expires);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("username"));
+ Assert.That(cookie.Value, Is.EqualTo("John Doe"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(cookie.Expires, Is.EqualTo(new DateTimeOffset(date).ToUnixTimeSeconds()));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
[PlaywrightTest("browsercontext-cookies.spec.ts", "should properly report httpOnly cookie")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldProperlyReportHttpOnlyCookie()
{
Server.SetRoute("/empty.html", context =>
@@ -77,8 +69,8 @@ public async Task ShouldProperlyReportHttpOnlyCookie()
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Context.GetCookiesAsync();
- Assert.Single(cookies);
- Assert.True(cookies.ElementAt(0).HttpOnly);
+ Assert.That(cookies, Has.Count.EqualTo(1));
+ Assert.That(cookies.ElementAt(0).HttpOnly, Is.True);
}
[PlaywrightTest("browsercontext-cookies.spec.ts", @"should properly report ""Strict"" sameSite cookie")]
@@ -92,8 +84,8 @@ public async Task ShouldProperlyReportStrictSameSiteCookie()
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Context.GetCookiesAsync();
- Assert.Single(cookies);
- Assert.Equal(SameSiteAttribute.Strict, cookies.ElementAt(0).SameSite);
+ Assert.That(cookies, Has.Count.EqualTo(1));
+ Assert.That(cookies.ElementAt(0).SameSite, Is.EqualTo(SameSiteAttribute.Strict));
}
[PlaywrightTest("browsercontext-cookies.spec.ts", @"should properly report ""Lax"" sameSite cookie")]
@@ -107,16 +99,16 @@ public async Task ShouldProperlyReportLaxSameSiteCookie()
});
await Page.GoToAsync(TestConstants.EmptyPage);
var cookies = await Context.GetCookiesAsync();
- Assert.Single(cookies);
- Assert.Equal(SameSiteAttribute.Lax, cookies.ElementAt(0).SameSite);
+ Assert.That(cookies, Has.Count.EqualTo(1));
+ Assert.That(cookies.ElementAt(0).SameSite, Is.EqualTo(SameSiteAttribute.Lax));
}
[PlaywrightTest("browsercontext-cookies.spec.ts", "should get multiple cookies")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldGetMultipleCookies()
{
await Page.GoToAsync(TestConstants.EmptyPage);
- Assert.Empty(await Context.GetCookiesAsync());
+ Assert.That(await Context.GetCookiesAsync(), Is.Empty);
string documentCookie = await Page.EvaluateAsync(@"() => {
document.cookie = 'username=John Doe';
@@ -125,30 +117,30 @@ public async Task ShouldGetMultipleCookies()
}");
var cookies = (await Context.GetCookiesAsync()).OrderBy(c => c.Name).ToList();
- Assert.Equal("password=1234; username=John Doe", documentCookie);
+ Assert.That(documentCookie, Is.EqualTo("password=1234; username=John Doe"));
var cookie = cookies[0];
- Assert.Equal("password", cookie.Name);
- Assert.Equal("1234", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("password"));
+ Assert.That(cookie.Value, Is.EqualTo("1234"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
cookie = cookies[1];
- Assert.Equal("username", cookie.Name);
- Assert.Equal("John Doe", cookie.Value);
- Assert.Equal("localhost", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.False(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("username"));
+ Assert.That(cookie.Value, Is.EqualTo("John Doe"));
+ Assert.That(cookie.Domain, Is.EqualTo("localhost"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.False);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
[PlaywrightTest("browsercontext-cookies.spec.ts", "should get cookies from multiple urls")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldGetCookiesFromMultipleUrls()
{
await Context.AddCookiesAsync(
@@ -173,27 +165,27 @@ await Context.AddCookiesAsync(
);
var cookies = (await Context.GetCookiesAsync("https://foo.com", "https://baz.com")).OrderBy(c => c.Name).ToList();
- Assert.Equal(2, cookies.Count);
+ Assert.That(cookies.Count, Is.EqualTo(2));
var cookie = cookies[0];
- Assert.Equal("birdo", cookie.Name);
- Assert.Equal("tweets", cookie.Value);
- Assert.Equal("baz.com", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.True(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("birdo"));
+ Assert.That(cookie.Value, Is.EqualTo("tweets"));
+ Assert.That(cookie.Domain, Is.EqualTo("baz.com"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.True);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
cookie = cookies[1];
- Assert.Equal("doggo", cookie.Name);
- Assert.Equal("woofs", cookie.Value);
- Assert.Equal("foo.com", cookie.Domain);
- Assert.Equal("/", cookie.Path);
- Assert.Equal(cookie.Expires, -1);
- Assert.False(cookie.HttpOnly);
- Assert.True(cookie.Secure);
- Assert.Equal(SameSiteAttribute.None, cookie.SameSite);
+ Assert.That(cookie.Name, Is.EqualTo("doggo"));
+ Assert.That(cookie.Value, Is.EqualTo("woofs"));
+ Assert.That(cookie.Domain, Is.EqualTo("foo.com"));
+ Assert.That(cookie.Path, Is.EqualTo("/"));
+ Assert.That(-1, Is.EqualTo(cookie.Expires));
+ Assert.That(cookie.HttpOnly, Is.False);
+ Assert.That(cookie.Secure, Is.True);
+ Assert.That(cookie.SameSite, Is.EqualTo(SameSiteAttribute.None));
}
}
}
diff --git a/src/Playwright.Tests/BrowserContextDeviceTests.cs b/src/Playwright.Tests/BrowserContextDeviceTests.cs
index 1b02c0b0e0..11146410c7 100644
--- a/src/Playwright.Tests/BrowserContextDeviceTests.cs
+++ b/src/Playwright.Tests/BrowserContextDeviceTests.cs
@@ -1,23 +1,14 @@
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.Attributes;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextDeviceTests : PlaywrightSharpBrowserBaseTest
{
- private readonly BrowserContextOptions _iPhone = TestConstants.iPhone6;
-
- ///
- public BrowserContextDeviceTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-device.spec.ts", "should work")]
+ private readonly BrowserContextOptions _iPhone = TestConstants.iPhone6; [PlaywrightTest("browsercontext-device.spec.ts", "should work")]
[SkipBrowserAndPlatformFact(skipFirefox: true)]
public async Task ShouldWork()
{
@@ -25,8 +16,8 @@ public async Task ShouldWork()
var page = await context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/mobile.html");
- Assert.Equal(375, await page.EvaluateAsync("window.innerWidth"));
- Assert.Contains("iPhone", await page.EvaluateAsync("navigator.userAgent"));
+ Assert.That(await page.EvaluateAsync("window.innerWidth"), Is.EqualTo(375));
+ Assert.That(await page.EvaluateAsync("navigator.userAgent"), Does.Contain("iPhone"));
}
[PlaywrightTest("browsercontext-device.spec.ts", "should support clicking")]
@@ -40,7 +31,7 @@ public async Task ShouldSupportClicking()
var button = await page.QuerySelectorAsync("button");
await button.EvaluateAsync("button => button.style.marginTop = '200px'", button);
await button.ClickAsync();
- Assert.Equal("Clicked", await page.EvaluateAsync("() => result"));
+ Assert.That(await page.EvaluateAsync("() => result"), Is.EqualTo("Clicked"));
}
[PlaywrightTest("browsercontext-device.spec.ts", "should scroll to click")]
@@ -62,7 +53,7 @@ public async Task ShouldScrollToClick()
await page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");
var element = await page.QuerySelectorAsync("#button-91");
await element.ClickAsync();
- Assert.Equal("clicked", await element.TextContentAsync());
+ Assert.That(await element.TextContentAsync(), Is.EqualTo("clicked"));
}
}
}
diff --git a/src/Playwright.Tests/BrowserContextExposeFunctionTests.cs b/src/Playwright.Tests/BrowserContextExposeFunctionTests.cs
index 810e7b4474..ff65677d4d 100644
--- a/src/Playwright.Tests/BrowserContextExposeFunctionTests.cs
+++ b/src/Playwright.Tests/BrowserContextExposeFunctionTests.cs
@@ -1,23 +1,15 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
-using Microsoft.Playwright.Testing.Xunit;
+using Microsoft.Playwright.Nunit;
using Microsoft.Playwright.Tests.BaseTests;
-using Xunit;
-using Xunit.Abstractions;
+using NUnit.Framework;
namespace Microsoft.Playwright.Tests
{
- [Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContextExposeFunctionTests : PlaywrightSharpBrowserContextBaseTest
- {
- ///
- public BrowserContextExposeFunctionTests(ITestOutputHelper output) : base(output)
- {
- }
-
- [PlaywrightTest("browsercontext-expose-function.spec.ts", "expose binding should work")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ { [PlaywrightTest("browsercontext-expose-function.spec.ts", "expose binding should work")]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ExposeBindingShouldWork()
{
BindingSource bindingSource = null;
@@ -33,15 +25,15 @@ await Context.ExposeBindingAsync("add", (BindingSource source, int a, int b) =>
return await add(5, 6);
}");
- Assert.Same(Context, bindingSource.Context);
- Assert.Same(page, bindingSource.Page);
- Assert.Same(page.MainFrame, bindingSource.Frame);
+ Assert.That(bindingSource.Context, Is.SameAs(Context));
+ Assert.That(bindingSource.Page, Is.SameAs(page));
+ Assert.That(bindingSource.Frame, Is.SameAs(page.MainFrame));
- Assert.Equal(11, result);
+ Assert.That(result, Is.EqualTo(11));
}
[PlaywrightTest("browsercontext-expose-function.spec.ts", "should work")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWork()
{
await Context.ExposeFunctionAsync("add", (int a, int b) => a + b);
@@ -53,32 +45,32 @@ public async Task ShouldWork()
var result = await page.EvaluateAsync(@"async function() {
return { mul: await mul(9, 4), add: await add(9, 4), sub: await sub(9, 4) };
}");
- Assert.Equal(36, result.GetProperty("mul").GetInt32());
- Assert.Equal(13, result.GetProperty("add").GetInt32());
- Assert.Equal(5, result.GetProperty("sub").GetInt32());
+ Assert.That(result.GetProperty("mul").GetInt32(), Is.EqualTo(36));
+ Assert.That(result.GetProperty("add").GetInt32(), Is.EqualTo(13));
+ Assert.That(result.GetProperty("sub").GetInt32(), Is.EqualTo(5));
}
[PlaywrightTest("browsercontext-expose-function.spec.ts", "should throw for duplicate registrations")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldThrowForDuplicateRegistrations()
{
await Context.ExposeFunctionAsync("foo", () => { });
await Context.ExposeFunctionAsync("bar", () => { });
- var exception = await Assert.ThrowsAnyAsync(() => Context.ExposeFunctionAsync("foo", () => { }));
- Assert.Equal("Function \"foo\" has been already registered", exception.Message);
+ var exception = Assert.CatchAsync(() => Context.ExposeFunctionAsync("foo", () => { }));
+ Assert.That(exception.Message, Is.EqualTo("Function \"foo\" has been already registered"));
var page = await Context.NewPageAsync();
- exception = await Assert.ThrowsAnyAsync(() => page.ExposeFunctionAsync("foo", () => { }));
- Assert.Equal("Function \"foo\" has been already registered in the browser context", exception.Message);
+ exception = Assert.CatchAsync(() => page.ExposeFunctionAsync("foo", () => { }));
+ Assert.That(exception.Message, Is.EqualTo("Function \"foo\" has been already registered in the browser context"));
await page.ExposeFunctionAsync("baz", () => { });
- exception = await Assert.ThrowsAnyAsync(() => Context.ExposeFunctionAsync("baz", () => { }));
- Assert.Equal("Function \"baz\" has been already registered in one of the pages", exception.Message);
+ exception = Assert.CatchAsync(() => Context.ExposeFunctionAsync("baz", () => { }));
+ Assert.That(exception.Message, Is.EqualTo("Function \"baz\" has been already registered in one of the pages"));
}
[PlaywrightTest("browsercontext-expose-function.spec.ts", "should be callable from-inside addInitScript")]
- [Fact(Timeout = TestConstants.DefaultTestTimeout)]
+ [Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldBeCallableFromInsideAddInitScript()
{
var args = new List