forked from EVOgeek/Vmeda.Online
		
	Merge pull request #3176 from NoelDeMartin/MOBILE-3833
MOBILE-3833: Fix performance tests
This commit is contained in:
		
						commit
						275ef0ac21
					
				| @ -153,6 +153,7 @@ export class CoreConstants { | ||||
|     static enableDevTools(): boolean { | ||||
|         // @todo [4.0] This is not the proper way to check for development tools, we should rely only on the BUILD variable.
 | ||||
|         return this.BUILD.isDevelopment | ||||
|             || this.BUILD.isTesting | ||||
|             || this.CONFIG.versionname.includes('-dev'); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -164,15 +164,21 @@ export class CoreConfigProvider { | ||||
|      * Update config with the given values. | ||||
|      * | ||||
|      * @param config Config updates. | ||||
|      * @param reset Whether to reset environment before applying the patch. | ||||
|      * @param options Patching options. | ||||
|      *  - reset: Whether to reset environment before applying the patch. | ||||
|      *  - patchDefault: Whether to patch default values as well. | ||||
|      */ | ||||
|     patchEnvironment(config: Partial<EnvironmentConfig>, reset: boolean = false): void { | ||||
|     patchEnvironment(config: Partial<EnvironmentConfig>, options: Partial<{ reset: boolean; patchDefault: boolean }> = {}): void { | ||||
|         this.defaultEnvironment = this.defaultEnvironment ?? { ...CoreConstants.CONFIG }; | ||||
| 
 | ||||
|         if (reset) { | ||||
|         if (options.reset) { | ||||
|             this.resetEnvironmentSilently(); | ||||
|         } | ||||
| 
 | ||||
|         if (options.patchDefault) { | ||||
|             Object.assign(this.defaultEnvironment, config); | ||||
|         } | ||||
| 
 | ||||
|         Object.assign(CoreConstants.CONFIG, config); | ||||
|         CoreEvents.trigger(CoreConfigProvider.ENVIRONMENT_UPDATED, CoreConstants.CONFIG); | ||||
|     } | ||||
| @ -199,7 +205,7 @@ export class CoreConfigProvider { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}')); | ||||
|         this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}'), { patchDefault: true }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -14,6 +14,8 @@ | ||||
| // You should have received a copy of the GNU General Public License
 | ||||
| // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| 
 | ||||
| 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',", | ||||
|                     "                    ],", | ||||
|                     "                ],", | ||||
|                     "            ],", | ||||
|                     "        ],", | ||||
|                     "    ],", | ||||
|                     ");", | ||||
|                     "", | ||||
|                 ]) | ||||
|             ); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -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 | | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user