From c5f955236986c8ac6d820b84dd65fed3286d18b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 15 Apr 2022 00:05:34 +0200 Subject: [PATCH] Add support for execute args --- src/Driver/CoreDriver.php | 4 ++-- src/Driver/DriverInterface.php | 6 ++++-- src/Session.php | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Driver/CoreDriver.php b/src/Driver/CoreDriver.php index 9b4c04e43..8e4d55e6c 100644 --- a/src/Driver/CoreDriver.php +++ b/src/Driver/CoreDriver.php @@ -428,7 +428,7 @@ public function dragTo($sourceXpath, $destinationXpath) /** * {@inheritdoc} */ - public function executeScript($script) + public function executeScript($script, array $args = []) { throw new UnsupportedDriverActionException('JS is not supported by %s', $this); } @@ -436,7 +436,7 @@ public function executeScript($script) /** * {@inheritdoc} */ - public function evaluateScript($script) + public function evaluateScript($script, array $args = []) { throw new UnsupportedDriverActionException('JS is not supported by %s', $this); } diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index 0eec66bc5..b05f6d32e 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -569,11 +569,12 @@ public function dragTo($sourceXpath, $destinationXpath); * Executes JS script. * * @param string $script + * @param array $args * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done */ - public function executeScript($script); + public function executeScript($script, array $args = []); /** * Evaluates JS script. @@ -582,13 +583,14 @@ public function executeScript($script); * must accept the expression both with and without the keyword. * * @param string $script + * @param array $args * * @return mixed * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done */ - public function evaluateScript($script); + public function evaluateScript($script, array $args = []); /** * Waits some time or until JS condition turns true. diff --git a/src/Session.php b/src/Session.php index 2bb16b640..c3294f163 100644 --- a/src/Session.php +++ b/src/Session.php @@ -325,22 +325,24 @@ public function switchToIFrame($name = null) * Execute JS in browser. * * @param string $script javascript + * @param array $args */ - public function executeScript($script) + public function executeScript($script, array $args = []) { - $this->driver->executeScript($script); + $this->driver->executeScript($script, $args); } /** * Execute JS in browser and return its response. * * @param string $script javascript + * @param array $args * * @return mixed */ - public function evaluateScript($script) + public function evaluateScript($script, array $args = []) { - return $this->driver->evaluateScript($script); + return $this->driver->evaluateScript($script, $args); } /**