From 9b85e5d3b0b40971372565def378e2d6d86ba930 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Thu, 8 Apr 2021 11:54:13 -0500 Subject: [PATCH] Added missing navigation methods --- src/Codeception/Lib/InnerBrowser.php | 54 +++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index 8f2e0b2..f6d1aec 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -1963,7 +1963,7 @@ public function moveBack($numberOfSteps = 1) } try { $history = $this->getRunningClient()->getHistory(); - for ($i = $numberOfSteps; $i > 0; $i--) { + for ($i = 0; $i < $numberOfSteps; $i++) { $request = $history->back(); } } catch (\LogicException $e) { @@ -2131,4 +2131,56 @@ public function setMaxRedirects($maxRedirects) { $this->client->setMaxRedirects($maxRedirects); } + + /** + * Goes forward in the browser history. + * + * @param int $numberOfSteps (default value 1) + */ + public function moveForward($numberOfSteps = 1) + { + if (!is_int($numberOfSteps) || $numberOfSteps < 1) { + throw new \InvalidArgumentException('numberOfSteps must be positive integer'); + } + try { + $history = $this->getRunningClient()->getHistory(); + for ($i = 0; $i < $numberOfSteps; $i++) { + $request = $history->forward(); + } + } catch (\LogicException $e) { + throw new \InvalidArgumentException( + sprintf( + 'numberOfSteps is set to %d, but there are only %d steps forward in history', + $numberOfSteps, + $numberOfSteps - $i + ) + ); + } + $this->_loadPage( + $request->getMethod(), + $request->getUri(), + $request->getParameters(), + $request->getFiles(), + $request->getServer(), + $request->getContent() + ); + } + + /** + * Reloads the current browser. + */ + public function reloadPage() + { + $this->client->reload(); + } + + /** + * Restarts the client. + * + * It flushes history and all cookies. + */ + public function restartBrowser() + { + $this->client->restart(); + } }