Skip to content

Commit

Permalink
Support Dusk Selectors in screenshotElement (#1094)
Browse files Browse the repository at this point in the history
* 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 <taylor@laravel.com>
  • Loading branch information
rabrowne85 and taylorotwell authored Mar 24, 2024
1 parent 783382b commit 1bdefcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function screenshotElement($selector, $name)
}

$this->scrollIntoView($selector)
->driver->findElement(WebDriverBy::cssSelector($selector))
->driver->findElement(WebDriverBy::cssSelector($this->resolver->format($selector)))
->takeElementScreenshot($filePath);

return $this;
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function test_screenshot_in_subdirectory()
$this->assertFileExists(Browser::$storeScreenshotsAt.'/'.$name.'.png');
}

public function test_element_screenshot()
public function test_screenshot_element()
{
$elementMock = $this->createMock(RemoteWebElement::class);
$elementMock->expects($this->once())
Expand All @@ -256,7 +256,7 @@ public function test_element_screenshot()
$driverMock = $this->createMock(RemoteWebDriver::class);
$driverMock->expects($this->once())
->method('findElement')
->with(WebDriverBy::cssSelector('#selector'))
->with(WebDriverBy::cssSelector('body #selector'))
->willReturn($elementMock);

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

public function test_element_screenshot_in_subdirectory()
public function test_screenshot_element_in_subdirectory()
{
$elementMock = $this->createMock(RemoteWebElement::class);
$elementMock->expects($this->once())
Expand All @@ -283,7 +283,7 @@ public function test_element_screenshot_in_subdirectory()
$driverMock = $this->createMock(RemoteWebDriver::class);
$driverMock->expects($this->once())
->method('findElement')
->with(WebDriverBy::cssSelector('#selector'))
->with(WebDriverBy::cssSelector('body #selector'))
->willReturn($elementMock);

$browser = new Browser($driverMock);
Expand Down

0 comments on commit 1bdefcf

Please sign in to comment.