How to use nodeName method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

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

PropertyBinding.tests.js

Source: PropertyBinding.tests.js Github

copy
1/**
2 * @author TristanVALCKE / https://github.com/Itee
3 * @author Anonymous
4 */
5/* global QUnit */
6
7import { PropertyBinding } from '../../../../src/animation/PropertyBinding';
8import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
9import { Mesh } from '../../../../src/objects/Mesh';
10import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial';
11
12export default QUnit.module( 'Animation', () => {
13
14	QUnit.module( 'PropertyBinding', () => {
15
16		// INSTANCING
17		QUnit.todo( "Instancing", ( assert ) => {
18
19			assert.ok( false, "everything's gonna be alright" );
20
21		} );
22
23		// STATIC STUFF
24		QUnit.todo( "Composite", ( assert ) => {
25
26			assert.ok( false, "everything's gonna be alright" );
27
28		} );
29
30		QUnit.todo( "create", ( assert ) => {
31
32			assert.ok( false, "everything's gonna be alright" );
33
34		} );
35
36		QUnit.test( 'sanitizeNodeName', ( assert ) => {
37
38			assert.equal(
39				PropertyBinding.sanitizeNodeName( 'valid-name-123_' ),
40				'valid-name-123_',
41				'Leaves valid name intact.'
42			);
43
44			assert.equal(
45				PropertyBinding.sanitizeNodeName( 'space separated name 123_ -' ),
46				'space_separated_name_123__-',
47				'Replaces spaces with underscores.'
48			);
49
50			assert.equal(
51				PropertyBinding.sanitizeNodeName( '"invalid" name %123%_' ),
52				'invalid_name_123_',
53				'Strips invalid characters.'
54			);
55
56		} );
57
58		QUnit.test( 'parseTrackName', ( assert ) => {
59
60			var paths = [
61
62				[
63					'.property',
64					{
65						nodeName: undefined,
66						objectName: undefined,
67						objectIndex: undefined,
68						propertyName: 'property',
69						propertyIndex: undefined
70					}
71				],
72
73				[
74					'nodeName.property',
75					{
76						nodeName: 'nodeName',
77						objectName: undefined,
78						objectIndex: undefined,
79						propertyName: 'property',
80						propertyIndex: undefined
81					}
82				],
83
84				[
85					'a.property',
86					{
87						nodeName: 'a',
88						objectName: undefined,
89						objectIndex: undefined,
90						propertyName: 'property',
91						propertyIndex: undefined
92					}
93				],
94
95				[
96					'no.de.Name.property',
97					{
98						nodeName: 'no.de.Name',
99						objectName: undefined,
100						objectIndex: undefined,
101						propertyName: 'property',
102						propertyIndex: undefined
103					}
104				],
105
106				[
107					'no.d-e.Name.property',
108					{
109						nodeName: 'no.d-e.Name',
110						objectName: undefined,
111						objectIndex: undefined,
112						propertyName: 'property',
113						propertyIndex: undefined
114					}
115				],
116
117				[
118					'nodeName.property[accessor]',
119					{
120						nodeName: 'nodeName',
121						objectName: undefined,
122						objectIndex: undefined,
123						propertyName: 'property',
124						propertyIndex: 'accessor'
125					}
126				],
127
128				[
129					'nodeName.material.property[accessor]',
130					{
131						nodeName: 'nodeName',
132						objectName: 'material',
133						objectIndex: undefined,
134						propertyName: 'property',
135						propertyIndex: 'accessor'
136					}
137				],
138
139				[
140					'no.de.Name.material.property',
141					{
142						nodeName: 'no.de.Name',
143						objectName: 'material',
144						objectIndex: undefined,
145						propertyName: 'property',
146						propertyIndex: undefined
147					}
148				],
149
150				[
151					'no.de.Name.material[materialIndex].property',
152					{
153						nodeName: 'no.de.Name',
154						objectName: 'material',
155						objectIndex: 'materialIndex',
156						propertyName: 'property',
157						propertyIndex: undefined
158					}
159				],
160
161				[
162					'uuid.property[accessor]',
163					{
164						nodeName: 'uuid',
165						objectName: undefined,
166						objectIndex: undefined,
167						propertyName: 'property',
168						propertyIndex: 'accessor'
169					}
170				],
171
172				[
173					'uuid.objectName[objectIndex].propertyName[propertyIndex]',
174					{
175						nodeName: 'uuid',
176						objectName: 'objectName',
177						objectIndex: 'objectIndex',
178						propertyName: 'propertyName',
179						propertyIndex: 'propertyIndex'
180					}
181				],
182
183				[
184					'parentName/nodeName.property',
185					{
186						// directoryName is currently unused.
187						nodeName: 'nodeName',
188						objectName: undefined,
189						objectIndex: undefined,
190						propertyName: 'property',
191						propertyIndex: undefined
192					}
193				],
194
195				[
196					'parentName/no.de.Name.property',
197					{
198						// directoryName is currently unused.
199						nodeName: 'no.de.Name',
200						objectName: undefined,
201						objectIndex: undefined,
202						propertyName: 'property',
203						propertyIndex: undefined
204					}
205				],
206
207				[
208					'parentName/parentName/nodeName.property[index]',
209					{
210						// directoryName is currently unused.
211						nodeName: 'nodeName',
212						objectName: undefined,
213						objectIndex: undefined,
214						propertyName: 'property',
215						propertyIndex: 'index'
216					}
217				],
218
219				[
220					'.bone[Armature.DEF_cog].position',
221					{
222						nodeName: undefined,
223						objectName: 'bone',
224						objectIndex: 'Armature.DEF_cog',
225						propertyName: 'position',
226						propertyIndex: undefined
227					}
228				],
229
230				[
231					'scene:helium_balloon_model:helium_balloon_model.position',
232					{
233						nodeName: 'helium_balloon_model',
234						objectName: undefined,
235						objectIndex: undefined,
236						propertyName: 'position',
237						propertyIndex: undefined
238					}
239				]
240			];
241
242			paths.forEach( function ( path ) {
243
244				assert.smartEqual(
245					PropertyBinding.parseTrackName( path[ 0 ] ),
246					path[ 1 ],
247					'Parses track name: ' + path[ 0 ]
248				);
249
250			} );
251
252		} );
253
254		QUnit.todo( "findNode", ( assert ) => {
255
256			assert.ok( false, "everything's gonna be alright" );
257
258		} );
259
260		// PUBLIC STUFF
261		QUnit.todo( "BindingType", ( assert ) => {
262
263			assert.ok( false, "everything's gonna be alright" );
264
265		} );
266
267		QUnit.todo( "Versioning", ( assert ) => {
268
269			assert.ok( false, "everything's gonna be alright" );
270
271		} );
272
273		QUnit.todo( "GetterByBindingType", ( assert ) => {
274
275			assert.ok( false, "everything's gonna be alright" );
276
277		} );
278
279		QUnit.todo( "SetterByBindingTypeAndVersioning", ( assert ) => {
280
281			assert.ok( false, "everything's gonna be alright" );
282
283		} );
284
285		QUnit.todo( "getValue", ( assert ) => {
286
287			assert.ok( false, "everything's gonna be alright" );
288
289		} );
290
291		QUnit.test( 'setValue', ( assert ) => {
292
293			var paths = [
294				'.material.opacity',
295				'.material[opacity]'
296			];
297
298			paths.forEach( function ( path ) {
299
300				var originalValue = 0;
301				var expectedValue = 1;
302
303				var geometry = new BoxGeometry();
304				var material = new MeshBasicMaterial();
305				material.opacity = originalValue;
306				var mesh = new Mesh( geometry, material );
307
308				var binding = new PropertyBinding( mesh, path, null );
309				binding.bind();
310
311				assert.equal(
312					material.opacity,
313					originalValue,
314					'Sets property of material with "' + path + '" (pre-setValue)'
315				);
316
317				binding.setValue( [ expectedValue ], 0 );
318				assert.equal(
319					material.opacity,
320					expectedValue,
321					'Sets property of material with "' + path + '" (post-setValue)'
322				);
323
324			} );
325
326		} );
327
328		QUnit.todo( "bind", ( assert ) => {
329
330			assert.ok( false, "everything's gonna be alright" );
331
332		} );
333
334		QUnit.todo( "unbind", ( assert ) => {
335
336			assert.ok( false, "everything's gonna be alright" );
337
338		} );
339
340	} );
341
342} );
343
Full Screen

