How to use _getNodeId method in chromy

Best JavaScript code snippet using chromy

dom_agent.js

Source:dom_agent.js Github

copy

Full Screen

...39// events.40// https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-requestNode41commands.requestNode = function(params) {42 let node = commands._findNode(params);43 if (!_getNodeId(node)) {44 _reportPathFromRoot(node.parentNode);45 }46 return JSON.stringify({nodeId: _getNodeId(node)});47}48// Returns a Runtime.RemoteObject corresponding to a node.49// https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-resolveNode50commands.resolveNode = function(params) {51 let node = commands._findNode(params);52 let result = {};53 result.object =54 JSON.parse(debugBackend.createRemoteObject(node, params.objectGroup));55 return JSON.stringify(result);56}57// Creates and returns a devtools.Node object that represents the specified DOM58// node. Adds the node's children up to the specified depth. A negative depth59// will cause all descendants to be added. All returned children are added to60// the node store, and should be reported to the client to maintain integrity of61// the node store holding only nodes the client knows about.62function _getNodeWithChildren(node, depth) {63 let result = new devtools.Node(node);64 let children = _getChildNodes(node, depth);65 if (children.length) {66 result.children = children;67 }68 return result;69}70// Creates and returns an array of devtools.Node objects corresponding to the71// children of the specified DOM node, recursing on each on down to the72// specified depth. All returned children are added to the node store, and73// should be reported to the client to maintain integrity of the node store74// holding only nodes the client knows about.75function _getChildNodes(node, depth) {76 let children;77 // Special-case the only text child - pretend the children were requested.78 if (node.firstChild && !node.firstChild.nextSibling &&79 node.firstChild.nodeType === Node.TEXT_NODE) {80 children = [node.firstChild];81 } else if (depth != 0) { // Negative depth recurses the whole tree.82 let child_nodes = Array.from(node.childNodes);83 children = child_nodes.filter((child) => !_isWhitespace(child));84 // Since we don't report whitespace text nodes they won't be in the node85 // store and won't otherwise be observed. However, we still need to observe86 // them to report if they get set to non-whitespace.87 child_nodes.filter(_isWhitespace)88 .forEach((child) => _nodeObserver.observe(child, _observerConfig));89 } else {90 // Children not requested, so don't set |childrenReported|.91 return [];92 }93 let nodeId = _getNodeId(node);94 _nodeStore.get(nodeId).childrenReported = true;95 return children.map((child) => _getNodeWithChildren(child, depth - 1));96}97// Whether the children of a node have been reported to the frontend.98function _areChildrenReported(nodeId) {99 let nodeInfo = _nodeStore.get(nodeId);100 return nodeInfo && nodeInfo.childrenReported;101}102// Sends DOM.setChildNode events to report all nodes not yet known to the client103// from the root down to the specified DOM node.104function _reportPathFromRoot(node) {105 // Report nothing if we get to a disconnected root.106 if (!node) {107 return false;108 }109 // Stop recursing when we get to a node that has already been reported, and110 // report its children first before unwinding the recursion down the tree.111 if (_getNodeId(node)) {112 _reportChildren(node);113 return true;114 }115 // Recurse up first to report in top-down order, and report nothing if we116 // reached a disconnected root.117 if (!_reportPathFromRoot(node.parentNode)) {118 return false;119 }120 // All ancestors are now reported, so report the node's children.121 _reportChildren(node);122 return true;123}124// Sends a DOM.setChildNodes event reporting the children of a DOM node, and125// their children recursively to the requested depth.126function _reportChildren(node, depth) {127 let nodeId = _addNode(node);128 let children = _getChildNodes(node, depth || 1);129 let params = {130 parentId: nodeId,131 nodes: children,132 };133 debugBackend.sendEvent('DOM.setChildNodes', JSON.stringify(params));134}135// Finds a DOM node specified by either nodeId or objectId (to get a node from136// its corresponding remote object). This is "exported" as a pseudo-command in137// the DOM domain for other agents to use.138commands._findNode = function(params) {139 if (params.nodeId) {140 return _nodeStore.get(params.nodeId).node;141 }142 if (params.objectId) {143 return debugBackend.lookupRemoteObjectId(params.objectId);144 }145 // Either nodeId or objectId must be specified.146 return null;147}148// Adds a DOM node to the internal node store and returns a unique id that can149// be used to access it again. If the node is already in the node store, its150// existing id is returned.151function _addNode(node) {152 let nodeId = _getNodeId(node);153 if (!nodeId) {154 nodeId = _nextNodeId++;155 // The map goes both ways: DOM node <=> node ID.156 _nodeStore.set(nodeId, {node: node});157 _nodeStore.set(node, nodeId);158 _nodeObserver.observe(node, _observerConfig);159 }160 return nodeId;161}162// Removes a DOM node and its children from the internal node store.163function _removeNode(node) {164 let nodeId = _getNodeId(node);165 if (!nodeId) return;166 Array.from(node.childNodes).forEach(_removeNode);167 _nodeStore.delete(node);168 _nodeStore.delete(nodeId);169}170// Returns the node id of a DOM node if it's already known, else undefined.171function _getNodeId(node) {172 return _nodeStore.get(node);173}174// MutationObserver callback to send events when nodes are changed.175function _onNodeMutated(mutationsList) {176 for (let mutation of mutationsList) {177 if (mutation.type === 'childList') {178 _onChildListMutated(mutation);179 } else if (mutation.type === 'attributes') {180 _onAttributesMutated(mutation);181 } else if (mutation.type === 'characterData') {182 _onCharacterDataMutated(mutation);183 }184 }185}186function _onChildListMutated(mutation) {187 let parentNodeId = _getNodeId(mutation.target);188 if (!_areChildrenReported(parentNodeId)) {189 // The mutated node hasn't been expanded in the Element tree so we haven't190 // yet reported any of its children to the frontend. Just report that the191 // number of children changed, without reporting the actual child nodes.192 let params = {193 nodeId: parentNodeId,194 childNodeCount: _countChildNodes(mutation.target),195 };196 debugBackend.sendEvent('DOM.childNodeCountUpdated', JSON.stringify(params));197 } else {198 // The mutated node has already been expanded in the Element tree so the199 // frontend already knows about its children. Report the removed/inserted200 // nodes. Report removed nodes first so that replacements (e.g. setting201 // textContent) are coherent.202 Array.from(mutation.removedNodes)203 .forEach((n) => _onNodeRemoved(parentNodeId, n));204 Array.from(mutation.addedNodes)205 .forEach((n) => _onNodeInserted(parentNodeId, n));206 }207}208// Report to the frontend when a DOM node is inserted.209function _onNodeInserted(parentNodeId, node) {210 if (_isWhitespace(node)) return;211 // Forget anything we knew about an existing subtree that gets re-attached.212 _removeNode(node);213 let params = {214 parentNodeId: parentNodeId,215 previousNodeId: _getNodeId(_getPreviousSibling(node)) || 0,216 node: new devtools.Node(node),217 };218 debugBackend.sendEvent('DOM.childNodeInserted', JSON.stringify(params));219}220// Report to the frontend when a DOM node is removed.221function _onNodeRemoved(parentNodeId, node) {222 let nodeId = _getNodeId(node);223 if (!parentNodeId || !nodeId) return;224 let params = {225 parentNodeId: parentNodeId,226 nodeId: _getNodeId(node),227 };228 debugBackend.sendEvent('DOM.childNodeRemoved', JSON.stringify(params));229 _removeNode(node);230}231function _onAttributesMutated(mutation) {232 let params = {233 nodeId: _getNodeId(mutation.target),234 name: mutation.attributeName,235 };236 if (mutation.target.hasAttribute(mutation.attributeName)) {237 params.value = mutation.target.getAttribute(mutation.attributeName);238 debugBackend.sendEvent('DOM.attributeModified', JSON.stringify(params));239 } else {240 debugBackend.sendEvent('DOM.attributeRemoved', JSON.stringify(params));241 }242}243function _onCharacterDataMutated(mutation) {244 let nodeId = _getNodeId(mutation.target);245 let parentNodeId = _getNodeId(mutation.target.parentNode);246 // If a node changes to/from whitespace, treat it as inserted/removed.247 if (!nodeId) {248 _onNodeInserted(parentNodeId, mutation.target);249 return;250 } else if (_isWhitespace(mutation.target)) {251 _onNodeRemoved(parentNodeId, mutation.target);252 return;253 }254 let params = {255 nodeId: nodeId,256 characterData: mutation.target.textContent,257 };258 debugBackend.sendEvent('DOM.characterDataModified', JSON.stringify(params));259}...

