Skip to content

Commit 1bdefcf

Browse files
Support Dusk Selectors in screenshotElement (#1094)
* Add Helper: `elementScreenshot` * Tests added for new helper `elementScreenshot` * rename method * Support Dusk Selectors in `screenshotElement` * Fix test for `screenshotElement` --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 783382b commit 1bdefcf

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Browser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public function screenshotElement($selector, $name)
466466
}
467467

468468
$this->scrollIntoView($selector)
469-
->driver->findElement(WebDriverBy::cssSelector($selector))
469+
->driver->findElement(WebDriverBy::cssSelector($this->resolver->format($selector)))
470470
->takeElementScreenshot($filePath);
471471

472472
return $this;

tests/Unit/BrowserTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function test_screenshot_in_subdirectory()
244244
$this->assertFileExists(Browser::$storeScreenshotsAt.'/'.$name.'.png');
245245
}
246246

247-
public function test_element_screenshot()
247+
public function test_screenshot_element()
248248
{
249249
$elementMock = $this->createMock(RemoteWebElement::class);
250250
$elementMock->expects($this->once())
@@ -256,7 +256,7 @@ public function test_element_screenshot()
256256
$driverMock = $this->createMock(RemoteWebDriver::class);
257257
$driverMock->expects($this->once())
258258
->method('findElement')
259-
->with(WebDriverBy::cssSelector('#selector'))
259+
->with(WebDriverBy::cssSelector('body #selector'))
260260
->willReturn($elementMock);
261261

262262
$browser = new Browser($driverMock);
@@ -271,7 +271,7 @@ public function test_element_screenshot()
271271
$this->assertFileExists(Browser::$storeScreenshotsAt.'/'.$name.'.png');
272272
}
273273

274-
public function test_element_screenshot_in_subdirectory()
274+
public function test_screenshot_element_in_subdirectory()
275275
{
276276
$elementMock = $this->createMock(RemoteWebElement::class);
277277
$elementMock->expects($this->once())
@@ -283,7 +283,7 @@ public function test_element_screenshot_in_subdirectory()
283283
$driverMock = $this->createMock(RemoteWebDriver::class);
284284
$driverMock->expects($this->once())
285285
->method('findElement')
286-
->with(WebDriverBy::cssSelector('#selector'))
286+
->with(WebDriverBy::cssSelector('body #selector'))
287287
->willReturn($elementMock);
288288

289289
$browser = new Browser($driverMock);

0 commit comments

Comments
 (0)