From 7b18e8ad63ae4e47321caad2abf2e1a2f421853e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Sun, 6 Nov 2022 21:00:09 +0800 Subject: [PATCH] MDL-76207 contentbank: Switch to opened window --- lib/tests/behat/behat_general.php | 16 ++++++++++++++++ .../tests/behat/contentbank_link.feature | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index e421253d68e..19158c9a2cf 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -187,6 +187,22 @@ class behat_general extends behat_base { ); } + /** + * Switches to a second window. + * + * @Given /^I switch to a second window$/ + * @throws DriverException If there aren't exactly 2 windows open. + */ + public function switch_to_second_window() { + $names = $this->getSession()->getWindowNames(); + + if (count($names) !== 2) { + throw new DriverException('Expected to see 2 windows open, found ' . count($names)); + } + + $this->getSession()->switchToWindow($names[1]); + } + /** * Switches to the main Moodle frame. * diff --git a/mod/h5pactivity/tests/behat/contentbank_link.feature b/mod/h5pactivity/tests/behat/contentbank_link.feature index 95f07da5260..ed75005db1e 100644 --- a/mod/h5pactivity/tests/behat/contentbank_link.feature +++ b/mod/h5pactivity/tests/behat/contentbank_link.feature @@ -28,7 +28,7 @@ Feature: Content bank link in the activity settings form And I add a "H5P" to section "1" Then I should see "Use the content bank (opens in new window) to manage your H5P files" And I click on "content bank (opens in new window)" "link" in the "General" "fieldset" - And I switch to the browser tab opened by the app + And I switch to a second window And I should see "Content bank" in the "page-content" "region" And I should see "filltheblanks.h5p" in the "page-content" "region" And I close all opened windows