Best JavaScript code snippet using chromeless
Serializer.js
Source:Serializer.js
1var DOM = tinymce.DOM;2module("tinymce.dom.Serializer", {3 setupModule: function() {4 document.getElementById('view').innerHTML = '<div id="content"><div id="test"></div></div>';5 }6});7test('Schema rules', function() {8 var ser = new tinymce.dom.Serializer({fix_list_elements : true});9 expect(8);10 ser.setRules('@[id|title|class|style],div,img[src|alt|-style|border],span,hr');11 DOM.setHTML('test', '<img title="test" src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" alt="test" border="0" style="border: 1px solid red" class="test" /><span id="test2">test</span><hr />');12 equal(ser.serialize(DOM.get('test')), '<div id="test"><img title="test" class="test" src="tinymce/ui/img/raster.gif" alt="test" border="0" /><span id="test2">test</span><hr /></div>', 'Global rule');13 ser.setRules('*a[*],em/i[*],strong/b[*i*]');14 DOM.setHTML('test', '<a href="test" data-mce-href="test">test</a><strong title="test" class="test">test2</strong><em title="test">test3</em>');15 equal(ser.serialize(DOM.get('test')), '<a href="test">test</a><strong title="test">test2</strong><em title="test">test3</em>', 'Wildcard rules');16 ser.setRules('br,hr,input[type|name|value],div[id],span[id],strong/b,a,em/i,a[!href|!name],img[src|border=0|title={$uid}]');17 DOM.setHTML('test', '<br /><hr /><input type="text" name="test" value="val" class="no" /><span id="test2" class="no"><b class="no">abc</b><em class="no">123</em></span>123<a href="file.html" data-mce-href="file.html">link</a><a name="anchor"></a><a>no</a><img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" />');18 equal(ser.serialize(DOM.get('test')), '<div id="test"><br /><hr /><input type="text" name="test" value="val" /><span id="test2"><strong>abc</strong><em>123</em></span>123<a href="file.html">link</a><a name="anchor"></a>no<img src="tinymce/ui/img/raster.gif" border="0" title="mce_0" /></div>', 'Output name and attribute rules');19 ser.setRules('a[href|target<_blank?_top|title:forced value]');20 DOM.setHTML('test', '<a href="file.htm" data-mce-href="file.htm" target="_blank" title="title">link</a><a href="#" data-mce-href="#" target="test">test2</a>');21 equal(ser.serialize(DOM.get('test')), '<a href="file.htm" target="_blank" title="forced value">link</a><a href="#" title="forced value">test2</a>');22 ser.setRules('img[src|border=0|alt=]');23 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" border="0" alt="" />');24 equal(ser.serialize(DOM.get('test')), '<img src="tinymce/ui/img/raster.gif" border="0" alt="" />', 'Default attribute with empty value');25 ser.setRules('img[src|border=0|alt=],*[*]');26 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" /><hr />');27 equal(ser.serialize(DOM.get('test')), '<div id="test"><img src="tinymce/ui/img/raster.gif" border="0" alt="" /><hr /></div>');28 ser = new tinymce.dom.Serializer({29 valid_elements : 'img[src|border=0|alt=]',30 extended_valid_elements : 'div[id],img[src|alt=]'31 });32 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" alt="" />');33 equal(ser.serialize(DOM.get('test')), '<div id="test"><img src="tinymce/ui/img/raster.gif" alt="" /></div>');34 ser = new tinymce.dom.Serializer({invalid_elements : 'hr,br'});35 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" /><hr /><br />');36 equal(ser.serialize(DOM.get('test')), '<div id="test"><img src="tinymce/ui/img/raster.gif" alt="" /></div>');37});38test('Entity encoding', function() {39 var ser;40 expect(4);41 ser = new tinymce.dom.Serializer({entity_encoding : 'numeric'});42 DOM.setHTML('test', '<>&" åäö');43 equal(ser.serialize(DOM.get('test')), '<div id="test"><>&" åäö</div>');44 ser = new tinymce.dom.Serializer({entity_encoding : 'named'});45 DOM.setHTML('test', '<>&" åäö');46 equal(ser.serialize(DOM.get('test')), '<div id="test"><>&" åäö</div>');47 ser = new tinymce.dom.Serializer({entity_encoding : 'named+numeric', entities : '160,nbsp,34,quot,38,amp,60,lt,62,gt'});48 DOM.setHTML('test', '<>&" åäö');49 equal(ser.serialize(DOM.get('test')), '<div id="test"><>&" åäö</div>');50 ser = new tinymce.dom.Serializer({entity_encoding : 'raw'});51 DOM.setHTML('test', '<>&" åäö');52 equal(ser.serialize(DOM.get('test')), '<div id="test"><>&"\u00a0\u00e5\u00e4\u00f6</div>');53});54test('Form elements (general)', function() {55 var ser = new tinymce.dom.Serializer({fix_list_elements : true});56 expect(5);57 ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected],textarea[name|disabled|readonly]');58 DOM.setHTML('test', '<input type="text" />');59 equal(ser.serialize(DOM.get('test')), '<input type="text" />');60 DOM.setHTML('test', '<input type="text" value="text" length="128" maxlength="129" />');61 equal(ser.serialize(DOM.get('test')), '<input type="text" value="text" length="128" maxlength="129" />');62 DOM.setHTML('test', '<form method="post"><input type="hidden" name="method" value="get" /></form>');63 equal(ser.serialize(DOM.get('test')), '<form method="post"><input type="hidden" name="method" value="get" /></form>');64 DOM.setHTML('test', '<label for="test">label</label>');65 equal(ser.serialize(DOM.get('test')), '<label for="test">label</label>');66 DOM.setHTML('test', '<input type="checkbox" value="test" /><input type="button" /><textarea></textarea>');67 // Edge will add an empty input value so remove that to normalize test since it doesn't break anything68 equal(ser.serialize(DOM.get('test')).replace(/ value=""/g, ''), '<input type="checkbox" value="test" /><input type="button" /><textarea></textarea>');69});70test('Form elements (checkbox)', function() {71 var ser = new tinymce.dom.Serializer({fix_list_elements : true});72 expect(4);73 ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected]');74 DOM.setHTML('test', '<input type="checkbox" value="1">');75 equal(ser.serialize(DOM.get('test')), '<input type="checkbox" value="1" />');76 DOM.setHTML('test', '<input type="checkbox" value="1" checked disabled readonly>');77 equal(ser.serialize(DOM.get('test')), '<input type="checkbox" value="1" checked="checked" disabled="disabled" readonly="readonly" />');78 DOM.setHTML('test', '<input type="checkbox" value="1" checked="1" disabled="1" readonly="1">');79 equal(ser.serialize(DOM.get('test')), '<input type="checkbox" value="1" checked="checked" disabled="disabled" readonly="readonly" />');80 DOM.setHTML('test', '<input type="checkbox" value="1" checked="true" disabled="true" readonly="true">');81 equal(ser.serialize(DOM.get('test')), '<input type="checkbox" value="1" checked="checked" disabled="disabled" readonly="readonly" />');82});83test('Form elements (select)', function() {84 var ser = new tinymce.dom.Serializer({fix_list_elements : true});85 expect(7);86 ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected]');87 DOM.setHTML('test', '<select><option value="1">test1</option><option value="2" selected>test2</option></select>');88 equal(ser.serialize(DOM.get('test')), '<select><option value="1">test1</option><option value="2" selected="selected">test2</option></select>');89 DOM.setHTML('test', '<select><option value="1">test1</option><option selected="1" value="2">test2</option></select>');90 equal(ser.serialize(DOM.get('test')), '<select><option value="1">test1</option><option value="2" selected="selected">test2</option></select>');91 DOM.setHTML('test', '<select><option value="1">test1</option><option value="2" selected="true">test2</option></select>');92 equal(ser.serialize(DOM.get('test')), '<select><option value="1">test1</option><option value="2" selected="selected">test2</option></select>');93 DOM.setHTML('test', '<select multiple></select>');94 equal(ser.serialize(DOM.get('test')), '<select multiple="multiple"></select>');95 DOM.setHTML('test', '<select multiple="multiple"></select>');96 equal(ser.serialize(DOM.get('test')), '<select multiple="multiple"></select>');97 DOM.setHTML('test', '<select multiple="1"></select>');98 equal(ser.serialize(DOM.get('test')), '<select multiple="multiple"></select>');99 DOM.setHTML('test', '<select></select>');100 equal(ser.serialize(DOM.get('test')), '<select></select>');101});102test('List elements', function() {103 var ser = new tinymce.dom.Serializer({fix_list_elements : true});104 expect(5);105 ser.setRules('ul[compact],ol,li');106 DOM.setHTML('test', '<ul compact></ul>');107 equal(ser.serialize(DOM.get('test')), '<ul compact="compact"></ul>');108 DOM.setHTML('test', '<ul compact="compact"></ul>');109 equal(ser.serialize(DOM.get('test')), '<ul compact="compact"></ul>');110 DOM.setHTML('test', '<ul compact="1"></ul>');111 equal(ser.serialize(DOM.get('test')), '<ul compact="compact"></ul>');112 DOM.setHTML('test', '<ul></ul>');113 equal(ser.serialize(DOM.get('test')), '<ul></ul>');114 DOM.setHTML('test', '<ol><li>a</li><ol><li>b</li><li>c</li></ol><li>e</li></ol>');115 equal(ser.serialize(DOM.get('test')), '<ol><li>a<ol><li>b</li><li>c</li></ol></li><li>e</li></ol>');116});117test('Tables', function() {118 var ser = new tinymce.dom.Serializer({fix_list_elements : true});119 expect(4);120 ser.setRules('table,tr,td[nowrap]');121 DOM.setHTML('test', '<table><tr><td></td></tr></table>');122 equal(ser.serialize(DOM.get('test')), '<table><tr><td></td></tr></table>');123 DOM.setHTML('test', '<table><tr><td nowrap></td></tr></table>');124 equal(ser.serialize(DOM.get('test')), '<table><tr><td nowrap="nowrap"></td></tr></table>');125 DOM.setHTML('test', '<table><tr><td nowrap="nowrap"></td></tr></table>');126 equal(ser.serialize(DOM.get('test')), '<table><tr><td nowrap="nowrap"></td></tr></table>');127 DOM.setHTML('test', '<table><tr><td nowrap="1"></td></tr></table>');128 equal(ser.serialize(DOM.get('test')), '<table><tr><td nowrap="nowrap"></td></tr></table>');129});130test('Styles', function() {131 var ser = new tinymce.dom.Serializer({fix_list_elements : true});132 expect(1);133 ser.setRules('*[*]');134 DOM.setHTML('test', '<span style="border: 1px solid red" data-mce-style="border: 1px solid red;">test</span>');135 equal(ser.serialize(DOM.get('test')), '<div id="test"><span style="border: 1px solid red;">test</span></div>');136});137test('Comments', function() {138 var ser = new tinymce.dom.Serializer({fix_list_elements : true});139 expect(1);140 ser.setRules('*[*]');141 DOM.setHTML('test', '<!-- abc -->');142 equal(ser.serialize(DOM.get('test')), '<div id="test"><!-- abc --></div>');143});144test('Non HTML elements and attributes', function() {145 var ser = new tinymce.dom.Serializer({fix_list_elements : true});146 expect(2);147 ser.setRules('*[*]');148 ser.schema.addValidChildren('+div[prefix:test]');149 DOM.setHTML('test', '<div test:attr="test">test</div>');150 equal(ser.serialize(DOM.get('test'), {getInner : 1}), '<div test:attr="test">test</div>');151 DOM.setHTML('test', 'test1<prefix:test>Test</prefix:test>test2');152 equal(ser.serialize(DOM.get('test')), '<div id="test">test1<prefix:test>Test</prefix:test>test2</div>');153});154test('Padd empty elements', function() {155 var ser = new tinymce.dom.Serializer({fix_list_elements : true});156 expect(1);157 ser.setRules('#p');158 DOM.setHTML('test', '<p>test</p><p></p>');159 equal(ser.serialize(DOM.get('test')), '<p>test</p><p> </p>');160});161test('Remove empty elements', function() {162 var ser = new tinymce.dom.Serializer({fix_list_elements : true});163 expect(1);164 ser.setRules('-p');165 DOM.setHTML('test', '<p>test</p><p></p>');166 equal(ser.serialize(DOM.get('test')), '<p>test</p>');167});168test('Pre/post process events', function() {169 var ser = new tinymce.dom.Serializer({fix_list_elements : true});170 expect(3);171 ser.setRules('div[id],span[id|class],a[href],b[class]');172 ser.onPreProcess = function(o) {173 equal(o.test, 'abc');174 DOM.setAttrib(o.node.getElementsByTagName('span')[0], 'class', 'abc');175 };176 ser.onPostProcess = function(o) {177 equal(o.test, 'abc');178 o.content = o.content.replace(/<b>/g, '<b class="123">');179 };180 DOM.setHTML('test', '<span id="test2"><b>abc</b></span>123<a href="file.html" data-mce-href="file.html">link</a>');181 equal(ser.serialize(DOM.get('test'), {test : 'abc'}), '<div id="test"><span id="test2" class="abc"><b class="123">abc</b></span>123<a href="file.html">link</a></div>');182});183test('Script with non JS type attribute', 1, function() {184 var ser = new tinymce.dom.Serializer({fix_list_elements : true});185 ser.setRules('script[type|language|src]');186 DOM.setHTML('test', '<s' + 'cript type="mylanguage"></s' + 'cript>');187 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript type="mylanguage"></s' + 'cript>');188});189test('Script with tags inside a comment', 1, function() {190 var ser = new tinymce.dom.Serializer({fix_list_elements : true});191 ser.setRules('script[type|language|src]');192 DOM.setHTML('test', '<s' + 'cript>// <img src="test"><a href="#"></a></s' + 'cript>');193 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n// <img src="test"><a href="#"></a>\n// ]]></s' + 'cript>');194});195test('Script with less than', 1, function() {196 var ser = new tinymce.dom.Serializer({fix_list_elements : true});197 ser.setRules('script[type|language|src]');198 DOM.setHTML('test', '<s' + 'cript>1 < 2;</s' + 'cript>');199 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');200});201test('Script with type attrib and less than', 1, function() {202 var ser = new tinymce.dom.Serializer({fix_list_elements : true});203 ser.setRules('script[type|language|src]');204 DOM.setHTML('test', '<s' + 'cript type="text/javascript">1 < 2;</s' + 'cript>');205 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<script type="text/javascript">// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');206});207test('Script with whitespace in beginning/end', 1, function() {208 var ser = new tinymce.dom.Serializer({fix_list_elements : true});209 ser.setRules('script[type|language|src]');210 DOM.setHTML('test', '<script>\n\t1 < 2;\n\t if (2 < 1)\n\t\talert(1);\n</s' + 'cript>');211 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n\t1 < 2;\n\t if (2 < 1)\n\t\talert(1);\n// ]]></s' + 'cript>');212});213test('Script with a HTML comment and less than', 1, function() {214 var ser = new tinymce.dom.Serializer({fix_list_elements : true});215 ser.setRules('script[type|language|src]');216 DOM.setHTML('test', '<script><!-- 1 < 2; // --></s' + 'cript>');217 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');218});219test('Script with white space in beginning, comment and less than', 1, function() {220 var ser = new tinymce.dom.Serializer({fix_list_elements : true});221 ser.setRules('script[type|language|src]');222 DOM.setHTML('test', '<script>\n\n<!-- 1 < 2;\n\n--></s' + 'cript>');223 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');224});225test('Script with comments and cdata', 1, function() {226 var ser = new tinymce.dom.Serializer({fix_list_elements : true});227 ser.setRules('script[type|language|src]');228 DOM.setHTML('test', '<script>// <![CDATA[1 < 2; // ]]></s' + 'cript>');229 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');230});231test('Script with cdata', 1, function() {232 var ser = new tinymce.dom.Serializer({fix_list_elements : true});233 ser.setRules('script[type|language|src]');234 DOM.setHTML('test', '<script><![CDATA[1 < 2; ]]></s' + 'cript>');235 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');236});237test('Script whitespace in beginning/end and cdata', 1, function() {238 var ser = new tinymce.dom.Serializer({fix_list_elements : true});239 ser.setRules('script[type|language|src]');240 DOM.setHTML('test', '<script>\n\n<![CDATA[\n\n1 < 2;\n\n]]>\n\n</s' + 'cript>');241 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<s' + 'cript>// <![CDATA[\n1 < 2;\n// ]]></s' + 'cript>');242});243test('Script with src attr', 1, function() {244 var ser = new tinymce.dom.Serializer({fix_list_elements : true});245 ser.setRules('script[type|language|src]');246 DOM.setHTML('test', '<script src="test.js" data-mce-src="test.js"></s' + 'cript>');247 equal(ser.serialize(DOM.get('test')), '<s' + 'cript src="test.js"></s' + 'cript>');248});249test('Script with HTML comment, comment and CDATA', 1, function() {250 var ser = new tinymce.dom.Serializer({fix_list_elements : true});251 ser.setRules('script[type|language|src]');252 DOM.setHTML('test', '<script><!--// <![CDATA[var hi = "hello";// ]]>--></s' + 'cript>');253 equal(ser.serialize(DOM.get('test')), '<script>// <![CDATA[\nvar hi = \"hello\";\n// ]]></s' + 'cript>');254});255test('Script with block comment around cdata', 1, function() {256 var ser = new tinymce.dom.Serializer({fix_list_elements : true});257 ser.setRules('script[type|language|src]');258 DOM.setHTML('test', '<script>/* <![CDATA[ */\nvar hi = "hello";\n/* ]]> */</s' + 'cript>');259 equal(ser.serialize(DOM.get('test')), '<script>// <![CDATA[\nvar hi = \"hello\";\n// ]]></s' + 'cript>');260});261test('Script with html comment and block comment around cdata', 1, function() {262 var ser = new tinymce.dom.Serializer({fix_list_elements : true});263 ser.setRules('script[type|language|src]');264 DOM.setHTML('test', '<script><!-- /* <![CDATA[ */\nvar hi = "hello";\n/* ]]>*/--></s' + 'cript>');265 equal(ser.serialize(DOM.get('test')), '<script>// <![CDATA[\nvar hi = \"hello\";\n// ]]></s' + 'cript>');266});267test('Script with line comment and html comment', 1, function() {268 var ser = new tinymce.dom.Serializer({fix_list_elements : true});269 ser.setRules('script[type|language|src]');270 DOM.setHTML('test', '<script>// <!--\nvar hi = "hello";\n// --></s' + 'cript>');271 equal(ser.serialize(DOM.get('test')), '<script>// <![CDATA[\nvar hi = \"hello\";\n// ]]></s' + 'cript>');272});273test('Script with block comment around html comment', 1, function() {274 var ser = new tinymce.dom.Serializer({fix_list_elements : true});275 ser.setRules('script[type|language|src]');276 DOM.setHTML('test', '<script>/* <!-- */\nvar hi = "hello";\n/*-->*/</s' + 'cript>');277 equal(ser.serialize(DOM.get('test')), '<script>// <![CDATA[\nvar hi = \"hello\";\n// ]]></s' + 'cript>');278});279test('Protected blocks', function() {280 var ser = new tinymce.dom.Serializer({fix_list_elements : true});281 expect(3);282 ser.setRules('noscript[test]');283 DOM.setHTML('test', '<!--mce:protected ' + escape('<noscript test="test"><br></noscript>') + '-->');284 equal(ser.serialize(DOM.get('test')), '<noscript test="test"><br></noscript>');285 DOM.setHTML('test', '<!--mce:protected ' + escape('<noscript><br></noscript>') + '-->');286 equal(ser.serialize(DOM.get('test')), '<noscript><br></noscript>');287 DOM.setHTML('test', '<!--mce:protected ' + escape('<noscript><!-- text --><br></noscript>') + '-->');288 equal(ser.serialize(DOM.get('test')), '<noscript><!-- text --><br></noscript>');289});290test('Style with whitespace at beginning', 1, function() {291 var ser = new tinymce.dom.Serializer({fix_list_elements : true, valid_children: '+body[style]'});292 ser.setRules('style');293 DOM.setHTML('test', '<style> body { background:#fff }</style>');294 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<style><!--\n body { background:#fff }\n--></style>');295});296test('Style with cdata', 1, function() {297 var ser = new tinymce.dom.Serializer({fix_list_elements : true, valid_children: '+body[style]'});298 ser.setRules('style');299 DOM.setHTML('test', '<style>\r\n<![CDATA[\r\n body { background:#fff }]]></style>');300 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '<style><!--\nbody { background:#fff }\n--></style>');301});302test('CDATA', function() {303 var ser = new tinymce.dom.Serializer({fix_list_elements : true});304 expect(2);305 ser.setRules('span');306 DOM.setHTML('test', '123<!--[CDATA[<test>]]-->abc');307 equal(ser.serialize(DOM.get('test')), '123<![CDATA[<test>]]>abc');308 DOM.setHTML('test', '123<!--[CDATA[<te\n\nst>]]-->abc');309 equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '123<![CDATA[<te\n\nst>]]>abc');310});311test('BR at end of blocks', function() {312 var ser = new tinymce.dom.Serializer({fix_list_elements : true});313 ser.setRules('ul,li,br');314 DOM.setHTML('test', '<ul><li>test<br /></li><li>test<br /></li><li>test<br /></li></ul>');315 equal(ser.serialize(DOM.get('test')), '<ul><li>test</li><li>test</li><li>test</li></ul>');316});317test('Map elements', function() {318 var ser = new tinymce.dom.Serializer({fix_list_elements : true});319 ser.setRules('map[id|name],area[shape|coords|href|target|alt]');320 DOM.setHTML('test', '<map id="planetmap" name="planetmap"><area shape="rect" coords="0,0,82,126" href="sun.htm" data-mce-href="sun.htm" target="_blank" alt="sun" /></map>');321 equal(ser.serialize(DOM.get('test')).toLowerCase(), '<map id="planetmap" name="planetmap"><area shape="rect" coords="0,0,82,126" href="sun.htm" target="_blank" alt="sun" /></map>');322});323test('Custom elements', function() {324 var ser = new tinymce.dom.Serializer({325 custom_elements: 'custom1,~custom2',326 valid_elements: 'custom1,custom2'327 });328 document.createElement('custom1');329 document.createElement('custom2');330 DOM.setHTML('test', '<p><custom1>c1</custom1><custom2>c2</custom2></p>');331 equal(ser.serialize(DOM.get('test')), '<custom1>c1</custom1><custom2>c2</custom2>');332});333test('Remove internal classes', function() {334 var ser = new tinymce.dom.Serializer({335 valid_elements: 'span[class]'336 });337 DOM.setHTML('test', '<span class="a mce-item-X mce-item-selected b"></span>');338 equal(ser.serialize(DOM.get('test')), '<span class="a b"></span>');339 DOM.setHTML('test', '<span class="a mce-item-X"></span>');340 equal(ser.serialize(DOM.get('test')), '<span class="a"></span>');341 DOM.setHTML('test', '<span class="mce-item-X"></span>');342 equal(ser.serialize(DOM.get('test')), '<span></span>');343 DOM.setHTML('test', '<span class="mce-item-X b"></span>');344 equal(ser.serialize(DOM.get('test')), '<span class=" b"></span>');345 DOM.setHTML('test', '<span class="b mce-item-X"></span>');346 equal(ser.serialize(DOM.get('test')), '<span class="b"></span>');347});348test('Restore tabindex', function() {349 var ser = new tinymce.dom.Serializer({350 valid_elements: 'span[tabindex]'351 });352 DOM.setHTML('test', '<span data-mce-tabindex="42"></span>');353 equal(ser.serialize(DOM.get('test')), '<span tabindex="42"></span>');354});355test('Trailing BR (IE11)', function() {356 var ser = new tinymce.dom.Serializer({357 valid_elements: 'p,br'358 });359 DOM.setHTML('test', '<p>a</p><br><br>');360 equal(ser.serialize(DOM.get('test')), '<p>a</p>');361 DOM.setHTML('test', 'a<br><br>');362 equal(ser.serialize(DOM.get('test')), 'a');...
Using AI Code Generation
1const chromeless = new Chromeless()2 .type('chromeless', 'input[name="q"]')3 .press(13)4 .wait('#resultStats')5 .evaluate(() => document.title)6 .setHtml('input[name="q"]', 'chromeless')7 .press(13)8 .wait('#resultStats')9 .screenshot()10 .end()11const chromeless = new Chromeless()12 .type('chromeless', 'input[name="q"]')13 .press(13)14 .wait('#resultStats')15 .evaluate(() => document.title)16 .click('#resultStats')17 .wait('#resultStats')18 .screenshot()19 .end()20const chromeless = new Chromeless()21 .type('chromeless', 'input[name="q"]')22 .press(13)23 .wait('#resultStats')24 .evaluate(() => document.title)25 .press(13)26 .wait('#resultStats')27 .screenshot()28 .end()29const chromeless = new Chromeless()30 .type('chromeless', 'input[name="q"]')31 .press(13)32 .wait('#resultStats')33 .evaluate(() => document.title)34 .press(13)35 .wait('#resultStats')36 .screenshot()37 .end()38const chromeless = new Chromeless()39 .type('chrome
Using AI Code Generation
1const chromeless = new Chromeless()2 .type('chromeless', 'input[name="q"]')3 .press(13)4 .wait('#resultStats')5 .setHtml('<h1>Hello World</h1>')6 .screenshot()7await chromeless.end()8const chromeless = new Chromeless()9 .type('chromeless', 'input[name="q"]')10 .press(13)11 .wait('#resultStats')12 .setHtml('<h1>Hello World</h1>')13 .screenshot()14await chromeless.end()15const chromeless = new Chromeless()16 .type('chromeless', 'input[name="q"]')17 .press(13)18 .wait('#resultStats')19 .setHtml('<h1>Hello World</h1>')20 .screenshot()21await chromeless.end()22const chromeless = new Chromeless()23 .type('chromeless', 'input[name="q"]')24 .press(13)25 .wait('#resultStats')26 .setHtml('<h1>Hello World</h1>')27 .screenshot()28await chromeless.end()29const chromeless = new Chromeless()30 .type('chromeless', 'input[name="q"]')31 .press(13)32 .wait('#resultStats')33 .setHtml('<h1>Hello World</h1>')34 .screenshot()
Using AI Code Generation
1const chromeless = require('chromeless').default2async function run() {3 const chromeless = new Chromeless()4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .screenshot()8 await chromeless.end()9}10run().catch(console.error.bind(console))11const chromeless = require('chromeless').default12async function run() {13 const chromeless = new Chromeless()14 .type('chromeless', 'input[name="q"]')15 .press(13)16 .wait('#resultStats')17 .screenshot()18 await chromeless.end()19}20run().catch(console.error.bind(console))21const chromeless = require('chromeless').default22async function run() {23 const chromeless = new Chromeless()24 .setHtml('<h1>Hello World</h1>')25 .html()26 await chromeless.end()27}28run().catch(console.error.bind(console))29const chromeless = require('chromeless').default30async function run() {31 const chromeless = new Chromeless()32 .setHtml('<h1>Hello World</h1>')33 .html()34 await chromeless.end()35}36run().catch(console.error.bind(console))37const chromeless = require('chromeless').default38async function run() {
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless;2async function run() {3 const chromeless = new Chromeless();4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .evaluate(() => {8 return document.querySelector('.g').innerText9 })10 .screenshot()11 await chromeless.end()12}13run().catch(console.error.bind(console));14{15 "dependencies": {16 },17 "devDependencies": {},18 "scripts": {19 },20}
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless;2const chromeless = new Chromeless();3 .type('chromeless', 'input[name="q"]')4 .press(13)5 .wait('#resultStats')6 .evaluate(() => {7 })8 .then((title) => {9 console.log('title is:', title)10 })11 .catch((error) => {12 console.error(error)13 })14const puppeteer = require('puppeteer');15(async() => {16 const browser = await puppeteer.launch();17 const page = await browser.newPage();18 await page.type('chromeless', 'input[name="q"]');19 await page.keyboard.press('Enter');20 await page.waitForSelector('#resultStats');21 const title = await page.evaluate(() => document.title);22 console.log('title is:', title);23 await browser.close();24})();
Using AI Code Generation
1var Chromeless = require('chromeless').Chromeless;2var chromeless = new Chromeless();3 .type('chromeless', 'input[name="q"]')4 .press(13)5 .wait('#resultStats')6 .evaluate(() => {7 })8 .then((title) => {9 console.log('The title is:', title)10 })11 .catch((err) => {12 console.error('Something went wrong:', err)13 })14var Chromeless = require('chromeless').Chromeless;15var chromeless = new Chromeless();16 .setHtml('<html><body><h1>Hello World</h1></body></html>')17 .evaluate(() => {18 })19 .then((title) => {20 console.log('The title is:', title)21 })22 .catch((err) => {23 console.error('Something went wrong:', err)24 })25var Chromeless = require('chromeless').Chromeless;26var chromeless = new Chromeless();27 .setHtml('<html><body><h1>Hello World</h1></body></html>')28 .evaluate(() => {29 })30 .then((title) => {31 console.log('The title is:', title)32 })33 .catch((err) => {34 console.error('Something went wrong:', err)35 })36var Chromeless = require('chromeless').Chromeless;37var chromeless = new Chromeless();38 .setHtml('<html><body><h1>Hello World</h1></body></html>')39 .evaluate(() => {40 })41 .then((title) => {42 console.log('The title is:', title)43 })44 .catch((err) => {45 console.error('Something went wrong:', err)46 })47var Chromeless = require('chromeless').Chromeless;48var chromeless = new Chromeless();49 .setHtml('<html><body><h1>Hello World</h1></body></html>')50 .evaluate(() => {51 })52 .then((title) => {53 console.log('The title is:', title)54 })55 .catch((err)
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const chromeless = new Chromeless()3const run = async () => {4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .screenshot()8 await chromeless.end()9}10run().catch(console.error.bind(console))11{12 "scripts": {13 },14 "dependencies": {15 }16}17Copyright (c) 2017 Alex Van Boxel
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const chromeless = new Chromeless()3 .setHtml('<h1>hello world</h1>')4 .html()5 .then(html => console.log(html))6 .catch(console.error)7 .then(() => chromeless.end())8const Chromeless = require('chromeless').Chromeless9const chromeless = new Chromeless()10 .setHtml('<h1>hello world</h1>')11 .html()12 .then(html => console.log(html))13 .catch(console.error)14 .then(() => chromeless.end())15const Chromeless = require('chromeless').Chromeless16const chromeless = new Chromeless()17 .setHtml('<h1>hello world</h1>')18 .html()19 .then(html => console.log(html))20 .catch(console.error)21 .then(() => chromeless.end())22const Chromeless = require('chromeless').Chromeless23const chromeless = new Chromeless()24 .setHtml('<h1>hello world</h1>')25 .html()26 .then(html => console.log(html))27 .catch(console.error)28 .then(() => chromeless.end())29const Chromeless = require('chromeless').Chromeless30const chromeless = new Chromeless()31 .setHtml('<h1>hello world</h1>')32 .html()33 .then(html => console.log(html))34 .catch(console.error)35 .then(() => chromeless.end())36const Chromeless = require('chromeless').Chromeless37const chromeless = new Chromeless()
Using AI Code Generation
1const chromeless = new Chromeless();2const run = async () => {3 .setHtml('<h1>Hello World</h1>')4 .screenshot();5 await chromeless.end();6}7run().catch(console.error.bind(console));8const chromeless = new Chromeless();9const run = async () => {10 .setHtml('<h1>Hello World</h1>')11 .screenshot();12 await chromeless.end();13}14run().catch(console.error.bind(console));15const chromeless = new Chromeless();16const run = async () => {17 .setHtml('<h1>Hello World</h1>')18 .screenshot();19 await chromeless.end();20}21run().catch(console.error.bind(console));
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!