Skip to content

Commit f408e65

Browse files
committed
bug: fix setGeolocation() signature and harder test
1 parent ba72f50 commit f408e65

2 files changed

Lines changed: 4 additions & 18 deletions

File tree

src/Browser/BrowserContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public function loadStorageState(string $filePath): void
402402
$this->setStorageState($storageState);
403403
}
404404

405-
public function setGeolocation(?float $latitude, ?float $longitude, ?float $accuracy = null): void
405+
public function setGeolocation(?float $latitude, ?float $longitude, ?float $accuracy = 0): void
406406
{
407407
$this->transport->send([
408408
'action' => 'context.setGeolocation',

tests/Integration/Browser/BrowserContextTest.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,9 @@ public function itSetsGeolocation(): void
170170

171171
$page->click('button');
172172

173-
// Poll for either coordinates or error text since Page::waitForFunction is not available
174-
$deadline = microtime(true) + 5.0; // 5 seconds
175-
do {
176-
$content = $page->content() ?? '';
177-
$hasCoordinates = str_contains($content, '59.95,30.31667');
178-
$hasError = str_contains($content, 'Error');
179-
if ($hasCoordinates || $hasError) {
180-
break;
181-
}
182-
usleep(100 * 1000); // 100ms
183-
} while (microtime(true) < $deadline);
184-
185-
$content = $page->content();
186-
$hasCoordinates = str_contains($content, '59.95,30.31667');
187-
$hasError = str_contains($content, 'Error:');
188-
189-
$this->assertTrue($hasCoordinates || $hasError, 'Geolocation API should respond with either coordinates or error message');
173+
$page->waitForFunction("() => document.body.innerText.includes('59.95') || document.body.innerText.includes('Error: ')", options: ['timeout' => 200]);
174+
175+
$this->assertStringContainsString('59.95,30.31667', $page->content(), 'Geolocation API should respond with either coordinates or error message');
190176

191177
$page->close();
192178
}

0 commit comments

Comments
 (0)