Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params based AddCoogkies #1576

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 deletions src/Playwright.Tests/BrowserContextAddCookiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ public async Task ShouldWork()
Assert.AreEqual("password=123456", await Page.EvaluateAsync<string>("document.cookie"));
}

[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should work")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldWorkParams()
{
await Page.GotoAsync(Server.EmptyPage);
await Context.AddCookiesAsync(new Cookie
{
Url = Server.EmptyPage,
Name = "password",
Value = "123456"
});
Assert.AreEqual("password=123456", await Page.EvaluateAsync<string>("document.cookie"));
}

[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should roundtrip cookie")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldRoundtripCookie()
Expand Down
11 changes: 11 additions & 0 deletions src/Playwright/API/Generated/IBrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ public partial interface IBrowserContext
/// </param>
Task AddCookiesAsync(IEnumerable<Cookie> cookies);

/// <summary>
Copy link
Member

Choose a reason for hiding this comment

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

The folder Generated should have given you an idea :-). I am not sure what the params implications are for versioning, but it is not options friendly anyways, so we won't be able to add optional options to this overload. It does not seem to be worth it in the general case.

/// <para>
/// Adds cookies into this browser context. All pages within this context will have
/// these cookies installed. Cookies can be obtained via <see cref="IBrowserContext.CookiesAsync"/>.
/// </para>
/// <code>await context.AddCookiesAsync(cookie1, cookie2);</code>
/// </summary>
/// <param name="cookies">
/// </param>
Task AddCookiesAsync(params Cookie[] cookies);

/// <summary>
/// <para>Adds a script which would be evaluated in one of the following scenarios:</para>
/// <list type="bullet">
Expand Down
2 changes: 2 additions & 0 deletions src/Playwright/Core/BrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ internal float DefaultTimeout

public Task AddCookiesAsync(IEnumerable<Cookie> cookies) => Channel.AddCookiesAsync(cookies);

public Task AddCookiesAsync(params Cookie[] cookies) => Channel.AddCookiesAsync(cookies);

public Task AddInitScriptAsync(string script = null, string scriptPath = null)
{
if (string.IsNullOrEmpty(script))
Expand Down