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
11 changes: 11 additions & 0 deletions src/Playwright.Tests/PageCloseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ namespace Microsoft.Playwright.Tests;

public class PageCloseTests : PageTestEx
{
[PlaywrightTest("page-close.spec.ts", "should close the page using await using")]
public async Task ShouldClosePageWithAwaitUsing()
{
IPage closedPage;
await using (var page = await Context.NewPageAsync())
{
closedPage = page;
Assert.False(page.IsClosed);
}
Assert.True(closedPage.IsClosed);
}
}
2 changes: 1 addition & 1 deletion src/Playwright/API/Supplements/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace Microsoft.Playwright;

public partial interface IPage
public partial interface IPage : IAsyncDisposable
{
Task<JsonElement?> EvaluateAsync(string expression, object? arg = default);

Expand Down
3 changes: 3 additions & 0 deletions src/Playwright/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ internal async Task<T> InnerWaitForEventAsync<T>(PlaywrightEvent<T> pageEvent, F
return await waitForEventTask.ConfigureAwait(false);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public ValueTask DisposeAsync() => new(CloseAsync());

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task CloseAsync(PageCloseOptions? options = default)
{
Expand Down
Loading