Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/Playwright.Tests/Attributes/PlaywrightTestAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@

// Run all tests in sequence
[assembly: LevelOfParallelism(1)]
[assembly: Parallelizable(ParallelScope.Fixtures)]

namespace Microsoft.Playwright.Tests;

/// <summary>
/// Enables decorating test facts with information about the corresponding test in the upstream repository.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class PlaywrightTestAttribute : TestAttribute, IWrapSetUpTearDown
public class PlaywrightTestAttribute : TestAttribute, IApplyToContext, IApplyToTest, IWrapSetUpTearDown
{
private readonly CancelAfterAttribute _cancelAfterAttribute = new(TestConstants.DefaultTestTimeout);

public PlaywrightTestAttribute()
{
}
Expand All @@ -52,17 +55,6 @@ public PlaywrightTestAttribute(string fileName, string nameOfTest)
TestName = nameOfTest;
}

/// <summary>
/// Creates a new instance of the attribute.
/// </summary>
/// <param name="fileName"><see cref="FileName"/></param>
/// <param name="describe"><see cref="Describe"/></param>
/// <param name="nameOfTest"><see cref="TestName"/></param>
public PlaywrightTestAttribute(string fileName, string describe, string nameOfTest) : this(fileName, nameOfTest)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method with this kind of signature we haven't used much, hence removed + modified the tests which used it.

{
Describe = describe;
}

/// <summary>
/// The file name origin of the test.
/// </summary>
Expand All @@ -83,6 +75,22 @@ public PlaywrightTestAttribute(string fileName, string describe, string nameOfTe
/// </summary>
public string Describe { get; }

public void ApplyToContext(TestExecutionContext context)
{
if (context.TestCaseTimeout == 0)
{
(_cancelAfterAttribute as IApplyToContext).ApplyToContext(context);
}
}

public new void ApplyToTest(Test test)
{
base.ApplyToTest(test);
if (TestExecutionContext.CurrentContext.TestCaseTimeout == 0)
{
_cancelAfterAttribute.ApplyToTest(test);
}
}
/// <summary>
/// Wraps the current test command in a <see cref="UnobservedTaskExceptionCommand"/>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.Tests/BrowserContextBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public async Task ShouldReturnAllOfThePages()
CollectionAssert.Contains(context.Pages, second);
}

[PlaywrightTest("browsercontext-basic.spec.ts", "BrowserContext.pages()", "should close all belonging pages once closing context")]
[PlaywrightTest("browsercontext-basic.spec.ts", "should close all belonging pages once closing context")]
public async Task ShouldCloseAllBelongingPagesOnceClosingContext()
{
await using var context = await Browser.NewContextAsync();
Expand Down
6 changes: 3 additions & 3 deletions src/Playwright.Tests/ElementHandleConvenienceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task TextContentShouldWork()
Assert.AreEqual("Text,\nmore text", await Page.TextContentAsync("#outer"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "innerText should be atomic")]
[PlaywrightTest("elementhandle-convenience.spec.ts", "innerText should be atomic")]
public async Task InnerTextShouldBeAtomic()
{
const string createDummySelector = @"({
Expand All @@ -120,7 +120,7 @@ public async Task InnerTextShouldBeAtomic()
Assert.AreEqual("modified", await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "innerHTML should be atomic")]
[PlaywrightTest("elementhandle-convenience.spec.ts", "innerHTML should be atomic")]
public async Task InnerHtmlShouldBeAtomic()
{
const string createDummySelector = @"({
Expand All @@ -146,7 +146,7 @@ public async Task InnerHtmlShouldBeAtomic()
Assert.AreEqual("modified", await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "getAttribute should be atomic")]
[PlaywrightTest("elementhandle-convenience.spec.ts", "getAttribute should be atomic")]
public async Task GetAttributeShouldBeAtomic()
{
const string createDummySelector = @"({
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/PageDispatchEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async Task ShouldBeAtomic()
Assert.True(await Page.EvaluateAsync<bool>("() => window['_clicked']"));
}

[PlaywrightTest("page-dispatchevent.spec.ts", "Page.dispatchEvent(drag)", "should dispatch drag drop events")]
[PlaywrightTest("page-dispatchevent.spec.ts", "should dispatch drag drop events")]
[Skip(SkipAttribute.Targets.Webkit)]
public async Task ShouldDispatchDragDropEvents()
{
Expand All @@ -176,7 +176,7 @@ public async Task ShouldDispatchDragDropEvents()
}", new { source, target }));
}

[PlaywrightTest("page-dispatchevent.spec.ts", "Page.dispatchEvent(drag)", "should dispatch drag drop events")]
[PlaywrightTest("page-dispatchevent.spec.ts", "should dispatch drag drop events")]
[Skip(SkipAttribute.Targets.Webkit)]
public async Task ElementHandleShouldDispatchDragDropEvents()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Playwright.Tests/PageEvaluateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ private enum TestEnum
Test = 1
}

[PlaywrightTest(Description = "https://github.com/microsoft/playwright-dotnet/issues/1706")]
// See https://github.com/microsoft/playwright-dotnet/issues/1706
[PlaywrightTest]
public async Task ShouldNotReturnDisposedJsonElement()
{
var result = await Page.EvaluateAsync<JsonElement?>("()=> [{a:1,b:2},{a:1,b:2}]");
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.Tests/PageNetworkRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public async Task ShouldReturnNavigationBit()
Assert.False(requests["style.css"].IsNavigationRequest);
}

[PlaywrightTest("page-network-request.spec.ts", "Request.isNavigationRequest", "should return navigation bit when navigating to image")]
[PlaywrightTest("page-network-request.spec.ts", "should return navigation bit when navigating to image")]
public async Task ShouldReturnNavigationBitWhenNavigatingToImage()
{
var requests = new List<IRequest>();
Expand Down
3 changes: 1 addition & 2 deletions src/Playwright.Tests/PageWaitForNavigationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,14 @@ public async Task ShouldWorkOnFrame()
}

[PlaywrightTest]
[CancelAfter(45_000)]
[CancelAfter(TestConstants.SlowTestTimeout)]
public async Task ShouldHaveADefaultTimeout()
{
await Page.GotoAsync(Server.Prefix + "/frames/one-frame.html");
await PlaywrightAssert.ThrowsAsync<TimeoutException>(async () => await Page.RunAndWaitForNavigationAsync(() => Task.CompletedTask));
}

[PlaywrightTest]
[CancelAfter(5_000)]
public async Task ShouldTakeTimeoutIntoAccount()
{
await Page.GotoAsync(Server.Prefix + "/frames/one-frame.html");
Expand Down
1 change: 0 additions & 1 deletion src/Playwright.Tests/ScreencastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public async Task ShouldCaptureStaticPageInPersistentContext()


[PlaywrightTest("screencast.spec.ts", "video.path()/saveAs() does not hang immediately after launchPersistentContext and context.close()")]
[CancelAfter(30_000)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 is the default, hence removed.

public async Task VideoPathSaveAsDoesNotHangImmediatelyAfterLaunchPersistentContextAndContextClose()
{
using var userDirectory = new TempDirectory();
Expand Down
3 changes: 0 additions & 3 deletions src/Playwright.Tests/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

using System.Runtime.InteropServices;

[assembly: NUnit.Framework.Timeout(Microsoft.Playwright.Tests.TestConstants.DefaultTestTimeout)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First line removed, second line moved to the PlaywrightTestAttribute.cs.

[assembly: NUnit.Framework.Parallelizable(NUnit.Framework.ParallelScope.Fixtures)]

namespace Microsoft.Playwright.Tests;

internal static class TestConstants
Expand Down
Loading