How to use checkExpression 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.

object-preview-internal-properties.js

Source: object-preview-internal-properties.js Github

copy
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4//
5// Flags: --harmony-class-fields
6
7let {session, contextGroup, Protocol} = InspectorTest.start("Check internal properties reported in object preview.");
8
9Protocol.Debugger.enable();
10Protocol.Runtime.enable();
11Protocol.Runtime.onConsoleAPICalled(dumpInternalPropertiesAndEntries);
12
13contextGroup.setupInjectedScriptEnvironment();
14
15InspectorTest.runTestSuite([
16  function boxedObjects(next)
17  {
18    checkExpression("new Number(239)")
19      .then(() => checkExpression("new Boolean(false)"))
20      .then(() => checkExpression("new String(\"abc\")"))
21      .then(() => checkExpression("Object(Symbol(42))"))
22      .then(() => checkExpression("Object(BigInt(2))"))
23      .then(next);
24  },
25
26  function promise(next)
27  {
28    checkExpression("Promise.resolve(42)")
29      .then(() => checkExpression("new Promise(() => undefined)"))
30      .then(next);
31  },
32
33  function generatorObject(next)
34  {
35    checkExpression("(function* foo() { yield 1 })()")
36      .then(next);
37  },
38
39  function entriesInMapAndSet(next)
40  {
41    checkExpression("new Map([[1,2]])")
42      .then(() => checkExpression("new Set([1])"))
43      .then(() => checkExpression("new WeakMap([[{}, 42]])"))
44      .then(() => checkExpression("new WeakSet([{}])"))
45      .then(next);
46  },
47
48  function iteratorObject(next)
49  {
50    checkExpression("(new Map([[1,2]])).entries()")
51      .then(() => checkExpression("(new Set([1,2])).entries()"))
52      .then(next);
53  },
54
55  function noPreviewForFunctionObject(next)
56  {
57    var expression = "(function foo(){})";
58    InspectorTest.log(expression);
59    Protocol.Runtime.evaluate({ expression: expression, generatePreview: true})
60      .then(message => InspectorTest.logMessage(message))
61      .then(next);
62  },
63
64  function otherObjects(next)
65  {
66    checkExpression("[1,2,3]")
67      .then(() => checkExpression("/123/"))
68      .then(() => checkExpression("({})"))
69      .then(next);
70  },
71
72  function overridenArrayGetter(next)
73  {
74    Protocol.Runtime.evaluate({ expression: "Array.prototype.__defineGetter__(\"0\",() => { throw new Error() }) "})
75      .then(() => checkExpression("Promise.resolve(42)"))
76      .then(next);
77  },
78
79  function privateNames(next)
80  {
81    checkExpression("new class { #foo = 1; #bar = 2; baz = 3;}")
82      .then(() => checkExpression("new class extends class { #baz = 3; } { #foo = 1; #bar = 2; }"))
83      .then(() => checkExpression("new class extends class { constructor() { return new Proxy({}, {}); } } { #foo = 1; #bar = 2; }"))
84      .then(next);
85  },
86
87  function functionProxy(next)
88  {
89    checkExpression("new Proxy(() => {}, { get: () => x++ })")
90      .then(next);
91  }
92]);
93
94function checkExpression(expression)
95{
96  InspectorTest.log(`expression: ${expression}`);
97  // console.table has higher limits for internal properties amount in preview.
98  return Protocol.Runtime.evaluate({ expression: `console.table(${expression})`, generatePreview: true });
99}
100
101function dumpInternalPropertiesAndEntries(message)
102{
103  var properties;
104  var entries;
105  try {
106    var preview = message.params.args[0].preview;
107    properties = preview.properties;
108    entries = preview.entries;
109  } catch (e) {
110    InspectorTest.logMessage(message);
111    return;
112  }
113  if (!properties) {
114    InspectorTest.logMessage(message);
115    return;
116  }
117  for (var property of properties)
118    InspectorTest.logMessage(property);
119  if (entries) {
120    InspectorTest.log("[[Entries]]:");
121    InspectorTest.logMessage(entries);
122  }
123  InspectorTest.log("");
124}
125
Full Screen

internal-properties-entries.js

Source: internal-properties-entries.js Github

