From 994d1bb1493bed779ed73911dd49339aab7e7683 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 15 Mar 2022 10:38:10 +0100 Subject: [PATCH] MOBILE-3833 behat: Document performance config --- tests/behat/classes/performance_measure.php | 39 ++++++++++++++++++++- tests/behat/performance.feature | 19 ++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/behat/classes/performance_measure.php b/tests/behat/classes/performance_measure.php index 3348fba36..4e3c8ee7d 100644 --- a/tests/behat/classes/performance_measure.php +++ b/tests/behat/classes/performance_measure.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +use Behat\Mink\Exception\DriverException; +use Facebook\WebDriver\Exception\InvalidArgumentException; use Moodle\BehatExtension\Driver\WebDriver; /** @@ -268,7 +270,7 @@ class performance_measure implements behat_app_listener { $scripting = 0; $styling = 0; $networking = 0; - $logs = $this->driver->getWebDriver()->manage()->getLog('performance'); + $logs = $this->getPerformanceLogs(); foreach ($logs as $log) { // TODO this should filter by end time as well, but it seems like the timestamps are not @@ -304,4 +306,39 @@ class performance_measure implements behat_app_listener { $this->networking = $networking; } + /** + * Get performance logs. + * + * @return array Performance logs. + */ + private function getPerformanceLogs(): array { + try { + return $this->driver->getWebDriver()->manage()->getLog('performance'); + } catch (InvalidArgumentException $e) { + throw new DriverException( + implode("\n", [ + "It wasn't possible to get performance logs, make sure that you have configured the following capabilities:", + "", + "\$CFG->behat_profiles = [", + " 'default' => [", + " 'browser' => 'chrome',", + " 'wd_host' => 'http://selenium:4444/wd/hub',", + " 'capabilities' => [", + " 'extra_capabilities' => [", + " 'goog:loggingPrefs' => ['performance' => 'ALL'],", + " 'chromeOptions' => [", + " 'perfLoggingPrefs' => [", + " 'traceCategories' => 'devtools.timeline',", + " ],", + " ],", + " ],", + " ],", + " ],", + ");", + "", + ]) + ); + } + } + } diff --git a/tests/behat/performance.feature b/tests/behat/performance.feature index f90a81ce9..39a41c5d1 100644 --- a/tests/behat/performance.feature +++ b/tests/behat/performance.feature @@ -1,6 +1,25 @@ @app @javascript @performance Feature: Measure performance. + # In order to run performance tests, you need to add the following capabilities to your Behat configuration: + # + # $CFG->behat_profiles = [ + # 'default' => [ + # 'browser' => 'chrome', + # 'wd_host' => 'http://selenium:4444/wd/hub', + # 'capabilities' => [ + # 'extra_capabilities' => [ + # 'goog:loggingPrefs' => ['performance' => 'ALL'], + # 'chromeOptions' => [ + # 'perfLoggingPrefs' => [ + # 'traceCategories' => 'devtools.timeline', + # ], + # ], + # ], + # ], + # ], + # ]; + Background: Given the following "users" exist: | username |