How to use resourcesForAction method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

modelUtil.js

Source: modelUtil.js Github

copy
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.context = context;
7exports.eventsForAction = eventsForAction;
8exports.indexModel = indexModel;
9exports.next = next;
10exports.resourcesForAction = resourcesForAction;
11exports.stats = stats;
12
13/**
14 * Copyright (c) Microsoft Corporation.
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License");
17 * you may not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 *     http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28const contextSymbol = Symbol('context');
29const nextSymbol = Symbol('next');
30const eventsSymbol = Symbol('events');
31const resourcesSymbol = Symbol('resources');
32
33function indexModel(context) {
34  for (const page of context.pages) page[contextSymbol] = context;
35
36  for (let i = 0; i < context.actions.length; ++i) {
37    const action = context.actions[i];
38    action[contextSymbol] = context;
39    action[nextSymbol] = context.actions[i + 1];
40  }
41
42  for (const event of context.events) event[contextSymbol] = context;
43}
44
45function context(action) {
46  return action[contextSymbol];
47}
48
49function next(action) {
50  return action[nextSymbol];
51}
52
53function stats(action) {
54  let errors = 0;
55  let warnings = 0;
56  const c = context(action);
57
58  for (const event of eventsForAction(action)) {
59    if (event.metadata.method === 'console') {
60      var _c$objects$guid;
61
62      const {
63        guid
64      } = event.metadata.params.message;
65      const type = (_c$objects$guid = c.objects[guid]) === null || _c$objects$guid === void 0 ? void 0 : _c$objects$guid.type;
66      if (type === 'warning') ++warnings;else if (type === 'error') ++errors;
67    }
68
69    if (event.metadata.method === 'pageError') ++errors;
70  }
71
72  return {
73    errors,
74    warnings
75  };
76}
77
78function eventsForAction(action) {
79  let result = action[eventsSymbol];
80  if (result) return result;
81  const nextAction = next(action);
82  result = context(action).events.filter(event => {
83    return event.metadata.startTime >= action.metadata.startTime && (!nextAction || event.metadata.startTime < nextAction.metadata.startTime);
84  });
85  action[eventsSymbol] = result;
86  return result;
87}
88
89function resourcesForAction(action) {
90  let result = action[resourcesSymbol];
91  if (result) return result;
92  const nextAction = next(action);
93  result = context(action).resources.filter(resource => {
94    return resource._monotonicTime > action.metadata.startTime && (!nextAction || resource._monotonicTime < nextAction.metadata.startTime);
95  });
96  action[resourcesSymbol] = result;
97  return result;
98}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)