gentest-go.js

Source: gentest-go.js Github

copy
1/**
2 * Copyright (c) 2014-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8function toValueGo(value) {
9  return value.toString().replace('px','').replace('%','');
10}
11
12function toMethodName(value) {
13  if (value.indexOf('%') >= 0){
14    return 'Percent';
15  } else if(value.indexOf('Auto') >= 0) {
16    return 'Auto';
17  }
18  return '';
19}
20
21function toExportName(name) {
22  name = name.replace(/(\_\w)/g, function(m) { return m[1].toUpperCase(); });
23  if (name.length > 0) {
24    name = name[0].toUpperCase() + name.substring(1);
25  }
26  return name;
27}
28
29var GoEmitter = function() {
30  Emitter.call(this, 'go', '  ');
31};
32
33GoEmitter.prototype = Object.create(Emitter.prototype, {
34  constructor:{value:GoEmitter},
35
36  emitPrologue:{value:function() {}},
37
38  emitTestPrologue:{value:function(name, experiments) {
39    this.push('func Test' + toExportName(name) + '(t *testing.T) {');
40    this.pushIndent();
41
42    this.push('config := NewConfig()')
43    this.push('defer config.Free()')
44    for (var i in experiments) {
45      this.push('config.SetExperimentalFeatureEnabled(Experiment' + experiments[i] +', true)');
46    }
47    this.push('');
48  }},
49
50  emitTestTreePrologue:{value:function(nodeName) {
51    this.push(nodeName + ' := NewNodeWithConfig(config)');
52    this.push('defer ' +nodeName + '.Free()')
53  }},
54
55  emitTestEpilogue:{value:function(experiments) {
56    this.popIndent();
57    this.push('}');
58    this.push('');
59  }},
60
61  emitEpilogue:{value:function(lines) {}},
62
63  AssertEQ:{value:function(v0, v1) {
64    this.push('assert.EqualValues(t, ' + v0 + ', ' + v1 + ')');
65  }},
66
67  YGAlignAuto:{value:'AlignAuto'},
68  YGAlignCenter:{value:'AlignCenter'},
69  YGAlignFlexEnd:{value:'AlignFlexEnd'},
70  YGAlignFlexStart:{value:'AlignFlexStart'},
71  YGAlignStretch:{value:'AlignStretch'},
72  YGAlignSpaceBetween:{value:'AlignSpaceBetween'},
73  YGAlignSpaceAround:{value:'AlignSpaceAround'},
74  YGAlignBaseline:{value:'AlignBaseline'},
75
76  YGDirectionInherit:{value:'DirectionInherit'},
77  YGDirectionLTR:{value:'DirectionLTR'},
78  YGDirectionRTL:{value:'DirectionRTL'},
79
80  YGEdgeBottom:{value:'EdgeBottom'},
81  YGEdgeEnd:{value:'EdgeEnd'},
82  YGEdgeLeft:{value:'EdgeLeft'},
83  YGEdgeRight:{value:'EdgeRight'},
84  YGEdgeStart:{value:'EdgeStart'},
85  YGEdgeTop:{value:'EdgeTop'},
86
87  YGFlexDirectionColumn:{value:'FlexDirectionColumn'},
88  YGFlexDirectionColumnReverse:{value:'FlexDirectionColumnReverse'},
89  YGFlexDirectionRow:{value:'FlexDirectionRow'},
90  YGFlexDirectionRowReverse:{value:'FlexDirectionRowReverse'},
91
92  YGJustifyCenter:{value:'JustifyCenter'},
93  YGJustifyFlexEnd:{value:'JustifyFlexEnd'},
94  YGJustifyFlexStart:{value:'JustifyFlexStart'},
95  YGJustifySpaceAround:{value:'JustifySpaceAround'},
96  YGJustifySpaceBetween:{value:'JustifySpaceBetween'},
97  YGJustifySpaceEvenly:{value:'JustifySpaceEvenly'},
98
99  YGOverflowHidden:{value:'OverflowHidden'},
100  YGOverflowVisible:{value:'OverflowVisible'},
101
102  YGPositionTypeAbsolute:{value:'PositionAbsolute'},
103  YGPositionTypeRelative:{value:'PositionRelative'},
104
105  YGUndefined:{value:'Undefined'},
106
107  YGDisplayFlex:{value:'DisplayFlex'},
108  YGDisplayNone:{value:'DisplayNone'},
109  YGAuto:{value:'Auto'},
110
111
112  YGWrapNoWrap:{value:'WrapNone'},
113  YGWrapWrap:{value:'WrapWrap'},
114  YGWrapWrapReverse:{value: 'WrapReverse'},
115
116  YGNodeCalculateLayout:{value:function(node, dir, experiments) {
117    this.push(node + '.Style().SetDirection(' + dir + ')');
118    this.push(node + '.CalculateLayout(Undefined, Undefined, ' + dir +')');
119  }},
120
121  YGNodeInsertChild:{value:function(parentName, nodeName, index) {
122    this.push(parentName + '.InsertChild(' + nodeName + ', ' + index + ')');
123  }},
124
125  YGNodeLayoutGetLeft:{value:function(nodeName) {
126    return nodeName + '.Layout().Left()';
127  }},
128
129  YGNodeLayoutGetTop:{value:function(nodeName) {
130    return nodeName + '.Layout().Top()';
131  }},
132
133  YGNodeLayoutGetWidth:{value:function(nodeName) {
134    return nodeName + '.Layout().Width()';
135  }},
136
137  YGNodeLayoutGetHeight:{value:function(nodeName) {
138    return nodeName + '.Layout().Height()';
139  }},
140
141  YGNodeStyleSetAlignContent:{value:function(nodeName, value) {
142    this.push(nodeName + '.Style().SetAlignContent(' + toValueGo(value) + ')');
143  }},
144
145  YGNodeStyleSetAlignItems:{value:function(nodeName, value) {
146    this.push(nodeName + '.Style().SetAlignItems(' + toValueGo(value) + ')');
147  }},
148
149  YGNodeStyleSetAlignSelf:{value:function(nodeName, value) {
150    this.push(nodeName + '.Style().SetAlignSelf(' + toValueGo(value) + ')');
151  }},
152
153  YGNodeStyleSetBorder:{value:function(nodeName, edge, value) {
154    this.push(nodeName + '.Style().SetBorder(' + edge + ', ' + toValueGo(value) + ')');
155  }},
156
157  YGNodeStyleSetDirection:{value:function(nodeName, value) {
158    this.push(nodeName + '.Style().SetDirection(' + toValueGo(value) + ')');
159  }},
160
161  YGNodeStyleSetDisplay:{value:function(nodeName, value) {
162    this.push(nodeName + '.Style().SetDisplay(' + toValueGo(value) + ')');
163  }},
164
165  YGNodeStyleSetFlexBasis:{value:function(nodeName, value) {
166    this.push(nodeName + '.Style().SetFlexBasis' + toMethodName(value) + '(' + toValueGo(value) + ')');
167  }},
168
169  YGNodeStyleSetFlexDirection:{value:function(nodeName, value) {
170    this.push(nodeName + '.Style().SetFlexDirection(' + toValueGo(value) + ')');
171  }},
172
173  YGNodeStyleSetFlexGrow:{value:function(nodeName, value) {
174    this.push(nodeName + '.Style().SetFlexGrow(' + toValueGo(value) + ')');
175  }},
176
177  YGNodeStyleSetFlexShrink:{value:function(nodeName, value) {
178    this.push(nodeName + '.Style().SetFlexShrink(' + toValueGo(value) + ')');
179  }},
180
181  YGNodeStyleSetFlexWrap:{value:function(nodeName, value) {
182    this.push(nodeName + '.Style().SetFlexWrap(' + toValueGo(value) + ')');
183  }},
184
185  YGNodeStyleSetHeight:{value:function(nodeName, value) {
186    this.push(nodeName + '.Style().SetHeight' + toMethodName(value) + '(' + toValueGo(value) + ')');
187  }},
188
189  YGNodeStyleSetJustifyContent:{value:function(nodeName, value) {
190    this.push(nodeName + '.Style().SetJustifyContent(' + toValueGo(value) + ')');
191  }},
192
193  YGNodeStyleSetMargin:{value:function(nodeName, edge, value) {
194    var valueStr = toValueGo(value);
195    if (valueStr != 'Auto') {
196      valueStr = ', ' + valueStr + '';
197    } else {
198      valueStr = '';
199    }
200
201    this.push(nodeName + '.Style().SetMargin' + toMethodName(value) + '(' + edge + valueStr + ')');
202  }},
203
204  YGNodeStyleSetMaxHeight:{value:function(nodeName, value) {
205    this.push(nodeName + '.Style().SetMaxHeight' + toMethodName(value) + '(' + toValueGo(value) + ')');
206  }},
207
208  YGNodeStyleSetMaxWidth:{value:function(nodeName, value) {
209    this.push(nodeName + '.Style().SetMaxWidth' + toMethodName(value) + '(' + toValueGo(value) + ')');
210  }},
211
212  YGNodeStyleSetMinHeight:{value:function(nodeName, value) {
213    this.push(nodeName + '.Style().SetMinHeight' + toMethodName(value) + '(' + toValueGo(value) + ')');
214  }},
215
216  YGNodeStyleSetMinWidth:{value:function(nodeName, value) {
217    this.push(nodeName + '.Style().SetMinWidth' + toMethodName(value) + '(' + toValueGo(value) + ')');
218  }},
219
220  YGNodeStyleSetOverflow:{value:function(nodeName, value) {
221    this.push(nodeName + '.Style().SetOverflow(' + toValueGo(value) + ')');
222  }},
223
224  YGNodeStyleSetPadding:{value:function(nodeName, edge, value) {
225    this.push(nodeName + '.Style().SetPadding' + toMethodName(value) + '(' + edge + ', ' + toValueGo(value) + ')');
226  }},
227
228  YGNodeStyleSetPosition:{value:function(nodeName, edge, value) {
229    this.push(nodeName + '.Style().SetPosition' + toMethodName(value) + '(' + edge + ', ' + toValueGo(value) + ')');
230  }},
231
232  YGNodeStyleSetPositionType:{value:function(nodeName, value) {
233    this.push(nodeName + '.Style().SetPositionType(' + toValueGo(value) + ')');
234  }},
235
236  YGNodeStyleSetWidth:{value:function(nodeName, value) {
237    this.push(nodeName + '.Style().SetWidth' + toMethodName(value) + '(' + toValueGo(value) + ')');
238  }},
239});
Full Screen

nodereplacechild30.js

Source: nodereplacechild30.js Github

copy
1
2/*
3Copyright © 2001-2004 World Wide Web Consortium, 
4(Massachusetts Institute of Technology, European Research Consortium 
5for Informatics and Mathematics, Keio University). All 
6Rights Reserved. This work is distributed under the W3C® Software License [1] in the 
7hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
8the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
9
10[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
11*/
12
13
14
15   /**
16    *  Gets URI that identifies the test.
17    *  @return uri identifier of test
18    */
19function getTargetURI() {
20      return "http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild30";
21   }
22
23var docsLoaded = -1000000;
24var builder = null;
25
26//
27//   This function is called by the testing framework before
28//      running the test suite.
29//
30//   If there are no configuration exceptions, asynchronous
31//        document loading is started.  Otherwise, the status
32//        is set to complete and the exception is immediately
33//        raised when entering the body of the test.
34//
35function setUpPage() {
36   setUpPageStatus = 'running';
37   try {
38     //
39     //   creates test document builder, may throw exception
40     //
41     builder = createConfiguredBuilder();
42
43      docsLoaded = 0;
44      
45      var docRef = null;
46      if (typeof(this.doc) != 'undefined') {
47        docRef = this.doc;
48      }
49      docsLoaded += preload(docRef, "doc", "hc_staff");
50        
51       if (docsLoaded == 1) {
52          setUpPageStatus = 'complete';
53       }
54    } catch(ex) {
55    	catchInitializationError(builder, ex);
56        setUpPageStatus = 'complete';
57    }
58}
59
60
61
62//
63//   This method is called on the completion of 
64//      each asychronous load started in setUpTests.
65//
66//   When every synchronous loaded document has completed,
67//      the page status is changed which allows the
68//      body of the test to be executed.
69function loadComplete() {
70    if (++docsLoaded == 1) {
71        setUpPageStatus = 'complete';
72    }
73}
74
75
76/**
77* 
78
79
80
81	Using replaceChild on an Element node attempt to replace a new Element child node with 
82	new child nodes and vice versa and in each case verify the name of the replaced node.
83
84* @author IBM
85* @author Neil Delima
86* @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ID-785887307
87*/
88function nodereplacechild30() {
89   var success;
90    if(checkInitialization(builder, "nodereplacechild30") != null) return;
91    var doc;
92      var parent;
93      var oldChild;
94      var newElement;
95      var newText;
96      var newComment;
97      var newPI;
98      var newCdata;
99      var newERef;
100      var replaced;
101      var nodeName;
102      var appendedChild;
103      
104      var docRef = null;
105      if (typeof(this.doc) != 'undefined') {
106        docRef = this.doc;
107      }
108      doc = load(docRef, "doc", "hc_staff");
109      parent = doc.createElementNS("http://www.w3.org/1999/xhtml","xhtml:html");
110      oldChild = doc.createElementNS("http://www.w3.org/1999/xhtml","xhtml:head");
111      newElement = doc.createElementNS("http://www.w3.org/1999/xhtml","xhtml:body");
112      appendedChild = parent.appendChild(oldChild);
113      appendedChild = parent.appendChild(newElement);
114      newText = doc.createTextNode("Text");
115      appendedChild = parent.appendChild(newText);
116      newComment = doc.createComment("Comment");
117      appendedChild = parent.appendChild(newComment);
118      newPI = doc.createProcessingInstruction("target","data");
119      appendedChild = parent.appendChild(newPI);
120      newCdata = doc.createCDATASection("Cdata");
121      appendedChild = parent.appendChild(newCdata);
122      newERef = doc.createEntityReference("delta");
123      appendedChild = parent.appendChild(newERef);
124      replaced = parent.replaceChild(newElement,oldChild);
125      nodeName = replaced.nodeName;
126
127      assertEquals("nodereplacechild30_1","xhtml:head",nodeName);
128       replaced = parent.replaceChild(oldChild,newElement);
129      nodeName = replaced.nodeName;
130
131      assertEquals("nodereplacechild30_2","xhtml:body",nodeName);
132       replaced = parent.replaceChild(newText,oldChild);
133      nodeName = replaced.nodeName;
134
135      assertEquals("nodereplacechild30_3","xhtml:head",nodeName);
136       replaced = parent.replaceChild(oldChild,newText);
137      nodeName = replaced.nodeName;
138
139      assertEquals("nodereplacechild30_4","#text",nodeName);
140       replaced = parent.replaceChild(newComment,oldChild);
141      nodeName = replaced.nodeName;
142
143      assertEquals("nodereplacechild30_5","xhtml:head",nodeName);
144       replaced = parent.replaceChild(oldChild,newComment);
145      nodeName = replaced.nodeName;
146
147      assertEquals("nodereplacechild30_6","#comment",nodeName);
148       replaced = parent.replaceChild(oldChild,newPI);
149      nodeName = replaced.nodeName;
150
151      assertEquals("nodereplacechild30_7","target",nodeName);
152       replaced = parent.replaceChild(oldChild,newCdata);
153      nodeName = replaced.nodeName;
154
155      assertEquals("nodereplacechild30_8","#cdata-section",nodeName);
156       replaced = parent.replaceChild(oldChild,newERef);
157      nodeName = replaced.nodeName;
158
159      assertEquals("nodereplacechild30_9","delta",nodeName);
160       
161}
162
163
164
165
166function runTest() {
167   nodereplacechild30();
168}
169
Full Screen

xmltojson.js

Source: xmltojson.js Github

copy
1function xmlToJson(xml) {
2    
3
4    var obj = {}, i, j, attribute, item, nodeName, old;
5
6    if (xml.nodeType === 1) { // element
7        // do attributes
8        if (xml.attributes.length > 0) {
9            obj["@attributes"] = {};
10            for (j = 0; j < xml.attributes.length; j = j + 1) {
11                attribute = xml.attributes.item(j);
12                obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
13            }
14        }
15    } else if (xml.nodeType === 3) { // text
16        obj = xml.nodeValue.trim();
17    }
18
19    // do children
20    if (xml.hasChildNodes()) {
21        for (i = 0; i < xml.childNodes.length; i = i + 1) {
22            item = xml.childNodes.item(i);
23            nodeName = item.nodeName;
24            if ((obj[nodeName]) === undefined) {
25                obj[nodeName] = xmlToJson(item);
26            } else {
27                if ((obj[nodeName].push) === undefined) {
28                    old = obj[nodeName];
29                    obj[nodeName] = [];
30                    obj[nodeName].push(old);
31                }
32                obj[nodeName].push(xmlToJson(item));
33            }
34        }
35    }
36    return obj;
37};
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 Cypress 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)