From 22497fe7cd8c94fa9fd7e9af51b22e92130450af Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 26 May 2021 17:09:47 +0200 Subject: [PATCH] MOBILE-3320 behat: Implement browser tab assertion --- tests/behat/behat_app.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index b5abee45e..3d52a63c5 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -653,6 +653,31 @@ class behat_app extends behat_base { }); } + /** + * Check that the app opened a new browser tab. + * + * @Given /^the app should(?P not)? have opened a browser tab$/ + * @param string $not + */ + public function the_app_should_have_opened_a_browser_tab($not = '') { + $not = !empty($not); + + $this->spin(function() use ($not) { + $openedbrowsertab = count($this->getSession()->getWindowNames()) === 2; + + if ($not === $openedbrowsertab) { + throw new ExpectationException( + $not + ? 'Did not expect the app to have opened a browser tab' + : 'Expected the app to have opened a browser tab', + $this->getSession()->getDriver() + ); + } + + return true; + }); + } + /** * Switches to a newly-opened browser tab. *