Skip to content
Open
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
2 changes: 1 addition & 1 deletion bin/lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ContextHandler extends BaseHandler {
setOffline: () => context.setOffline(!!command.offline),
setGeolocation: () => context.setGeolocation(command.geolocation),
addCookies: () => context.addCookies(command.cookies),
clearCookies: () => context.clearCookies(),
clearCookies: () => context.clearCookies(command.options || {}),
grantPermissions: () => context.grantPermissions(command.permissions, command.origin ? { origin: command.origin } : undefined),
clearPermissions: () => context.clearPermissions(),
startTracing: () => context.tracing.start(command.options || {}),
Expand Down
2 changes: 1 addition & 1 deletion bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Playwright server for PHP",
"main": "playwright-server.js",
"dependencies": {
"playwright": "^1.40.0"
"playwright": "^1.58.2"
},
"scripts": {
"install-browsers": "npx playwright install",
Expand Down
6 changes: 5 additions & 1 deletion src/Browser/BrowserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,15 @@ public function addInitScript(string $script): void
]);
}

public function clearCookies(): void
/**
* @param array<string, mixed> $options
*/
public function clearCookies(array $options = []): void
{
$this->transport->send([
'action' => 'context.clearCookies',
'contextId' => $this->contextId,
'options' => $options,
]);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Browser/BrowserContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function addCookies(array $cookies): void;

public function addInitScript(string $script): void;

public function clearCookies(): void;
/**
* @param array<array{domain: string, name: string, path: string}> $options
*/
public function clearCookies(array $options = []): void;

/**
* Delete all cookies with the given name across domain and path variants.
Expand Down
14 changes: 6 additions & 8 deletions tests/Functional/Auth/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,24 @@ public function testCanGetCookies(): void
self::assertSame('my_value', $myCookie['value']);
}

public function testCanDeleteCookies(): void
public function testCanDeleteSingleCookie(): void
{
$this->goto('/cookies.html');

$this->context->addCookies([
[
'name' => 'to_delete',
'value' => 'delete_me',
'url' => $this->getBaseUrl(),
],
['name' => 'to_delete', 'value' => 'delete_me', 'url' => $this->getBaseUrl()],
['name' => 'to_keep', 'value' => 'keep_me', 'url' => $this->getBaseUrl()],
]);

$cookies = $this->context->cookies();
$cookieNames = \array_column($cookies, 'name');
self::assertContains('to_delete', $cookieNames);

$this->context->clearCookies();
$this->context->clearCookies(['name' => 'to_delete']);

$cookiesAfter = $this->context->cookies();
self::assertEmpty($cookiesAfter);
self::assertCount(1, $cookiesAfter);
self::assertSame('keep_me', $cookiesAfter[0]['value']);
}

public function testCanSetCookieWithExpiration(): void
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Browser/BrowserContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,26 @@ public function testClearCookies(): void
->with([
'action' => 'context.clearCookies',
'contextId' => 'context_1',
'options' => [],
]);

$this->context->clearCookies();
}

public function testClearCookiesWithOptions(): void
{
$this->mockTransport
->expects($this->once())
->method('send')
->with([
'action' => 'context.clearCookies',
'contextId' => 'context_1',
'options' => ['name' => 'name_1'],
]);

$this->context->clearCookies(['name' => 'name_1']);
}

public function testClearPermissions(): void
{
$this->mockTransport
Expand Down