copy
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --no-stress-flush-bytecode
6
7let {session, contextGroup, Protocol} = InspectorTest.start('Checks internal [[Entries]] in Runtime.getProperties output');
8
9Protocol.Runtime.enable();
10
11InspectorTest.runTestSuite([
12  function maps(next) {
13    checkExpression('new Map([[1,2],[3,4]])')
14      .then(() => checkExpression('new Map()'))
15      .then(next);
16  },
17
18  function mapIterators(next) {
19    checkExpression('new Map([[1,2],[3,4]]).entries()')
20      .then(() => checkExpression('it = new Map([[1,2],[3,4]]).entries(); it.next(); it'))
21      .then(() => checkExpression('it = new Map([[1,2],[3,4]]).keys(); it.next(); it'))
22      .then(() => checkExpression('it = new Map([[1,2],[3,4]]).values(); it.next(); it'))
23      .then(() => checkExpression('it = new Map([[1,2],[3,4]]).entries(); it.next(); it.next(); it'))
24      .then(() => checkExpression('new Map([[1, undefined], [2, () => 42], [3, /abc/], [4, new Error()]]).entries()'))
25      .then(next);
26  },
27
28  function sets(next) {
29    checkExpression('new Set([1,2])')
30      .then(() => checkExpression('new Set()'))
31      .then(next);
32  },
33
34  function setIterators(next) {
35    checkExpression('new Set([1,2]).values()')
36      .then(() => checkExpression('it = new Set([1,2]).values(); it.next(); it'))
37      .then(() => checkExpression('it = new Set([1,2]).keys(); it.next(); it'))
38      .then(() => checkExpression('it = new Set([1,2]).entries(); it.next(); it'))
39      .then(() => checkExpression('it = new Set([1,2]).values(); it.next(); it.next(); it'))
40      .then(next);
41  },
42
43  function weakMaps(next) {
44    checkExpression('new WeakMap()')
45      .then(() => checkExpression('new WeakMap([[{ a: 2 }, 42]])'))
46      .then(next);
47  },
48
49  function weakSets(next) {
50    checkExpression('new WeakSet()')
51      .then(() => checkExpression('new WeakSet([{a:2}])'))
52      .then(next);
53  }
54]);
55
56function checkExpression(expression)
57{
58  InspectorTest.log(`expression: ${expression}`);
59  var entriesObjectId;
60  return Protocol.Runtime.evaluate({ expression: expression })
61    .then(message => Protocol.Runtime.getProperties({ objectId: message.result.result.objectId }))
62    .then(message => message.result.internalProperties.filter(p => p.name === '[[Entries]]')[0])
63    .then(entries => entriesObjectId = entries.value.objectId)
64    .then(() => Protocol.Runtime.callFunctionOn({ objectId: entriesObjectId, functionDeclaration: 'function f() { return this; }', returnByValue: true }))
65    .then(message => InspectorTest.logMessage(message.result.result.value))
66    .then(() => Protocol.Runtime.getProperties({ objectId: entriesObjectId, ownProperties: true }))
67    .then(message => InspectorTest.logMessage(message));
68}
69
Full Screen

internal-properties.js

Source: internal-properties.js Github

copy
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5let {session, contextGroup, Protocol} = InspectorTest.start('Checks internal properties in Runtime.getProperties output');
6
7contextGroup.addScript(`
8function* foo() {
9  yield 1;
10}
11var gen1 = foo();
12var gen2 = foo();
13//# sourceURL=test.js`, 7, 26);
14
15Protocol.Runtime.enable();
16Protocol.Debugger.enable();
17
18InspectorTest.runTestSuite([
19  function generatorFunction(next) {
20    checkExpression('(function* foo() { yield 1 })').then(next);
21  },
22
23  function regularFunction(next) {
24    checkExpression('(function foo() {})').then(next);
25  },
26
27  function boxedObjects(next) {
28    checkExpression('new Number(239)')
29      .then(() => checkExpression('new Boolean(false)'))
30      .then(() => checkExpression('new String(\'abc\')'))
31      .then(() => checkExpression('Object(Symbol(42))'))
32      .then(() => checkExpression("Object(BigInt(2))"))
33      .then(next);
34  },
35
36  function promise(next) {
37    checkExpression('Promise.resolve(42)')
38      .then(() => checkExpression('new Promise(() => undefined)'))
39      .then(next);
40  },
41
42  function generatorObject(next) {
43    checkExpression('gen1')
44      .then(() => checkExpression('gen1.next();gen1'))
45      .then(() => checkExpression('gen1.next();gen1'))
46      .then(next);
47  },
48
49  function generatorObjectDebuggerDisabled(next) {
50    Protocol.Debugger.disable()
51      .then(() => checkExpression('gen2'))
52      .then(() => checkExpression('gen2.next();gen2'))
53      .then(() => checkExpression('gen2.next();gen2'))
54      .then(next);
55  },
56
57  function iteratorObject(next) {
58    checkExpression('(new Map([[1,2]])).entries()')
59      .then(() => checkExpression('(new Set([[1,2]])).entries()'))
60      .then(next);
61  }
62]);
63
64function checkExpression(expression)
65{
66  InspectorTest.log(`expression: ${expression}`);
67  return Protocol.Runtime.evaluate({ expression: expression })
68    .then(message => Protocol.Runtime.getProperties({ objectId: message.result.result.objectId }))
69    .then(message => { delete message.result.result; return message; })
70    .then(InspectorTest.logMessage);
71}
72
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)