diff --git a/admin/tool/customlang/tests/behat/customisation_create.feature b/admin/tool/customlang/tests/behat/customisation_create.feature
index 84f71bb8ba9..1d139473593 100644
--- a/admin/tool/customlang/tests/behat/customisation_create.feature
+++ b/admin/tool/customlang/tests/behat/customisation_create.feature
@@ -5,7 +5,10 @@ Feature: Within a moodle instance, an administrator should be able to modify lan
I need to be able to access and change values in the the language customisation of the language pack.
Background:
- Given I log in as "admin"
+ # This is a very slow running test and on slow databases can take minutes to complete.
+ Given I mark this test as slow setting a timeout factor of 4
+
+ And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
diff --git a/admin/tool/customlang/tests/behat/export.feature b/admin/tool/customlang/tests/behat/export.feature
index a42e6722b08..8ff826d5b30 100644
--- a/admin/tool/customlang/tests/behat/export.feature
+++ b/admin/tool/customlang/tests/behat/export.feature
@@ -4,6 +4,10 @@ Feature: Within a moodle instance, an administrator should be able to export mod
As an admin
I need to be able to export the php-files of the language customisation of a language.
+ Background:
+ # This is a very slow running feature and on slow databases can take minutes to complete.
+ Given I mark this test as slow setting a timeout factor of 4
+
@javascript
Scenario: Export button should not appear if no customization is made
Given I log in as "admin"
diff --git a/admin/tool/customlang/tests/behat/import_files.feature b/admin/tool/customlang/tests/behat/import_files.feature
index 20df1c0f675..3d93dfec90f 100644
--- a/admin/tool/customlang/tests/behat/import_files.feature
+++ b/admin/tool/customlang/tests/behat/import_files.feature
@@ -5,7 +5,10 @@ Feature: Within a moodle instance, an administrator should be able to import mod
I need to be able to import the zips and php files of the language customisation of a language.
Background:
- Given I log in as "admin"
+ # This is a very slow running test and on slow databases can take minutes to complete.
+ Given I mark this test as slow setting a timeout factor of 4
+
+ And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I click on "Import custom strings" "button"
diff --git a/admin/tool/customlang/tests/behat/import_mode.feature b/admin/tool/customlang/tests/behat/import_mode.feature
index 2347cf24e9d..e977237a5e8 100644
--- a/admin/tool/customlang/tests/behat/import_mode.feature
+++ b/admin/tool/customlang/tests/behat/import_mode.feature
@@ -5,8 +5,11 @@ Feature: Within a moodle instance, an administrator should be able to import lan
I need to be able to import only some language customisation strings depending on some conditions.
Background:
+ # This is a very slow running feature and on slow databases can take minutes to complete.
+ Given I mark this test as slow setting a timeout factor of 4
+
# Add one customization.
- Given I log in as "admin"
+ And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
diff --git a/admin/tool/httpsreplace/tests/behat/httpsreplace.feature b/admin/tool/httpsreplace/tests/behat/httpsreplace.feature
index 76e77e0f8f7..f8d99f95059 100644
--- a/admin/tool/httpsreplace/tests/behat/httpsreplace.feature
+++ b/admin/tool/httpsreplace/tests/behat/httpsreplace.feature
@@ -5,7 +5,10 @@ Feature: View the httpsreplace report
I need to be able to automatically replace http links
Background: Create some http links
- Given I am on site homepage
+ # This is a slow running feature and on slow databases can take over 30 seconds to complete.
+ Given I mark this test as slow setting a timeout factor of 2
+
+ And I am on site homepage
And the following "courses" exist:
| fullname | shortname | category | summary |
| Course 1 | C1 | 0 |
|
diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php
index 2def65d9b65..4d1a39fff26 100644
--- a/lib/behat/classes/behat_session_trait.php
+++ b/lib/behat/classes/behat_session_trait.php
@@ -1355,4 +1355,25 @@ EOF;
return $this->evaluate_script($script);
}
+
+ /**
+ * Set the timeout factor for the remaining lifetime of the session.
+ *
+ * @param int $factor A multiplication factor to use when calculating the timeout
+ */
+ public function set_test_timeout_factor(int $factor = 1): void {
+ $driver = $this->getSession()->getDriver();
+
+ if (!$driver instanceof \OAndreyev\Mink\Driver\WebDriver) {
+ // This is a feature of the OAndreyev MinkWebDriver.
+ return;
+ }
+
+ // Use `get_real_timeout` to multiply the timeout by the global behat_increasetimeout value, and again by the
+ // factor specified.
+ $this->getSession()->getDriver()->setTimeouts([
+ // The standard script timeout is 30000 ms. (aka, 30 seconds).
+ 'script' => self::get_real_timeout(30) * 1000 * $factor,
+ ]);
+ }
}
diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php
index effa94ce047..36075385a0d 100644
--- a/lib/tests/behat/behat_general.php
+++ b/lib/tests/behat/behat_general.php
@@ -2065,4 +2065,15 @@ EOF;
$localurl = new moodle_url($localurl);
$this->getSession()->visit($this->locate_path($localurl->out_as_local_url(false)));
}
+
+ /**
+ * Increase the webdriver timeouts.
+ *
+ * This should be reset between scenarios, or can be called again to decrease the timeouts.
+ *
+ * @Given I mark this test as slow setting a timeout factor of :factor
+ */
+ public function i_mark_this_test_as_long_running(int $factor = 2): void {
+ $this->set_test_timeout_factor($factor);
+ }
}
diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php
index 36f6a7eb353..5458a382214 100644
--- a/lib/tests/behat/behat_hooks.php
+++ b/lib/tests/behat/behat_hooks.php
@@ -303,13 +303,7 @@ EOF;
protected function start_session(): void {
$this->getSession()->start();
- if ($this->running_javascript()) { // Goutte driver doesn't implement this.
- $this->getSession()->getDriver()->setTimeouts([
- // The standard script timeout is 30000 ms. (aka, 30 seconds).
- // Use `get_real_timeout` to multiply this by the behat increased timeout factor.
- 'script' => self::get_real_timeout(30) * 1000,
- ]);
- }
+ $this->set_test_timeout_factor(1);
}
/**