From e9a85caf3b3a49350232ddc1e4803200f8f31b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Mon, 16 Oct 2023 15:16:47 +0200 Subject: [PATCH] Added way of accesing the Chrome DevToolsDriver --- src/lib/Browser/Component/Component.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/Browser/Component/Component.php b/src/lib/Browser/Component/Component.php index 0f29f4fb..9b51f95c 100644 --- a/src/lib/Browser/Component/Component.php +++ b/src/lib/Browser/Component/Component.php @@ -9,6 +9,7 @@ namespace Ibexa\Behat\Browser\Component; use Behat\Mink\Session; +use Facebook\WebDriver\Chrome\ChromeDevToolsDriver; use Ibexa\Behat\Browser\Element\Factory\Debug\Highlighting\ElementFactory as HighlightingDebugElementFactory; use Ibexa\Behat\Browser\Element\Factory\Debug\Interactive\ElementFactory as InteractiveDebugElementFactory; use Ibexa\Behat\Browser\Element\Factory\ElementFactory; @@ -16,6 +17,9 @@ use Ibexa\Behat\Browser\Element\RootElementInterface; use Ibexa\Behat\Browser\Locator\LocatorCollection; use Ibexa\Behat\Browser\Locator\LocatorInterface; +use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; +use OAndreyev\Mink\Driver\WebDriver; +use RuntimeException; abstract class Component implements ComponentInterface { @@ -52,6 +56,23 @@ protected function getSession(): Session return $this->session; } + protected function getDevToolsDriver(): ChromeDevToolsDriver + { + $driver = $this->session->getDriver(); + + if (!($driver instanceof WebDriver)) { + throw new NotImplementedException('Chrome DevTools driver is not available for this driver'); + } + + $webDriver = $driver->getWebDriver(); + + if (null === $webDriver) { + throw new RuntimeException('Error happened when accessing the WebDriver'); + } + + return new ChromeDevToolsDriver($webDriver); + } + /** * @return \Ibexa\Behat\Browser\Locator\LocatorInterface[] */