Full Screen

Full Screen

__FinderViewTree.js

Source:__FinderViewTree.js Github

copy

Full Screen

...34 const _onDragEnd = (results) => {35 const { draggableId, source, destination, combine } = results36 let id, parentId, sourceId, destinationId37 if (source && destination && source.droppableId !== destination.droppableId) {38 id = _getNodeId(draggableId)39 parentId = _getNodeId(destination.droppableId)40 sourceId = _getNodeId(source.droppableId)41 } else if (combine && combine.draggableId !== source.droppableId && draggableId !== combine.draggableId) {42 id = _getNodeId(draggableId)43 parentId = _getNodeId(combine.draggableId)44 sourceId = _getNodeId(source.droppableId)45 }46 if (id && id !== parentId) {47 _onChange({48 id: id,49 parentId: parentId,50 sourceId: sourceId,51 })52 }53 }54 const _onCreate = () => {55 56 }57 const _onChange = () => {58 }59 const _onToggle = () => {60 61 }62 63 const _onSelect = ({url}) => {64 /*65 if (sq) {66 url = url + "?" + qs.stringify(sq);67 }68 url && props.history.push(url)69 const uniqueId = _getNodeId(url)70 uniqueId && getModel(uniqueId)71 */72 }73 // viewOptions74 return (75 <TreeListView 76 treeRoot={treeRoot}77 treeParent={treeParent}78 treeChildren={treeChildren}79 onToggle={_onToggle}80 onSelect={_onSelect}81 onCreate={_onCreate}82 onDragEnd={_onDragEnd} />83 )...

