Best JavaScript code snippet using tracetest
css-matched-rules.js
Source:css-matched-rules.js
1/*2 * Copyright 2010-2020 Gildas Lormeau3 * contact : gildas.lormeau <at> gmail.com4 * 5 * This file is part of SingleFile.6 *7 * The code in this file is free software: you can redistribute it and/or 8 * modify it under the terms of the GNU Affero General Public License 9 * (GNU AGPL) as published by the Free Software Foundation, either version 310 * of the License, or (at your option) any later version.11 * 12 * The code in this file is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero 15 * General Public License for more details.16 *17 * As additional permission under GNU AGPL version 3 section 7, you may 18 * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU 19 * AGPL normally required by section 4, provided you include this license 20 * notice and a URL through which recipients can access the Corresponding 21 * Source.22 */23this.singlefile.lib.modules.matchedRules = this.singlefile.lib.modules.matchedRules || (() => {24 const singlefile = this.singlefile;25 const MEDIA_ALL = "all";26 const IGNORED_PSEUDO_ELEMENTS = ["after", "before", "first-letter", "first-line", "placeholder", "selection", "part", "marker"];27 const SINGLE_FILE_HIDDEN_CLASS_NAME = "sf-hidden";28 const DISPLAY_STYLE = "display";29 const REGEXP_VENDOR_IDENTIFIER = /-(ms|webkit|moz|o)-/;30 const DEBUG = false;31 class MatchedRules {32 constructor(doc, stylesheets, styles) {33 this.doc = doc;34 this.mediaAllInfo = createMediaInfo(MEDIA_ALL);35 const matchedElementsCache = new Map();36 let sheetIndex = 0;37 const workStyleElement = doc.createElement("style");38 doc.body.appendChild(workStyleElement);39 stylesheets.forEach(stylesheetInfo => {40 if (!stylesheetInfo.scoped) {41 const cssRules = stylesheetInfo.stylesheet.children;42 if (cssRules) {43 if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {44 const mediaInfo = createMediaInfo(stylesheetInfo.mediaText);45 this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaInfo);46 getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache, workStyleElement);47 } else {48 getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache, workStyleElement);49 }50 }51 }52 sheetIndex++;53 });54 let startTime;55 if (DEBUG) {56 startTime = Date.now();57 log(" -- STARTED sortRules");58 }59 sortRules(this.mediaAllInfo);60 if (DEBUG) {61 log(" -- ENDED sortRules", Date.now() - startTime);62 startTime = Date.now();63 log(" -- STARTED computeCascade");64 }65 computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleElement);66 workStyleElement.remove();67 if (DEBUG) {68 log(" -- ENDED computeCascade", Date.now() - startTime);69 }70 }71 getMediaAllInfo() {72 return this.mediaAllInfo;73 }74 }75 return {76 getMediaAllInfo(doc, stylesheets, styles) {77 return new MatchedRules(doc, stylesheets, styles).getMediaAllInfo();78 }79 };80 function createMediaInfo(media) {81 const mediaInfo = { media: media, elements: new Map(), medias: new Map(), rules: new Map(), pseudoRules: new Map() };82 if (media == MEDIA_ALL) {83 mediaInfo.matchedStyles = new Map();84 }85 return mediaInfo;86 }87 function getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache, workStylesheet) {88 const cssTree = singlefile.lib.vendor.cssTree;89 let mediaIndex = 0;90 let ruleIndex = 0;91 let startTime;92 if (DEBUG && cssRules.length > 1) {93 startTime = Date.now();94 log(" -- STARTED getMatchedElementsRules", " index =", sheetIndex, "rules.length =", cssRules.length);95 }96 cssRules.forEach(ruleData => {97 if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {98 if (ruleData.type == "Atrule" && ruleData.name == "media") {99 const mediaText = cssTree.generate(ruleData.prelude);100 const ruleMediaInfo = createMediaInfo(mediaText);101 mediaInfo.medias.set("rule-" + sheetIndex + "-" + mediaIndex + "-" + mediaText, ruleMediaInfo);102 mediaIndex++;103 getMatchedElementsRules(doc, ruleData.block.children, ruleMediaInfo, sheetIndex, styles, matchedElementsCache, workStylesheet);104 } else if (ruleData.type == "Rule") {105 const selectors = ruleData.prelude.children.toArray();106 const selectorsText = ruleData.prelude.children.toArray().map(selector => cssTree.generate(selector));107 const ruleInfo = { ruleData, mediaInfo, ruleIndex, sheetIndex, matchedSelectors: new Set(), declarations: new Set(), selectors, selectorsText };108 if (!invalidSelector(selectorsText.join(","), workStylesheet)) {109 for (let selector = ruleData.prelude.children.head, selectorIndex = 0; selector; selector = selector.next, selectorIndex++) {110 const selectorText = selectorsText[selectorIndex];111 const selectorInfo = { selector, selectorText, ruleInfo };112 getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCache);113 }114 }115 ruleIndex++;116 }117 }118 });119 if (DEBUG && cssRules.length > 1) {120 log(" -- ENDED getMatchedElementsRules", "delay =", Date.now() - startTime);121 }122 }123 function invalidSelector(selectorText, workStylesheet) {124 workStylesheet.textContent = selectorText + "{}";125 return workStylesheet.sheet ? !workStylesheet.sheet.cssRules.length : workStylesheet.sheet;126 }127 function getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCache) {128 const filteredSelectorText = getFilteredSelector(selectorInfo.selector, selectorInfo.selectorText);129 const selectorText = filteredSelectorText != selectorInfo.selectorText ? filteredSelectorText : selectorInfo.selectorText;130 const cachedMatchedElements = matchedElementsCache.get(selectorText);131 let matchedElements = cachedMatchedElements;132 if (!matchedElements) {133 try {134 matchedElements = doc.querySelectorAll(selectorText);135 if (selectorText != "." + SINGLE_FILE_HIDDEN_CLASS_NAME) {136 matchedElements = Array.from(doc.querySelectorAll(selectorText)).filter(matchedElement =>137 !matchedElement.classList.contains(SINGLE_FILE_HIDDEN_CLASS_NAME) &&138 (matchedElement.style.getPropertyValue(DISPLAY_STYLE) != "none" || matchedElement.style.getPropertyPriority("display") != "important")139 );140 }141 } catch (error) {142 // ignored 143 }144 }145 if (matchedElements) {146 if (!cachedMatchedElements) {147 matchedElementsCache.set(selectorText, matchedElements);148 }149 if (matchedElements.length) {150 if (filteredSelectorText == selectorInfo.selectorText) {151 matchedElements.forEach(element => addRule(element, selectorInfo, styles));152 } else {153 let pseudoSelectors = selectorInfo.ruleInfo.mediaInfo.pseudoRules.get(selectorInfo.ruleInfo.ruleData);154 if (!pseudoSelectors) {155 pseudoSelectors = new Set();156 selectorInfo.ruleInfo.mediaInfo.pseudoRules.set(selectorInfo.ruleInfo.ruleData, pseudoSelectors);157 }158 pseudoSelectors.add(selectorInfo.selectorText);159 }160 }161 }162 }163 function getFilteredSelector(selector, selectorText) {164 const cssTree = singlefile.lib.vendor.cssTree;165 const removedSelectors = [];166 selector = { data: cssTree.parse(cssTree.generate(selector.data), { context: "selector" }) };167 filterPseudoClasses(selector);168 if (removedSelectors.length) {169 removedSelectors.forEach(({ parentSelector, selector }) => {170 if (parentSelector.data.children.getSize() == 0 || !selector.prev || selector.prev.data.type == "Combinator" || selector.prev.data.type == "WhiteSpace") {171 parentSelector.data.children.replace(selector, cssTree.parse("*", { context: "selector" }).children.head);172 } else {173 parentSelector.data.children.remove(selector);174 }175 });176 selectorText = cssTree.generate(selector.data).trim();177 }178 return selectorText;179 function filterPseudoClasses(selector, parentSelector) {180 if (selector.data.children) {181 for (let childSelector = selector.data.children.head; childSelector; childSelector = childSelector.next) {182 filterPseudoClasses(childSelector, selector);183 }184 }185 if ((selector.data.type == "PseudoClassSelector") ||186 (selector.data.type == "PseudoElementSelector" && (testVendorPseudo(selector) || IGNORED_PSEUDO_ELEMENTS.includes(selector.data.name)))) {187 removedSelectors.push({ parentSelector, selector });188 }189 }190 function testVendorPseudo(selector) {191 const name = selector.data.name;192 return name.startsWith("-") || name.startsWith("\\-");193 }194 }195 function addRule(element, selectorInfo, styles) {196 const mediaInfo = selectorInfo.ruleInfo.mediaInfo;197 const elementStyle = styles.get(element);198 let elementInfo = mediaInfo.elements.get(element);199 if (!elementInfo) {200 elementInfo = [];201 if (elementStyle) {202 elementInfo.push({ styleInfo: { styleData: elementStyle, declarations: new Set() } });203 }204 mediaInfo.elements.set(element, elementInfo);205 }206 const specificity = computeSpecificity(selectorInfo.selector.data);207 specificity.ruleIndex = selectorInfo.ruleInfo.ruleIndex;208 specificity.sheetIndex = selectorInfo.ruleInfo.sheetIndex;209 selectorInfo.specificity = specificity;210 elementInfo.push(selectorInfo);211 }212 function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet) {213 mediaInfo.elements.forEach((elementInfo/*, element*/) =>214 getDeclarationsInfo(elementInfo, workStylesheet/*, element*/).forEach((declarationsInfo, property) => {215 if (declarationsInfo.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {216 let info;217 if (declarationsInfo.selectorInfo.ruleInfo) {218 info = declarationsInfo.selectorInfo.ruleInfo;219 const ruleData = info.ruleData;220 const ascendantMedia = [mediaInfo, ...parentMediaInfo].find(media => media.rules.get(ruleData)) || mediaInfo;221 ascendantMedia.rules.set(ruleData, info);222 if (ruleData) {223 info.matchedSelectors.add(declarationsInfo.selectorInfo.selectorText);224 }225 } else {226 info = declarationsInfo.selectorInfo.styleInfo;227 const styleData = info.styleData;228 const matchedStyleInfo = mediaAllInfo.matchedStyles.get(styleData);229 if (!matchedStyleInfo) {230 mediaAllInfo.matchedStyles.set(styleData, info);231 }232 }233 if (!info.declarations.has(property)) {234 info.declarations.add(property);235 }236 }237 }));238 delete mediaInfo.elements;239 mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet));240 }241 function getDeclarationsInfo(elementInfo, workStylesheet/*, element*/) {242 const declarationsInfo = new Map();243 const processedProperties = new Set();244 elementInfo.forEach(selectorInfo => {245 let declarations;246 if (selectorInfo.styleInfo) {247 declarations = selectorInfo.styleInfo.styleData.children;248 } else {249 declarations = selectorInfo.ruleInfo.ruleData.block.children;250 }251 processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet);252 });253 return declarationsInfo;254 }255 function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet) {256 const cssTree = singlefile.lib.vendor.cssTree;257 for (let declaration = declarations.tail; declaration; declaration = declaration.prev) {258 const declarationData = declaration.data;259 const declarationText = cssTree.generate(declarationData);260 if (declarationData.type == "Declaration" &&261 (declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText, workStylesheet)) {262 const declarationInfo = declarationsInfo.get(declarationData);263 if (!declarationInfo || (declarationData.important && !declarationInfo.important)) {264 declarationsInfo.set(declarationData, { selectorInfo, important: declarationData.important });265 if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {266 processedProperties.add(declarationData.property);267 }268 }269 }270 }271 }272 function invalidDeclaration(declarationText, workStylesheet) {273 let invalidDeclaration;274 workStylesheet.textContent = "single-file-declaration { " + declarationText + "}";275 if (workStylesheet.sheet && !workStylesheet.sheet.cssRules[0].style.length) {276 if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {277 invalidDeclaration = true;278 }279 }280 return invalidDeclaration;281 }282 function sortRules(media) {283 media.elements.forEach(elementRules => elementRules.sort((ruleInfo1, ruleInfo2) =>284 ruleInfo1.styleInfo && !ruleInfo2.styleInfo ? -1 :285 !ruleInfo1.styleInfo && ruleInfo2.styleInfo ? 1 :286 compareSpecificity(ruleInfo1.specificity, ruleInfo2.specificity)));287 media.medias.forEach(sortRules);288 }289 function computeSpecificity(selector, specificity = { a: 0, b: 0, c: 0 }) {290 if (selector.type == "IdSelector") {291 specificity.a++;292 }293 if (selector.type == "ClassSelector" || selector.type == "AttributeSelector" || (selector.type == "PseudoClassSelector" && selector.name != "not")) {294 specificity.b++;295 }296 if ((selector.type == "TypeSelector" && selector.name != "*") || selector.type == "PseudoElementSelector") {297 specificity.c++;298 }299 if (selector.children) {300 selector.children.forEach(selector => computeSpecificity(selector, specificity));301 }302 return specificity;303 }304 function compareSpecificity(specificity1, specificity2) {305 if (specificity1.a > specificity2.a) {306 return -1;307 } else if (specificity1.a < specificity2.a) {308 return 1;309 } else if (specificity1.b > specificity2.b) {310 return -1;311 } else if (specificity1.b < specificity2.b) {312 return 1;313 } else if (specificity1.c > specificity2.c) {314 return -1;315 } else if (specificity1.c < specificity2.c) {316 return 1;317 } else if (specificity1.sheetIndex > specificity2.sheetIndex) {318 return -1;319 } else if (specificity1.sheetIndex < specificity2.sheetIndex) {320 return 1;321 } else if (specificity1.ruleIndex > specificity2.ruleIndex) {322 return -1;323 } else if (specificity1.ruleIndex < specificity2.ruleIndex) {324 return 1;325 } else {326 return -1;327 }328 }329 function log(...args) {330 console.log("S-File <css-mat>", ...args); // eslint-disable-line no-console331 }...
main.js
Source:main.js
1/*2 * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions:10 * 11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE.21 * 22 */23/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */24/*global define, $, brackets */25define(function (require, exports, module) {26 "use strict";27 var EditorManager = brackets.getModule("editor/EditorManager"),28 QuickOpen = brackets.getModule("search/QuickOpen"),29 CSSUtils = brackets.getModule("language/CSSUtils"),30 DocumentManager = brackets.getModule("document/DocumentManager");31 /**32 * Returns a list of information about selectors for a single document. This array is populated33 * by createSelectorList()34 * @return {?Array.<FileLocation>}35 */36 function createSelectorList() {37 var doc = DocumentManager.getCurrentDocument();38 if (!doc) {39 return;40 }41 var selectorList = [];42 var docText = doc.getText();43 return CSSUtils.extractAllSelectors(docText);44 }45 /**46 * @param {string} query what the user is searching for47 * @returns {Array.<SearchResult>} sorted and filtered results that match the query48 */49 function search(query, matcher) {50 var selectorList = matcher.selectorList;51 if (!selectorList) {52 selectorList = createSelectorList();53 matcher.selectorList = selectorList;54 }55 query = query.slice(query.indexOf("@") + 1, query.length);56 57 // Filter and rank how good each match is58 var filteredList = $.map(selectorList, function (itemInfo) {59 var searchResult = matcher.match(itemInfo.selector, query);60 if (searchResult) {61 searchResult.selectorInfo = itemInfo;62 }63 return searchResult;64 });65 66 // Sort based on ranking & basic alphabetical order67 QuickOpen.basicMatchSort(filteredList);68 return filteredList;69 }70 /**71 * @param {string} query what the user is searching for72 * @param {boolean} returns true if this plugin wants to provide results for this query73 */74 function match(query) {75 // TODO: match any location of @ when QuickOpen._handleItemFocus() is modified to76 // dynamic open files77 //if (query.indexOf("@") !== -1) {78 if (query.indexOf("@") === 0) {79 return true;80 }81 }82 /**83 * Select the selected item in the current document84 * @param {?SearchResult} selectedItem85 */86 function itemFocus(selectedItem) {87 if (!selectedItem) {88 return;89 }90 var selectorInfo = selectedItem.selectorInfo;91 var from = {line: selectorInfo.selectorStartLine, ch: selectorInfo.selectorStartChar};92 var to = {line: selectorInfo.selectorStartLine, ch: selectorInfo.selectorEndChar};93 EditorManager.getCurrentFullEditor().setSelection(from, to, true);94 }95 function itemSelect(selectedItem) {96 itemFocus(selectedItem);97 }98 QuickOpen.addQuickOpenPlugin(99 {100 name: "CSS Selectors",101 languageIds: ["css"],102 search: search,103 match: match,104 itemFocus: itemFocus,105 itemSelect: itemSelect106 }107 );...
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = new tracetest.Trace();3trace.selectorInfo('a');4var tracetest = require('tracetest');5var trace = new tracetest.Trace();6trace.selectorInfo('a');7var tracetest = require('tracetest');8var trace = new tracetest.Trace();9trace.selectorInfo('a');10var tracetest = require('tracetest');11var trace = new tracetest.Trace();12trace.selectorInfo('a');13var tracetest = require('tracetest');14var trace = new tracetest.Trace();15trace.selectorInfo('a');16var tracetest = require('tracetest');17var trace = new tracetest.Trace();18trace.selectorInfo('a');19var tracetest = require('tracetest');20var trace = new tracetest.Trace();21trace.selectorInfo('a');22var tracetest = require('tracetest');23var trace = new tracetest.Trace();24trace.selectorInfo('a');25var tracetest = require('tracetest');26var trace = new tracetest.Trace();27trace.selectorInfo('a');28var tracetest = require('tracetest');29var trace = new tracetest.Trace();30trace.selectorInfo('a');31var tracetest = require('tracetest');32var trace = new tracetest.Trace();33trace.selectorInfo('a');
Using AI Code Generation
1var tracetest = require('tracetest');2var selectorInfo = tracetest.selectorInfo;3var msg = selectorInfo('button');4console.log(msg);5var tracetest = require('tracetest');6var selectorInfo = tracetest.selectorInfo;7var msg = selectorInfo('button');8console.log(msg);9var tracetest = require('tracetest');10var selectorInfo = tracetest.selectorInfo;11var msg = selectorInfo('button');12console.log(msg);13var tracetest = require('tracetest');14var selectorInfo = tracetest.selectorInfo;15var msg = selectorInfo('button');16console.log(msg);17var tracetest = require('tracetest');18var selectorInfo = tracetest.selectorInfo;19var msg = selectorInfo('button');20console.log(msg);21var tracetest = require('tracetest');22var selectorInfo = tracetest.selectorInfo;23var msg = selectorInfo('button');24console.log(msg);25var tracetest = require('tracetest');26var selectorInfo = tracetest.selectorInfo;27var msg = selectorInfo('button');28console.log(msg);29var tracetest = require('tracetest');30var selectorInfo = tracetest.selectorInfo;31var msg = selectorInfo('button');32console.log(msg);33var tracetest = require('tracetest');34var selectorInfo = tracetest.selectorInfo;35var msg = selectorInfo('button');36console.log(msg);37var tracetest = require('tracetest');38var selectorInfo = tracetest.selectorInfo;39var msg = selectorInfo('button');
Using AI Code Generation
1var tracetest = require('tracetest');2var selectorInfo = tracetest.selectorInfo;3 {selector: 'button', type: 'css'},4 {selector: 'button', type: 'xpath'},5 {selector: 'button', type: 'linkText'},6 {selector: 'button', type: 'partialLinkText'},7 {selector: 'button', type: 'name'},8 {selector: 'button', type: 'tagName'},9 {selector: 'button', type: 'className'},10 {selector: 'button', type: 'cssContainingText'},11 {selector: 'button', type: 'xpathContainingText'},12 {selector: 'button', type: 'id'},13 {selector: 'button', type: 'cssContainingText', text: 'click me'},14 {selector: 'button', type: 'xpathContainingText', text: 'click me'},15 {selector: 'button', type: 'cssContainingText', text: 'click me', index: 1},16 {selector: 'button', type: 'xpathContainingText', text: 'click me', index: 1},17 {selector: 'button', type: 'cssContainingText', text: 'click me', index: 2},18 {selector: 'button', type: 'xpathContainingText', text: 'click me', index: 2}19];20selectors.forEach(function (selector) {21 console.log(selectorInfo(selector));22});23exports.config = {24 capabilities: {25 },26 onPrepare: function () {27 browser.driver.manage().window().maximize();28 browser.ignoreSynchronization = true;29 browser.waitForAngular();30 }31};32{ selector: 'button',
Using AI Code Generation
1var tracetest = require('tracetest');2var selectorInfo = tracetest.selectorInfo;3var selector = selectorInfo('a');4console.log(selector);5var tracetest = require('tracetest');6var selectorInfo = tracetest.selectorInfo;7var selector = selectorInfo('a', 'b');8console.log(selector);9var tracetest = require('tracetest');10var selectorInfo = tracetest.selectorInfo;11var selector = selectorInfo('a', 'b', 'c');12console.log(selector);13var tracetest = require('tracetest');14var selectorInfo = tracetest.selectorInfo;15var selector = selectorInfo('a', 'b', 'c', 'd');16console.log(selector);17var tracetest = require('tracetest');18var selectorInfo = tracetest.selectorInfo;19var selector = selectorInfo('a', 'b', 'c', 'd', 'e');20console.log(selector);21var tracetest = require('tracetest');22var selectorInfo = tracetest.selectorInfo;23var selector = selectorInfo('a', 'b', 'c', 'd', 'e', 'f');24console.log(selector);25var tracetest = require('tracetest');26var selectorInfo = tracetest.selectorInfo;27var selector = selectorInfo('a', 'b', 'c', 'd', 'e', 'f', 'g');28console.log(selector);29var tracetest = require('tracetest');30var selectorInfo = tracetest.selectorInfo;
Using AI Code Generation
1var tracetest = require('tracetest');2var selectorInfo = tracetest.selectorInfo;3var selector = selectorInfo('#myId');4console.log(selector);5{ type: 'id', value: 'myId' }6Pseudo Selector Description Example :first-child The selector matches the first child of the parent. :first-child :last-child The selector matches the last child of the parent. :last-child :nth-child(n) The selector matches the nth child of the parent. :nth-child(3) :nth-last-child(n) The selector matches the nth last child of the parent. :nth-last-child(3) :first-of-type The selector matches the first of the same type of the parent. :first-of-type :last-of-type The selector matches the last of the same type of the parent. :last-of-type :nth-of-type(n) The selector matches the nth of the same type of the parent. :nth-of-type(3) :nth-last-of-type(n) The selector matches the nth last of the same type of the parent. :nth-last-of-type(3
Using AI Code Generation
1var traceTest = require('tracetest');2var selectorInfo = traceTest.selectorInfo;3var info = selectorInfo('div#id.class1.class2');4console.log(info);5var traceTest = require('tracetest');6var selectorInfo = traceTest.selectorInfo;7var info = selectorInfo('div#id.class1.class2');8console.log(info);9var traceTest = require('tracetest');10var selectorInfo = traceTest.selectorInfo;11var info = selectorInfo('div#id.class1.class2');12console.log(info);13var traceTest = require('tracetest');14var selectorInfo = traceTest.selectorInfo;15var info = selectorInfo('div#id.class1.class2');16console.log(info);17var traceTest = require('tracetest');18var selectorInfo = traceTest.selectorInfo;19var info = selectorInfo('div#id.class1.class2');20console.log(info);21var traceTest = require('tracetest');22var selectorInfo = traceTest.selectorInfo;23var info = selectorInfo('div#id.class1.class2');24console.log(info);25var traceTest = require('tracetest');26var selectorInfo = traceTest.selectorInfo;27var info = selectorInfo('div#id.class1.class
Using AI Code Generation
1var tracetest = require('tracetest');2exports['test selectorInfo'] = function(assert, done) {3 tracetest.selectorInfo('div').then(function(data) {4 assert.equal(data, 'div', 'selectorInfo works');5 done();6 });7};8require("sdk/test").run(exports);9var tracetest = require('tracetest');10exports['test selectorInfo'] = function(assert, done) {11 tracetest.selectorInfo('div').then(function(data) {12 assert.equal(data, 'div', 'selectorInfo works');13 done();14 });15};16require("sdk/test").run(exports);17var {Cc, Ci} = require("chrome");18var {defer, resolve} = require("sdk/core/promise");19exports.selectorInfo = function(selector) {20 var deferred = defer();21 var window = Cc["@mozilla.org/appshell/window-mediator;1"]22 .getService(Ci.nsIWindowMediator)23 .getMostRecentWindow("navigator:browser");24 var document = window.document;25 var element = document.querySelector(selector);26 deferred.resolve(element.nodeName);27 return deferred.promise;28};29var tracetest = require('tracetest');30exports['test selectorInfo'] = function(assert, done) {31 tracetest.selectorInfo('div').then(function(data) {32 assert.equal(data, 'div', 'selectorInfo works');33 done();34 });35};36require("sdk/test").run(exports);37var {Cc, Ci} = require("chrome");38var {defer, resolve} = require("sdk/core/promise");39exports.selectorInfo = function(selector) {40 var deferred = defer();41 var window = Cc["@mozilla.org/appshell/window-mediator;1"]42 .getService(Ci.nsIWindowMediator)43 .getMostRecentWindow("navigator:browser");44 var document = window.document;45 var element = document.querySelector(selector);46 deferred.resolve(element
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!!