Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for executeScript/evaluateScript args #826

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Driver/CoreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,23 @@ 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);
}

/**
* {@inheritdoc}
*/
public function evaluateScript($script)
public function evaluateScript($script, array $args = [])
{
throw new UnsupportedDriverActionException('JS is not supported by %s', $this);
}

/**
* {@inheritdoc}
*/
public function wait($timeout, $condition)
public function wait($timeout, $condition, array $args = [])
{
throw new UnsupportedDriverActionException('JS is not supported by %s', $this);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -582,26 +583,28 @@ 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.
*
* @param int $timeout timeout in milliseconds
* @param string $condition JS condition
* @param array $args
*
* @return bool
*
* @throws UnsupportedDriverActionException When operation not supported by the driver
* @throws DriverException When the operation cannot be done
*/
public function wait($timeout, $condition);
public function wait($timeout, $condition, array $args = []);

/**
* Set the dimensions of the window.
Expand Down
15 changes: 9 additions & 6 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,35 +325,38 @@ 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);
}

/**
* Waits some time or until JS condition turns true.
*
* @param int $time time in milliseconds
* @param string $condition JS condition
* @param array $args
*
* @return bool
*/
public function wait($time, $condition = 'false')
public function wait($time, $condition = 'false', array $args = [])
{
return $this->driver->wait($time, $condition);
return $this->driver->wait($time, $condition, $args);
}

/**
Expand Down