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

util.js

Source: util.js Github

copy
1// util辅助函数
2import { addEvent, removeEvent } from './event-system'
3import {
4    setStyle,
5    removeStyle,
6    patchStyle
7} from './CSSPropertyOperations.js'
8import {
9    setPropValue,
10    removePropValue,
11    updateSelectOptions
12} from './DOMPropertyOperations'
13import { HTML_KEY } from './constant'
14
15export function isFn(obj) {
16    return typeof obj === 'function'
17}
18
19export let isArr = Array.isArray
20
21export function noop() {}
22export function identity(obj) {
23    return obj
24}
25export function pipe(fn1, fn2) {
26    return function() {
27        fn1.apply(this, arguments)
28        return fn2.apply(this, arguments)
29    }
30}
31
32
33
34export function flatEach(list, iteratee, a) {
35    let len = list.length
36    let i = -1
37
38    while (len--) {
39        let item = list[++i]
40        if (isArr(item)) {
41            flatEach(item, iteratee, a)
42        } else {
43            iteratee(item, a)
44        }
45    }
46}
47
48
49let uid = 0
50export function getUid() {
51    return ++uid
52}
53
54export let EVENT_KEYS = /^on/i
55
56function setProp(elem, key, value, isCustomComponent) {
57    if (EVENT_KEYS.test(key)) {
58        addEvent(elem, key, value)
59    } else if (key === 'style') {
60        setStyle(elem.style, value)
61    } else if (key === HTML_KEY) {
62        if (value && value.__html != null) {
63            elem.innerHTML = value.__html
64        }
65    } else if (isCustomComponent) {
66        if (value == null) {
67            elem.removeAttribute(key)
68        } else {
69            elem.setAttribute(key, '' + value)
70        }
71    } else {
72        setPropValue(elem, key, value)
73    }
74}
75
76function removeProp(elem, key, oldValue, isCustomComponent) {
77    if (EVENT_KEYS.test(key)) {
78        removeEvent(elem, key)
79    } else if (key === 'style') {
80        removeStyle(elem.style, oldValue)
81    } else if (key === HTML_KEY) {
82        elem.innerHTML = ''
83    } else if (isCustomComponent) {
84        elem.removeAttribute(key)
85    } else {
86        removePropValue(elem, key)
87    }
88}
89
90function patchProp(elem, key, value, oldValue, isCustomComponent) {
91    if (key === 'value' || key === 'checked') {
92        oldValue = elem[key]
93    }
94    if (value === oldValue) {
95        return
96    }
97    if (value === undefined) {
98        removeProp(elem, key, oldValue, isCustomComponent)
99        return
100    }
101    if (key === 'style') {
102        patchStyle(elem.style, oldValue, value)
103    } else {
104        setProp(elem, key, value, isCustomComponent)
105    }
106}
107
108export function setProps(elem, props, isCustomComponent) {
109    var isSelect = elem.nodeName === 'SELECT'
110    for (let key in props) {
111        if (key !== 'children') {
112            if (isSelect && (key === 'value' || key === 'defaultValue')) {
113                updateSelectOptions(elem, props.multiple, props[key])
114            } else {
115                setProp(elem, key, props[key], isCustomComponent)
116            }
117        }
118    }
119}
120
121export function patchProps(elem, props, newProps, isCustomComponent) {
122    var isSelect = elem.nodeName === 'SELECT'
123    for (let key in props) {
124        if (key !== 'children') {
125            if (newProps.hasOwnProperty(key)) {
126                if (isSelect && (key === 'value' || key === 'defaultValue')) {
127                    updateSelectOptions(elem, newProps.multiple, newProps[key])
128                } else {
129                    patchProp(elem, key, newProps[key], props[key], isCustomComponent)
130                }
131            } else {
132                removeProp(elem, key, props[key], isCustomComponent)
133            }
134        }
135    }
136    for (let key in newProps) {
137        if (key !== 'children' && !props.hasOwnProperty(key)) {
138            if (isSelect && (key === 'value' || key === 'defaultValue')) {
139                updateSelectOptions(elem, newProps.multiple, newProps[key])
140            } else {
141                setProp(elem, key, newProps[key], isCustomComponent)
142            }
143        }
144    }
145}
146
147if (!Object.freeze) {
148    Object.freeze = identity
149}
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)