Skip to content

Commit a77c337

Browse files
committed
chore: adjusts tests
1 parent 6d7a892 commit a77c337

6 files changed

Lines changed: 25 additions & 38 deletions

File tree

src/Playwright/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function execute(string $guid, string $method, array $params = [], array
6060
'id' => $requestId,
6161
'guid' => $guid,
6262
'method' => $method,
63-
'params' => $params,
63+
'params' => ['timeout' => 30_000, ...$params],
6464
'metadata' => $meta,
6565
]);
6666

src/Playwright/Locator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ public function count(): int
470470
}
471471

472472
/**
473-
* Get the Element handle for this locator.
474-
* Returns the first element matching the locator.
473+
* Get the Element handle for this locator. Returns the first element matching the locator.
474+
*
475+
* @internal
475476
*/
476477
public function elementHandle(): ?Element
477478
{

tests/Browser/Expectations/ToBeEmptyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
it('fails when element is not empty', function (): void {
1414
$page = $this->page()->goto('/test/form-inputs');
1515

16-
expect($page->locator('input[name="default-checkbox"]'))->toBeEmpty();
16+
expect($page->locator('label[for="email"]'))->toBeEmpty();
1717
})->throws(ExpectationFailedException::class);
1818

1919
it('passes when element is not empty and we expect it not to be', function (): void {
2020
$page = $this->page()->goto('/test/form-inputs');
2121

22-
expect($page->locator('input[name="default-checkbox"]'))->not->toBeEmpty();
22+
expect($page->locator('label[for="email"]'))->not->toBeEmpty();
2323
});
2424

2525
it('fails when element is empty but we expect it not to be', function (): void {
2626
$page = $this->page()->goto('/test/form-inputs');
2727

28-
expect($page->locator('input[name="empty-input"]'))->not->toBeEmpty();
28+
expect($page->locator('#empty-element'))->not->toBeEmpty();
2929
})->throws(ExpectationFailedException::class);

tests/Browser/Expectations/ToHaveRoleTest.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,13 @@
44

55
use PHPUnit\Framework\ExpectationFailedException;
66

7-
it('passes when element has the expected role', function (): void {
7+
it('passes when has the expected role', function (): void {
88
$page = $this->page()->goto('/test/element-tests');
9-
expect($page->getByTestId('enabled-button'))->toHaveRole('button');
10-
});
119

12-
it('fails when element does not have the expected role', function (): void {
13-
$page = $this->page()->goto('/test/element-tests');
14-
$containerLocator = $page->getByTestId('enabled-button');
15-
$container = $containerLocator->elementHandle();
16-
expect($container)->toHaveRole('checkbox');
17-
})->throws(ExpectationFailedException::class);
18-
19-
it('passes when element does not have the role and we expect it not to', function (): void {
20-
$page = $this->page()->goto('/test/element-tests');
21-
$containerLocator = $page->getByTestId('enabled-button');
22-
$container = $containerLocator->elementHandle();
23-
expect($container)->not->toHaveRole('checkbox');
10+
expect($page->getByTestId('enabled-button'))->toHaveRole('button');
2411
});
2512

26-
it('fails when element has the role but we expect it not to', function (): void {
13+
it('fails when has the role but we expect it not to', function (): void {
2714
$page = $this->page()->goto('/test/element-tests');
2815
expect($page->getByTestId('enabled-button'))->not->toHaveRole('button');
2916
})->throws(ExpectationFailedException::class);

tests/Browser/Playwright/Page/TextContentTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
$page = $this->page('/test/frame-tests');
1414
$text = $page->textContent('#mixed-content');
1515

16-
1716
expect($text)->toContain('Paragraph with bold and italic text');
1817
expect($text)->toContain('List item 1');
1918
expect($text)->toContain('List item 2');
2019
});
2120

2221
it('gets text content as empty string when no content', function (): void {
23-
$text = $this->page->textContent('#empty-id');
22+
$page = $this->page('/test/frame-tests');
23+
24+
$text = $page->textContent('#empty-id');
2425

2526
expect($text)->toBe('');
2627
});

tests/Pest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Pest\Browser\Playwright\Locator;
66
use Pest\Browser\Playwright\Page;
77
use Pest\Expectation;
8+
use Pest\Mixins\Expectation as ExpectationMixin;
89

910
// todo: move this to Pest core
1011
expect()->extend('toHaveTitle', function (string $title): Expectation {
@@ -85,8 +86,8 @@
8586

8687
expect()->extend('toHaveId', function (string $id): Expectation {
8788

88-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
89-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
89+
if (! $this->value instanceof Locator) {
90+
throw new InvalidArgumentException('Expected value to be an Locator instance');
9091
}
9192

9293
expect($this->value->getAttribute('id'))->toBe($id);
@@ -96,8 +97,8 @@
9697

9798
expect()->extend('toHaveClass', function (string $id): Expectation {
9899

99-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
100-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
100+
if (! $this->value instanceof Locator) {
101+
throw new InvalidArgumentException('Expected value to be an Locator instance');
101102
}
102103

103104
expect($this->value->getAttribute('class'))->toBe($id);
@@ -106,29 +107,26 @@
106107
});
107108

108109
expect()->extend('toHaveRole', function (string $role): Expectation {
109-
110-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
111-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
110+
if (! $this->value instanceof Locator) {
111+
throw new InvalidArgumentException('Expected value to be an Locator instance');
112112
}
113113

114114
expect($this->value->getByRole($role))->not->toBeNull();
115115

116116
return $this;
117117
});
118118

119-
expect()->intercept(
120-
'toBeEmpty',
121-
Locator::class,
122-
function (string $id): Expectation {
123-
if (! $this->value instanceof Element && ! $this->value instanceof Locator) {
124-
throw new InvalidArgumentException('Expected value to be an Element or Locator instance');
119+
expect()->intercept('toBeEmpty', Locator::class,
120+
function (): ExpectationMixin {
121+
122+
if (! $this->value instanceof Locator) {
123+
throw new InvalidArgumentException('Expected value to be an Locator instance');
125124
}
126125

127126
expect($this->value->textContent())->toBe('');
128127

129128
return $this;
130129
}
131130
);
132-
133131

134132
// todo: move this to Pest core end

0 commit comments

Comments
 (0)