Full Screen

Full Screen

NodeManager.js

Source:NodeManager.js Github

copy

Full Screen

...13 * @param {Node|string} node14 * @returns {boolean}15 */16 static isExist(nodeOrNodeId) {17 return nodesMap.has(this._getNodeId(nodeOrNodeId))18 }19 /**20 * @static21 * @memberof NodeManager22 * @method getNode23 * @param {Node|string} nodeOrNodeId24 * @returns {Node}25 */26 static getNode(nodeOrNodeId) {27 if (!NodeManager.isExist(this._getNodeId(nodeOrNodeId))) {28 throw new Error(29 `The node ${this._getNodeId(nodeOrNodeId)} was not found in NodeManager`30 )31 }32 return nodesMap.get(this._getNodeId(nodeOrNodeId))33 }34 /**35 * @static36 * @memberof NodeManager37 * @method addNode38 * @param {Node} node39 */40 static addNode(node) {41 if (!(node instanceof Node)) return42 nodesMap.set(node.nodeId, node)43 }44 static updateNode = this.addNode45 /**46 * @static47 * @memberof NodeManager48 * @method removeNode DFS 删除分子节点及其所有子节点49 * @param {Node|string} nodeOrNodeId50 * @param {boolean} removeChild 递归删除子节点51 */52 static removeNode(nodeOrNodeId, removeChild = true) {53 let node = NodeManager.getNode(nodeOrNodeId)54 if (!node || !(node instanceof Node)) return55 if (node.childNode && removeChild) {56 NodeManager.removeNode(node.childNode, removeChild)57 }58 nodesMap.delete(node.nodeId)59 if (process.env.NODE_ENV === 'development') {60 console.log(61 'Deleted node.nodeId is: ',62 node.nodeId,63 '\nnodesMap: ',64 nodesMap65 )66 }67 node = null68 }69 static clear() {70 nodesMap.clear()71 }72 /**73 * _getNodeId74 * @private75 * @protected76 * @param {Node|string} nodeOrNodeId77 * @returns {string}78 */79 static _getNodeId(nodeOrNodeId) {80 let nodeId = nodeOrNodeId81 if (nodeOrNodeId instanceof Node) {82 nodeId = nodeOrNodeId.nodeId83 }84 return nodeId85 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = new Chromy();2chromy.chain()3 .evaluate(function() {4 return _getNodeId(document.querySelector('h1'));5 })6 .end()7 .result(function(result) {8 console.log(result);9 })10 .run();

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = new Chromy({ port: 9222 });2chromy.chain()3 .evaluate(function() {4 return _getNodeId(document.querySelector('h1'));5 })6 .result(function(nodeId) {7 console.log(nodeId);8 })9 .end()10 .then(function() {11 chromy.close();12 });13### `chromy.chain().evaluate(function[, args...])`14var chromy = new Chromy({ port: 9222 });15chromy.chain()16 .evaluate(function() {17 return document.querySelector('h1').textContent;18 })19 .result(function(text) {20 console.log(text);21 })22 .end()23 .then(function() {24 chromy.close();25 });26### `chromy.chain().evaluate(function[, args...]).result(function)`27var chromy = new Chromy({ port: 9222 });28chromy.chain()29 .evaluate(function() {30 return document.querySelector('h1').textContent;31 })32 .result(function(text) {33 console.log(text);34 })35 .end()36 .then(function() {37 chromy.close();38 });39### `chromy.chain().evaluate(function[, args...]).end()`40var chromy = new Chromy({ port: 9222 });41chromy.chain()42 .evaluate(function() {43 return document.querySelector('h1').textContent;44 })45 .result(function(text) {46 console.log(text);47 })48 .end()49 .then(function() {50 chromy.close();51 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = new Chromy();2chromy.chain()3 .evaluate(function() {4 return _getNodeId(document.querySelector('input'));5 })6 .result(function(nodeId) {7 console.log(nodeId);8 })9 .end()10 .then(function() {11 console.log('Done');12 chromy.close();13 })14 .catch(function(e) {15 console.log(e);16 chromy.close();17 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var chromy = new Chromy();2chromy.chain()3 .wait('#lst-ib')4 .evaluate(function() {5 return _getNodeId(document.querySelector('#lst-ib'));6 })7 .result(function(id) {8 console.log(id);9 })10 .end()11 .then(function() {12 chromy.close();13 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({visible: true, waitTimeout: 5000, waitInterval: 1000});2chromy.chain()3 .evaluate(() => {4 return document.querySelector('h1').id5 })6 .result(id => {7 console.log(id)8 })9 .end()10 .then(() => chromy.close())11 .catch(e => {12 console.log('error:', e)13 chromy.close()14 })

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = require('chromy')2chromy.chain()3 .evaluate(() => {4 return _getNodeId(document.querySelector('input[name="q"]'))5 })6 .result((nodeId) => {7 console.log(nodeId)8 })9 .end()10 .then(() => {11 console.log('done')12 })

Full Screen

Using AI Code Generation

copy

Full Screen

1const chromy = new Chromy({ port: 9222 });2chromy.evaluate(() => {3 const id = _getNodeId(document.querySelector('#id'));4 console.log(id);5});6chromy.close();7const chromy = new Chromy({ port: 9222, host: '

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chromy automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful