How to use executablePath method in differencify

Best JavaScript code snippet using differencify

renderer.js

Source:renderer.js Github

copy

Full Screen

1'use strict';2window.$ = window.jQuery = require('jquery');3window.Tether = require('tether');4window.Bootstrap = require('bootstrap');5includeHTML();6function updateContent(contentPath) {7 $.when(8 $('#content').html(9 '<div class="col-12" w3-include-html="' + contentPath + '"></div>'10 )11 ).then(includeHTML);12}13// BruteForce Begin14function selectionSortPython() {15 var child = require('child_process').execFile;16 var executablePath = 'python';17 var parameters = [18 'app/bruteForce/python/selectionSort.py',19 '--list',20 $('#list').val()21 ];22 child(executablePath, parameters, function(err, data) {23 $('#result').html(24 data25 .toString()26 .replace(/\[/g, '')27 .replace(/\]/g, '')28 .replace(/,/g, '')29 );30 });31}32function selectionSortCpp() {33 var child = require('child_process').execFile;34 var executablePath = 'app/bruteForce/c++/selectionSort';35 var parameters = [$('#list').val()];36 child(executablePath, parameters, function(err, data) {37 $('#result').html(38 data39 .toString()40 .replace(/\[/g, '')41 .replace(/\]/g, '')42 .replace(/,/g, '')43 );44 });45}46function bubbleSortPython() {47 var child = require('child_process').execFile;48 var executablePath = 'python';49 var parameters = [50 'app/bruteForce/python/bubbleSort.py',51 '--list',52 $('#list').val()53 ];54 child(executablePath, parameters, function(err, data) {55 $('#result').html(56 data57 .toString()58 .replace(/\[/g, '')59 .replace(/\]/g, '')60 .replace(/,/g, '')61 );62 });63}64function bubbleSortCpp() {65 var child = require('child_process').execFile;66 var executablePath = 'app/bruteForce/c++/bubbleSort';67 var parameters = [$('#list').val()];68 child(executablePath, parameters, function(err, data) {69 $('#result').html(70 data71 .toString()72 .replace(/\[/g, '')73 .replace(/\]/g, '')74 .replace(/,/g, '')75 );76 });77}78function stringMatchingPython() {79 var child = require('child_process').execFile;80 var executablePath = 'python';81 var parameters = [82 'app/bruteForce/python/stringMatching.py',83 '--text',84 $('#text').val(),85 '--pattern',86 $('#pattern').val()87 ];88 child(executablePath, parameters, function(err, data) {89 console.log(data);90 $('#result').html(data.toString());91 });92}93function stringMatchingCpp() {94 var child = require('child_process').execFile;95 var executablePath = 'app/bruteForce/c++/stringMatching';96 var parameters = [$('#text').val(), $('#pattern').val()];97 child(executablePath, parameters, function(err, data) {98 console.log(data);99 $('#result').html(data.toString());100 });101}102function polynomialEvaluationPython() {103 var child = require('child_process').execFile;104 var executablePath = 'python';105 var parameters = [106 'app/bruteForce/python/polynomialEvaluation.py',107 '--list',108 $('#list').val(),109 '--x',110 $('#x').val()111 ];112 child(executablePath, parameters, function(err, data) {113 $('#result').html(data.toString());114 });115}116function polynomialEvaluationCpp() {117 var child = require('child_process').execFile;118 var executablePath = 'app/bruteForce/c++/polynomialEvaluation';119 var parameters = [$('#list').val(), $('#x').val()];120 child(executablePath, parameters, function(err, data) {121 $('#result').html(data.toString());122 });123}124function closestPoints() {125 var child = require('child_process').execFile;126 var executablePath = 'python';127 var parameters = [128 'app/bruteForce/python/closestPoints.py',129 '--points',130 $('#points').val()131 ];132 child(executablePath, parameters, function(err, data) {133 $('#result').html(134 data135 .toString()136 .replace('[', '')137 .replace(']', '')138 );139 });140}141// BruteForce End142// DivideAndConquer Begin143function recursiveSumPython() {144 var child = require('child_process').execFile;145 var executablePath = 'python';146 var parameters = [147 'app/divideAndConquer/python/recursiveSum.py',148 '--list',149 $('#list').val()150 ];151 child(executablePath, parameters, function(err, data) {152 $('#result').html(153 data154 .toString()155 .replace('[', '')156 .replace(']', '')157 );158 });159}160function recursiveSumCpp() {161 var child = require('child_process').execFile;162 var executablePath = 'app/divideAndConquer/c++/recursiveSum';163 var parameters = [$('#list').val()];164 child(executablePath, parameters, function(err, data) {165 $('#result').html(166 data167 .toString()168 .replace('[', '')169 .replace(']', '')170 );171 });172}173function mergeSortPython() {174 var child = require('child_process').execFile;175 var executablePath = 'python';176 var parameters = [177 'app/divideAndConquer/python/mergeSort.py',178 '--list',179 $('#list').val()180 ];181 child(executablePath, parameters, function(err, data) {182 $('#result').html(183 data184 .toString()185 .replace('[', '')186 .replace(']', '')187 );188 });189}190function mergeSortCpp() {191 var child = require('child_process').execFile;192 var executablePath = 'app/divideAndConquer/c++/mergeSort';193 var parameters = [$('#list').val()];194 child(executablePath, parameters, function(err, data) {195 $('#result').html(196 data197 .toString()198 .replace('[', '')199 .replace(']', '')200 );201 });202}203function quickSortPython() {204 var child = require('child_process').execFile;205 var executablePath = 'python';206 var parameters = [207 'app/divideAndConquer/python/quickSort.py',208 '--list',209 $('#list').val()210 ];211 child(executablePath, parameters, function(err, data) {212 $('#result').html(213 data214 .toString()215 .replace('[', '')216 .replace(']', '')217 );218 });219}220function quickSortCpp() {221 var child = require('child_process').execFile;222 var executablePath = 'app/divideAndConquer/c++/quickSort';223 var parameters = [$('#list').val()];224 child(executablePath, parameters, function(err, data) {225 $('#result').html(226 data227 .toString()228 .replace('[', '')229 .replace(']', '')230 );231 });232}233function binarySearchPython() {234 var child = require('child_process').execFile;235 var executablePath = 'python';236 var parameters = [237 'app/divideAndConquer/python/binarySearch.py',238 '--list',239 $('#list').val(),240 '--x',241 $('#x').val()242 ];243 child(executablePath, parameters, function(err, data) {244 $('#result').html(245 data246 .toString()247 .replace('[', '')248 .replace(']', '')249 );250 });251}252function binarySearchCpp() {253 var child = require('child_process').execFile;254 var executablePath = 'app/divideAndConquer/c++/binarySearch';255 var parameters = [$('#list').val(), $('#x').val()];256 child(executablePath, parameters, function(err, data) {257 $('#result').html(258 data259 .toString()260 .replace('[', '')261 .replace(']', '')262 );263 });264}265function multiplicationPython() {266 var child = require('child_process').execFile;267 var executablePath = 'python';268 var parameters = [269 'app/divideAndConquer/python/multiplication.py',270 '--x',271 $('#x').val(),272 '--y',273 $('#y').val()274 ];275 child(executablePath, parameters, function(err, data) {276 $('#result').html(277 data278 .toString()279 .replace('[', '')280 .replace(']', '')281 );282 });283}284function multiplicationCpp() {285 var child = require('child_process').execFile;286 var executablePath = 'app/divideAndConquer/c++/multiplication';287 var parameters = [$('#x').val(), $('#y').val()];288 child(executablePath, parameters, function(err, data) {289 $('#result').html(290 data291 .toString()292 .replace('[', '')293 .replace(']', '')294 );295 });296}297// DivideAndConquer End298// DecreaseAndConquer Begin299function insertionSortPython() {300 var child = require('child_process').execFile;301 var executablePath = 'python';302 var parameters = [303 'app/decreaseAndConquer/python/insertionSort.py',304 '--list',305 $('#list').val()306 ];307 child(executablePath, parameters, function(err, data) {308 $('#result').html(309 data310 .toString()311 .replace('[', '')312 .replace(']', '')313 );314 });315}316function insertionSortCpp() {317 var child = require('child_process').execFile;318 var executablePath = 'app/decreaseAndConquer/c++/insertionSort';319 var parameters = [$('#list').val()];320 child(executablePath, parameters, function(err, data) {321 $('#result').html(322 data323 .toString()324 .replace('[', '')325 .replace(']', '')326 );327 });328}329// DecreaseAndConquer End330// DynamicProgramming Begin331function binominalCoefficientPython() {332 var child = require('child_process').execFile;333 var executablePath = 'python';334 var parameters = [335 'app/dynamicProgramming/python/binominalCoefficient.py',336 '--n',337 $('#n').val(),338 '--k',339 $('#k').val()340 ];341 child(executablePath, parameters, function(err, data) {342 $('#result').html(343 data344 .toString()345 .replace('[', '')346 .replace(']', '')347 );348 });349}350function binominalCoefficientCpp() {351 var child = require('child_process').execFile;352 var executablePath = 'app/dynamicProgramming/c++/binominalCoefficient';353 var parameters = [$('#n').val(), $('#k').val()];354 child(executablePath, parameters, function(err, data) {355 $('#result').html(356 data357 .toString()358 .replace('[', '')359 .replace(']', '')360 );361 });362}363function longestCSPython() {364 var child = require('child_process').execFile;365 var executablePath = 'python';366 var parameters = [367 'app/dynamicProgramming/python/longestCS.py',368 '--sequence1',369 $('#sequence1').val(),370 '--sequence2',371 $('#sequence2').val()372 ];373 child(executablePath, parameters, function(err, data) {374 $('#result').html(375 data376 .toString()377 .replace('[', '')378 .replace(']', '')379 );380 });381}382function longestCSCpp() {383 var child = require('child_process').execFile;384 var executablePath = 'app/dynamicProgramming/c++/longestCS';385 var parameters = [$('#sequence1').val(), $('#sequence2').val()];386 child(executablePath, parameters, function(err, data) {387 $('#result').html(388 data389 .toString()390 .replace('[', '')391 .replace(']', '')392 );393 });394}395function shortestCSPython() {396 var child = require('child_process').execFile;397 var executablePath = 'python';398 var parameters = [399 'app/dynamicProgramming/python/shortestCS.py',400 '--sequence1',401 $('#sequence1').val(),402 '--sequence2',403 $('#sequence2').val()404 ];405 child(executablePath, parameters, function(err, data) {406 $('#result').html(407 data408 .toString()409 .replace('[', '')410 .replace(']', '')411 );412 });413}414function shortestCSCpp() {415 var child = require('child_process').execFile;416 var executablePath = 'app/dynamicProgramming/c++/shortestCS';417 var parameters = [$('#sequence1').val(), $('#sequence2').val()];418 child(executablePath, parameters, function(err, data) {419 $('#result').html(420 data421 .toString()422 .replace('[', '')423 .replace(']', '')424 );425 });426}427function knapsackProblemPython() {428 var child = require('child_process').execFile;429 var executablePath = 'python';430 var parameters = [431 'app/dynamicProgramming/python/knapsackProblem.py',432 '--values',433 $('#values').val(),434 '--weights',435 $('#weights').val(),436 '--weight',437 $('#weight').val()438 ];439 child(executablePath, parameters, function(err, data) {440 $('#result').html(441 data442 .toString()443 .replace('[', '')444 .replace(']', '')445 );446 });447}448function knapsackProblemCpp() {449 var child = require('child_process').execFile;450 var executablePath = 'app/dynamicProgramming/c++/knapsackProblem';451 var parameters = [452 $('#values').val(),453 $('#weights').val(),454 $('#weight').val()455 ];456 child(executablePath, parameters, function(err, data) {457 $('#result').html(458 data459 .toString()460 .replace('[', '')461 .replace(']', '')462 );463 });464}465// DynamicProgramming End466// GreedyAlgorithms Begin467function huffmanCodingCpp() {468 var child = require('child_process').execFile;469 var executablePath = 'app/greedyAlgorithms/c++/huffmanCoding';470 var parameters = [$('#characters').val(), $('#frequencies').val()];471 child(executablePath, parameters, function(err, data) {472 $('#result').html(473 data474 .toString()475 .replace('[', '')476 .replace(']', '')477 );478 });479}...

Full Screen

Full Screen

find_chrome_base.js

Source:find_chrome_base.js Github

copy

Full Screen

1/**2 * Copyright 2018 Google Inc. All rights reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the 'License');5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an 'AS IS' BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16'use strict';17const fs = require('fs');18const path = require('path');19const execSync = require('child_process').execSync;20const execFileSync = require('child_process').execFileSync;21const puppeteer = require('puppeteer-core');22const newLineRegex = /\r?\n/;23function darwin(canary) {24 const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' +25 '/Versions/A/Frameworks/LaunchServices.framework' +26 '/Versions/A/Support/lsregister';27 const grepexpr = canary ? 'google chrome canary' : 'google chrome';28 const result =29 execSync(`${LSREGISTER} -dump | grep -i \'${grepexpr}\\?.app$\' | awk \'{$1=""; print $0}\'`);30 const installations = new Set();31 const paths = result.toString().split(newLineRegex).filter(a => a).map(a => a.trim());32 paths.unshift(canary ? '/Applications/Google Chrome Canary.app' : '/Applications/Google Chrome.app');33 for (const p of paths) {34 if (p.startsWith('/Volumes'))35 continue;36 const inst = path.join(p, canary ? '/Contents/MacOS/Google Chrome Canary' : '/Contents/MacOS/Google Chrome');37 if (canAccess(inst))38 return inst;39 }40}41/**42 * Look for linux executables in 3 ways43 * 1. Look into CHROME_PATH env variable44 * 2. Look into the directories where .desktop are saved on gnome based distro's45 * 3. Look for google-chrome-stable & google-chrome executables by using the which command46 */47function linux(canary) {48 let installations = [];49 // Look into the directories where .desktop are saved on gnome based distro's50 const desktopInstallationFolders = [51 path.join(require('os').homedir(), '.local/share/applications/'),52 '/usr/share/applications/',53 ];54 desktopInstallationFolders.forEach(folder => {55 installations = installations.concat(findChromeExecutables(folder));56 });57 // Look for google-chrome(-stable) & chromium(-browser) executables by using the which command58 const executables = [59 'google-chrome-stable',60 'google-chrome',61 'chromium-browser',62 'chromium',63 ];64 executables.forEach(executable => {65 try {66 const chromePath =67 execFileSync('which', [executable], {stdio: 'pipe'}).toString().split(newLineRegex)[0];68 if (canAccess(chromePath))69 installations.push(chromePath);70 } catch (e) {71 // Not installed.72 }73 });74 if (!installations.length)75 throw new Error('The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.');76 const priorities = [77 {regex: /chrome-wrapper$/, weight: 51},78 {regex: /google-chrome-stable$/, weight: 50},79 {regex: /google-chrome$/, weight: 49},80 {regex: /chromium-browser$/, weight: 48},81 {regex: /chromium$/, weight: 47},82 ];83 if (process.env.CHROME_PATH)84 priorities.unshift({regex: new RegExp(`${process.env.CHROME_PATH}`), weight: 101});85 return sort(uniq(installations.filter(Boolean)), priorities)[0];86}87function win32(canary) {88 const suffix = canary ?89 `${path.sep}Google${path.sep}Chrome SxS${path.sep}Application${path.sep}chrome.exe` :90 `${path.sep}Google${path.sep}Chrome${path.sep}Application${path.sep}chrome.exe`;91 const prefixes = [92 process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']93 ].filter(Boolean);94 let result;95 prefixes.forEach(prefix => {96 const chromePath = path.join(prefix, suffix);97 if (canAccess(chromePath))98 result = chromePath;99 });100 return result;101}102function sort(installations, priorities) {103 const defaultPriority = 10;104 return installations105 // assign priorities106 .map(inst => {107 for (const pair of priorities) {108 if (pair.regex.test(inst))109 return {path: inst, weight: pair.weight};110 }111 return {path: inst, weight: defaultPriority};112 })113 // sort based on priorities114 .sort((a, b) => (b.weight - a.weight))115 // remove priority flag116 .map(pair => pair.path);117}118function canAccess(file) {119 if (!file)120 return false;121 try {122 fs.accessSync(file);123 return true;124 } catch (e) {125 return false;126 }127}128function uniq(arr) {129 return Array.from(new Set(arr));130}131function findChromeExecutables(folder) {132 const argumentsRegex = /(^[^ ]+).*/; // Take everything up to the first space133 const chromeExecRegex = '^Exec=\/.*\/(google-chrome|chrome|chromium)-.*';134 const installations = [];135 if (canAccess(folder)) {136 // Output of the grep & print looks like:137 // /opt/google/chrome/google-chrome --profile-directory138 // /home/user/Downloads/chrome-linux/chrome-wrapper %U139 let execPaths;140 // Some systems do not support grep -R so fallback to -r.141 // See https://github.com/GoogleChrome/chrome-launcher/issues/46 for more context.142 try {143 execPaths = execSync(`grep -ER "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);144 } catch (e) {145 execPaths = execSync(`grep -Er "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);146 }147 execPaths = execPaths.toString()148 .split(newLineRegex)149 .map(execPath => execPath.replace(argumentsRegex, '$1'));150 execPaths.forEach(execPath => canAccess(execPath) && installations.push(execPath));151 }152 return installations;153}154/**155 * @return {!Promise<?string>}156 */157async function downloadChromium(options, targetRevision) {158 const browserFetcher = puppeteer.createBrowserFetcher({ path: options.localDataDir });159 const revision = targetRevision || require('puppeteer-core/package.json').puppeteer.chromium_revision;160 const revisionInfo = browserFetcher.revisionInfo(revision);161 // Do nothing if the revision is already downloaded.162 if (revisionInfo.local)163 return revisionInfo;164 // Override current environment proxy settings with npm configuration, if any.165 try {166 console.log(`Downloading Chromium r${revision}...`);167 const newRevisionInfo = await browserFetcher.download(revisionInfo.revision);168 console.log('Chromium downloaded to ' + newRevisionInfo.folderPath);169 let localRevisions = await browserFetcher.localRevisions();170 localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);171 // Remove previous chromium revisions.172 const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));173 await Promise.all(cleanupOldVersions);174 return newRevisionInfo;175 } catch (error) {176 console.error(`ERROR: Failed to download Chromium r${revision}!`);177 console.error(error);178 return null;179 }180}181async function findChrome(options) {182 if (options.executablePath)183 return { executablePath: options.executablePath, type: 'user' };184 const config = new Set(options.channel || ['stable']);185 let executablePath;186 // Always prefer canary.187 if (config.has('canary') || config.has('*')) {188 if (process.platform === 'linux')189 executablePath = linux(true);190 else if (process.platform === 'win32')191 executablePath = win32(true);192 else if (process.platform === 'darwin')193 executablePath = darwin(true);194 if (executablePath)195 return { executablePath, type: 'canary' };196 }197 // Then pick stable.198 if (config.has('stable') || config.has('*')) {199 if (process.platform === 'linux')200 executablePath = linux();201 else if (process.platform === 'win32')202 executablePath = win32();203 else if (process.platform === 'darwin')204 executablePath = darwin();205 if (executablePath)206 return { executablePath, type: 'stable' };207 }208 // always prefer puppeteer revision of chromium209 if (config.has('chromium') || config.has('*')) {210 const revisionInfo = await downloadChromium(options);211 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };212 }213 for (const item of config) {214 if (!item.startsWith('r'))215 continue;216 const revisionInfo = await downloadChromium(options, item.substring(1));217 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };218 }219 return {};220}...

Full Screen

Full Screen

find_chrome_head.js

Source:find_chrome_head.js Github

copy

Full Screen

1/**2 * Copyright 2018 Google Inc. All rights reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the 'License');5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an 'AS IS' BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16'use strict';17const fs = require('fs');18const path = require('path');19const execSync = require('child_process').execSync;20const execFileSync=require('child_process').execFileSync;21const puppeteer = require('puppeteer-core');22const newLineRegex = /\r?\n/;23function darwin(canary) {24 const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' +25 '/Versions/A/Frameworks/LaunchServices.framework' +26 '/Versions/A/Support/lsregister';27 const grepexpr = canary ? 'google chrome canary' : 'google chrome';28 const result =29 execSync(`${LSREGISTER} -dump | grep -i \'${grepexpr}\\?.app$\' | awk \'{$1=""; print $0}\'`);30 const installations = new Set();31 const paths = result.toString().split(newLineRegex).filter(a => a).map(a => a.trim());32 paths.unshift(canary ? '/Applications/Google Chrome Canary.app' : '/Applications/Google Chrome.app');33 for (const p of paths) {34 if (p.startsWith('/Volumes'))35 continue;36 const inst = path.join(p, canary ? '/Contents/MacOS/Google Chrome Canary' : '/Contents/MacOS/Google Chrome');37 if (canAccess(inst))38 return inst;39 }40}41/**42 * Look for linux executables in 3 ways43 * 1. Look into CHROME_PATH env variable44 * 2. Look into the directories where .desktop are saved on gnome based distro's45 * 3. Look for google-chrome-stable & google-chrome executables by using the which command46 */47function linux(canary) {48 let installations = [];49 // Look into the directories where .desktop are saved on gnome based distro's50 const desktopInstallationFolders = [51 path.join(require('os').homedir(), '.local/share/applications/'),52 '/usr/share/applications/',53 ];54 desktopInstallationFolders.forEach(folder => {55 installations = installations.concat(findChromeExecutables(folder));56 });57 // Look for google-chrome(-stable) & chromium(-browser) executables by using the which command58 const executables = [59 'google-chrome-stable',60 'google-chrome',61 'chromium-browser',62 'chromium',63 ];64 executables.forEach(executable => {65 try {66 const chromePath =67 execFileSync('which', [executable], {stdio: 'pipe'}).toString().split(newLineRegex)[0];68 if (canAccess(chromePath))69 installations.push(chromePath);70 } catch (e) {71 // Not installed.72 }73 });74 if (!installations.length)75 throw new Error('The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.');76 const priorities = [77 {regex: /chrome-wrapper$/, weight: 51},78 {regex: /google-chrome-stable$/, weight: 50},79 {regex: /google-chrome$/, weight: 49},80 {regex: /chromium-browser$/, weight: 48},81 {regex: /chromium$/, weight: 47},82 ];83 if (process.env.CHROME_PATH)84 priorities.unshift({regex: new RegExp(`${process.env.CHROME_PATH}`), weight: 101});85 return sort(uniq(installations.filter(Boolean)), priorities)[0];86}87function win32(canary) {88 const suffix = canary ?89 `${path.sep}Google${path.sep}Chrome SxS${path.sep}Application${path.sep}chrome.exe` :90 `${path.sep}Google${path.sep}Chrome${path.sep}Application${path.sep}chrome.exe`;91 const prefixes = [92 process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']93 ].filter(Boolean);94 let result;95 prefixes.forEach(prefix => {96 const chromePath = path.join(prefix, suffix);97 if (canAccess(chromePath))98 result = chromePath;99 });100 return result;101}102function sort(installations, priorities) {103 const defaultPriority = 10;104 return installations105 // assign priorities106 .map(inst => {107 for (const pair of priorities) {108 if (pair.regex.test(inst))109 return {path: inst, weight: pair.weight};110 }111 return {path: inst, weight: defaultPriority};112 })113 // sort based on priorities114 .sort((a, b) => (b.weight - a.weight))115 // remove priority flag116 .map(pair => pair.path);117}118function canAccess(file) {119 if (!file)120 return false;121 try {122 fs.accessSync(file);123 return true;124 } catch (e) {125 return false;126 }127}128function uniq(arr) {129 return Array.from(new Set(arr));130}131function findChromeExecutables(folder) {132 const argumentsRegex = /(^[^ ]+).*/; // Take everything up to the first space133 const chromeExecRegex = '^Exec=\/.*\/(google-chrome|chrome|chromium)-.*';134 const installations = [];135 if (canAccess(folder)) {136 // Output of the grep & print looks like:137 // /opt/google/chrome/google-chrome --profile-directory138 // /home/user/Downloads/chrome-linux/chrome-wrapper %U139 let execPaths;140 // Some systems do not support grep -R so fallback to -r.141 // See https://github.com/GoogleChrome/chrome-launcher/issues/46 for more context.142 try {143 execPaths = execSync(`grep -ER "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);144 } catch (e) {145 execPaths = execSync(`grep -Er "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);146 }147 execPaths = execPaths.toString()148 .split(newLineRegex)149 .map(execPath => execPath.replace(argumentsRegex, '$1'));150 execPaths.forEach(execPath => canAccess(execPath) && installations.push(execPath));151 }152 return installations;153}154/**155 * @return {!Promise<?string>}156 */157async function downloadChromium(options, targetRevision) {158 const browserFetcher = puppeteer.createBrowserFetcher({ path: options.localDataDir });159 const revision = targetRevision || require('puppeteer-core/package.json').puppeteer.chromium_revision;160 const revisionInfo = browserFetcher.revisionInfo(revision);161 // Do nothing if the revision is already downloaded.162 if (revisionInfo.local)163 return revisionInfo;164 // Override current environment proxy settings with npm configuration, if any.165 try {166 console.log(`Downloading Chromium r${revision}...`);167 const newRevisionInfo = await browserFetcher.download(revisionInfo.revision);168 console.log('Chromium downloaded to ' + newRevisionInfo.folderPath);169 let localRevisions = await browserFetcher.localRevisions();170 localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);171 // Remove previous chromium revisions.172 const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));173 await Promise.all(cleanupOldVersions);174 return newRevisionInfo;175 } catch (error) {176 console.error(`ERROR: Failed to download Chromium r${revision}!`);177 console.error(error);178 return null;179 }180}181async function findChrome(options) {182 if (options.executablePath)183 return { executablePath: options.executablePath, type: 'user' };184 const config = new Set(options.channel || ['stable']);185 let executablePath;186 // Always prefer canary.187 if (config.has('canary') || config.has('*')) {188 if (process.platform === 'linux')189 executablePath = linux(true);190 else if (process.platform === 'win32')191 executablePath = win32(true);192 else if (process.platform === 'darwin')193 executablePath = darwin(true);194 if (executablePath)195 return { executablePath, type: 'canary' };196 }197 // Then pick stable.198 if (config.has('stable') || config.has('*')) {199 if (process.platform === 'linux')200 executablePath = linux();201 else if (process.platform === 'win32')202 executablePath = win32();203 else if (process.platform === 'darwin')204 executablePath = darwin();205 if (executablePath)206 return { executablePath, type: 'stable' };207 }208 // always prefer puppeteer revision of chromium209 if (config.has('chromium') || config.has('*')) {210 const revisionInfo = await downloadChromium(options);211 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };212 }213 for (const item of config) {214 if (!item.startsWith('r'))215 continue;216 const revisionInfo = await downloadChromium(options, item.substring(1));217 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };218 }219 return {};220}...

Full Screen

Full Screen

find_chrome.js

Source:find_chrome.js Github

copy

Full Screen

1/**2 * Copyright 2018 Google Inc. All rights reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the 'License');5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an 'AS IS' BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16'use strict';17const fs = require('fs');18const path = require('path');19const execSync = require('child_process').execSync;20const execFileSync = require('child_process').execFileSync;21const puppeteer = require('puppeteer-core');22const newLineRegex = /\r?\n/;23function darwin(canary) {24 const LSREGISTER =25 '/System/Library/Frameworks/CoreServices.framework' +26 '/Versions/A/Frameworks/LaunchServices.framework' +27 '/Versions/A/Support/lsregister';28 const grepexpr = canary ? 'google chrome canary' : 'google chrome';29 const result = execSync(30 `${LSREGISTER} -dump | grep -i \'${grepexpr}\\?.app$\' | awk \'{$1=""; print $0}\'`,31 );32 const installations = new Set();33 const paths = result34 .toString()35 .split(newLineRegex)36 .filter(a => a)37 .map(a => a.trim());38 paths.unshift(39 canary ? '/Applications/Google Chrome Canary.app' : '/Applications/Google Chrome.app',40 );41 for (const p of paths) {42 if (p.startsWith('/Volumes')) continue;43 const inst = path.join(44 p,45 canary ? '/Contents/MacOS/Google Chrome Canary' : '/Contents/MacOS/Google Chrome',46 );47 if (canAccess(inst)) return inst;48 }49}50/**51 * Look for linux executables in 3 ways52 * 1. Look into CHROME_PATH env variable53 * 2. Look into the directories where .desktop are saved on gnome based distro's54 * 3. Look for google-chrome-stable & google-chrome executables by using the which command55 */56function linux(canary) {57 let installations = [];58 // Look into the directories where .desktop are saved on gnome based distro's59 const desktopInstallationFolders = [60 path.join(require('os').homedir(), '.local/share/applications/'),61 '/usr/share/applications/',62 ];63 desktopInstallationFolders.forEach(folder => {64 installations = installations.concat(findChromeExecutables(folder));65 });66 // Look for google-chrome(-stable) & chromium(-browser) executables by using the which command67 const executables = ['google-chrome-stable', 'google-chrome', 'chromium-browser', 'chromium'];68 executables.forEach(executable => {69 try {70 const chromePath = execFileSync('which', [executable], { stdio: 'pipe' })71 .toString()72 .split(newLineRegex)[0];73 if (canAccess(chromePath)) installations.push(chromePath);74 } catch (e) {75 // Not installed.76 }77 });78 if (!installations.length)79 throw new Error(80 'The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.',81 );82 const priorities = [83 { regex: /chrome-wrapper$/, weight: 51 },84 { regex: /google-chrome-stable$/, weight: 50 },85 { regex: /google-chrome$/, weight: 49 },86 { regex: /chromium-browser$/, weight: 48 },87 { regex: /chromium$/, weight: 47 },88 ];89 if (process.env.CHROME_PATH)90 priorities.unshift({ regex: new RegExp(`${process.env.CHROME_PATH}`), weight: 101 });91 return sort(uniq(installations.filter(Boolean)), priorities)[0];92}93function win32(canary) {94 const suffix = canary95 ? `${path.sep}Google${path.sep}Chrome SxS${path.sep}Application${path.sep}chrome.exe`96 : `${path.sep}Google${path.sep}Chrome${path.sep}Application${path.sep}chrome.exe`;97 const prefixes = [98 process.env.LOCALAPPDATA,99 process.env.PROGRAMFILES,100 process.env['PROGRAMFILES(X86)'],101 ].filter(Boolean);102 let result;103 prefixes.forEach(prefix => {104 const chromePath = path.join(prefix, suffix);105 if (canAccess(chromePath)) result = chromePath;106 });107 return result;108}109function sort(installations, priorities) {110 const defaultPriority = 10;111 return (112 installations113 // assign priorities114 .map(inst => {115 for (const pair of priorities) {116 if (pair.regex.test(inst)) return { path: inst, weight: pair.weight };117 }118 return { path: inst, weight: defaultPriority };119 })120 // sort based on priorities121 .sort((a, b) => b.weight - a.weight)122 // remove priority flag123 .map(pair => pair.path)124 );125}126function canAccess(file) {127 if (!file) return false;128 try {129 fs.accessSync(file);130 return true;131 } catch (e) {132 return false;133 }134}135function uniq(arr) {136 return Array.from(new Set(arr));137}138function findChromeExecutables(folder) {139 const argumentsRegex = /(^[^ ]+).*/; // Take everything up to the first space140 const chromeExecRegex = '^Exec=/.*/(google-chrome|chrome|chromium)-.*';141 const installations = [];142 if (canAccess(folder)) {143 // Output of the grep & print looks like:144 // /opt/google/chrome/google-chrome --profile-directory145 // /home/user/Downloads/chrome-linux/chrome-wrapper %U146 let execPaths;147 // Some systems do not support grep -R so fallback to -r.148 // See https://github.com/GoogleChrome/chrome-launcher/issues/46 for more context.149 try {150 execPaths = execSync(`grep -ER "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);151 } catch (e) {152 execPaths = execSync(`grep -Er "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);153 }154 execPaths = execPaths155 .toString()156 .split(newLineRegex)157 .map(execPath => execPath.replace(argumentsRegex, '$1'));158 execPaths.forEach(execPath => canAccess(execPath) && installations.push(execPath));159 }160 return installations;161}162/**163 * @return {!Promise<?string>}164 */165async function downloadChromium(options, targetRevision) {166 const browserFetcher = puppeteer.createBrowserFetcher({ path: options.localDataDir });167 const revision =168 targetRevision || require('puppeteer-core/package.json').puppeteer.chromium_revision;169 const revisionInfo = browserFetcher.revisionInfo(revision);170 // Do nothing if the revision is already downloaded.171 if (revisionInfo.local) return revisionInfo;172 // Override current environment proxy settings with npm configuration, if any.173 try {174 console.log(`Downloading Chromium r${revision}...`);175 const newRevisionInfo = await browserFetcher.download(revisionInfo.revision);176 console.log('Chromium downloaded to ' + newRevisionInfo.folderPath);177 let localRevisions = await browserFetcher.localRevisions();178 localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);179 // Remove previous chromium revisions.180 const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));181 await Promise.all(cleanupOldVersions);182 return newRevisionInfo;183 } catch (error) {184 console.error(`ERROR: Failed to download Chromium r${revision}!`);185 console.error(error);186 return null;187 }188}189async function findChrome(options) {190 if (options.executablePath) return { executablePath: options.executablePath, type: 'user' };191 const config = new Set(options.channel || ['stable']);192 let executablePath;193 // Always prefer canary.194 if (config.has('canary') || config.has('*')) {195 if (process.platform === 'linux') executablePath = linux(true);196 else if (process.platform === 'win32') executablePath = win32(true);197 else if (process.platform === 'darwin') executablePath = darwin(true);198 if (executablePath) return { executablePath, type: 'canary' };199 }200 // Then pick stable.201 if (config.has('stable') || config.has('*')) {202 if (process.platform === 'linux') executablePath = linux();203 else if (process.platform === 'win32') executablePath = win32();204 else if (process.platform === 'darwin') executablePath = darwin();205 if (executablePath) return { executablePath, type: 'stable' };206 }207 // always prefer puppeteer revision of chromium208 if (config.has('chromium') || config.has('*')) {209 const revisionInfo = await downloadChromium(options);210 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };211 }212 for (const item of config) {213 if (!item.startsWith('r')) continue;214 const revisionInfo = await downloadChromium(options, item.substring(1));215 return { executablePath: revisionInfo.executablePath, type: revisionInfo.revision };216 }217 return {};218}...

Full Screen

Full Screen

ProcessUtils.js

Source:ProcessUtils.js Github

copy

Full Screen

1/* eslint-disable global-require */2/* eslint-disable no-unused-vars */3import find from 'find-process';4import Log from './log';5function isRunningAsar() {6 return process.mainModule.filename.indexOf('app.asar') !== -1;7}8export function launchProc(exePath, params) {9 const { execFile } = require('child_process');10 let executablePath = ``;11 const path = require('path');12 executablePath = path.join(__dirname, exePath);13 // if(isRunningAsar()) {14 // const path = require('path');15 // executablePath = path.join(__dirname, exePath);16 // }17 // else {18 // executablePath = `${process.resourcesPath}/app/${exePath}`;19 // }20 Log.info(`executablePath : ${executablePath}`);21 execFile(executablePath, params, (err, data) => {22 // Log.info(err);23 // Log.info(data);24 });25}26export function launchProcAsync(exePath, params) {27 const util = require('util');28 const execFile = util.promisify(require('child_process').execFile);29 let executablePath = ``;30 const path = require('path');31 executablePath = path.join(__dirname, exePath);32 Log.info(`executablePath : ${executablePath}`);33 if (params.length === 0) {34 return execFile(executablePath);35 }36 return execFile(executablePath, params);37}38export function launchDirectAsync(exePath, executable, params) {39 const util = require('util');40 const execFile = util.promisify(require('child_process').execFile);41 Log.info(`executablePath : ${exePath}${executable}`);42 return execFile(`${exePath}${executable}`, params, { cwd: exePath });43}44export function isPidRunning(pid) {45 try {46 return process.kill(pid, 0);47 } catch (e) {48 return e.code === 'EPERM';49 }50}51export function waitForAppExit(exeName, exitCallback) {52 find('name', exeName, true).then(list => {53 if (list.length > 0) {54 const interval = setInterval(() => {55 if (!isPidRunning(list[0].pid)) {56 clearInterval(interval);57 exitCallback();58 }59 }, 150);60 } else {61 exitCallback();62 }63 });...

Full Screen

Full Screen

chrome.js

Source:chrome.js Github

copy

Full Screen

...16 }17}18async function launchBrowser() {19 // Workaround for pkg20 const executablePath = getChromeExecutablePath(puppeteer.executablePath());21 // Launch a headless browser to do the shift code requests22 const browser = await puppeteer.launch({23 executablePath,24 headless: true25 });26 return browser;27}28module.exports = {29 getChromeExecutablePath,30 launchBrowser...

Full Screen

Full Screen

env.js

Source:env.js Github

copy

Full Screen

1module.exports = {2 "compile": true,3 "h5": {4/* "executablePath": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" */5 "executablePath": "C:/Program Files/Google/Chrome/Application/chrome.exe",6 },7 "mp-weixin": {8 "executablePath": "C:/Users/liuxi/download/微信web开发者工具/cli.bat"9 },10 "mp-qq": {11 "executablePath": ""12 },13 "mp-baidu": {14 "executablePath": ""15 },16 "mp-toutiao": {17 "executablePath": ""18 },19 "mp-alipay": {20 "executablePath": ""21 },22 "mp-360": {23 "executablePath": ""24 },25 "app-plus": {26 "android": {27 "executablePath": "D:/HX/alpha-3.1.3/HBuilderX/plugins/launcher/base/android_base.apk"28 },29 "version": "",30 "ios": {31 "id": "",32 "executablePath": ""33 }34 }...

Full Screen

Full Screen

ProcessLauncher.js

Source:ProcessLauncher.js Github

copy

Full Screen

1import Log from './log'2function isRunningAsar() {3 return process.mainModule.filename.indexOf('app.asar') !== -1;4}5export function launchProc(exePath, params) {6 const { execFile } = require('child_process');7 var executablePath = ``;8 const path = require('path');9 executablePath = path.join(__dirname, exePath);10 // if(isRunningAsar()) {11 // const path = require('path');12 // executablePath = path.join(__dirname, exePath);13 // }14 // else {15 // executablePath = `${process.resourcesPath}/app/${exePath}`;16 // }17 Log.info(`executablePath : ${executablePath}`);18 execFile(executablePath, params, function(err, data) {19 Log.info(err);20 Log.info(data);21 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const differencifyConfig = require('./differencify.config.js');3const { setDefaultOptions } = require('expect-puppeteer');4setDefaultOptions({ timeout: 3000 });5describe('My test', () => {6 beforeAll(async () => {7 });8 it('should match', async () => {9 await expect(page).toMatchElement('h1', { text: 'Example Domain' });10 });11 it('should match screenshot', async () => {12 await expect(page).toMatchElement('h1', { text: 'Example Domain' });13 await expect(page).toMatchScreenshot();14 });15});16const { execPath } = require('puppeteer');17module.exports = {18 browser: {19 launchOptions: {20 executablePath: execPath(),21 },22 },23};

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const expect = require('chai').expect;3const puppeteer = require('puppeteer');4const path = require('path');5const fs = require('fs');6const { PNG } = require('pngjs');7const pixelmatch = require('pixelmatch');8const browser = await puppeteer.launch({9});10const page = await browser.newPage();11await page.screenshot({path: 'google.png'});12await browser.close();13const differencify = require('differencify');14const expect = require('chai').expect;15const puppeteer = require('puppeteer');16const path = require('path');17const fs = require('fs');18const { PNG } = require('pngjs');19const pixelmatch = require('pixelmatch');20const browser = await puppeteer.launch();21const page = await browser.newPage();22await page.screenshot({path: 'google.png'});23await browser.close();24const differencify = require('differencify');25const expect = require('chai').expect;26const puppeteer = require('puppeteer');27const path = require('path');28const fs = require('fs');29const { PNG } = require('pngjs');30const pixelmatch = require('pixelmatch');31const browser = await puppeteer.launch();32const page = await browser.newPage();33await page.screenshot({path: 'google.png'});34await browser.close();35const diff = differencify.init(path.join(__dirname, 'screenshots'));36const result = await diff.runTest('google');37expect(result.percentage).to.be.below(0.1);38const differencify = require('differencify');39const expect = require('chai').expect;40const puppeteer = require('puppeteer');41const path = require('path');42const fs = require('fs');43const { PNG } = require('pngjs');44const pixelmatch = require('pixelmatch');45const browser = await puppeteer.launch();46const page = await browser.newPage();47await page.screenshot({path: 'google.png'});

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const path = require('path');3const fs = require('fs');4const {promisify} = require('util');5const puppeteer = require('puppeteer');6const readFile = promisify(fs.readFile);7const config = {8 referenceDir: path.join(__dirname, 'screenshots/reference'),9 screenshotDir: path.join(__dirname, 'screenshots/screen'),10 diffDir: path.join(__dirname, 'screenshots/diff'),11};12differencify.init(config);13const differencify = require('differencify');14const path = require('path');15const fs = require('fs');16const {promisify} = require('util');17const puppeteer = require('puppeteer');18const readFile = promisify(fs.readFile);19const config = {20 referenceDir: path.join(__dirname, 'screenshots/reference'),21 screenshotDir: path.join(__dirname, 'screenshots/screen'),22 diffDir: path.join(__dirname, 'screenshots/diff'),23};24differencify.init(config);25const differencify = require('differencify');26const path = require('path');27const fs = require('fs');28const {promisify} = require('util');29const puppeteer = require('puppeteer');30const readFile = promisify(fs.readFile);31const config = {32 referenceDir: path.join(__dirname, 'screenshots/reference'),33 screenshotDir: path.join(__dirname, 'screenshots/screen'),34 diffDir: path.join(__dirname, 'screenshots/diff'),35};36differencify.init(config);

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const differencifyConfig = {3};4const differencifyInstance = differencify.init(differencifyConfig);5differencifyInstance.setConfig({ autoSaveBaseline: true });6const page = await differencifyInstance.launchPage();7await page.waitFor(1000);8await page.differencify('example');9const differencify = require('differencify');10const differencifyInstance = differencify.init();11differencifyInstance.setConfig({ autoSaveBaseline: true });12describe('My App', () => {13 let page;14 beforeAll(async () => {15 page = await differencifyInstance.launchPage();16 await page.waitFor(1000);17 });18 it('should look the same', async () => {19 await page.differencify('example');20 });21});22const differencify = require('differencify');23const differencifyInstance = differencify.init();24differencifyInstance.setConfig({ autoSaveBaseline: true });25describe('My App', () => {26 let page;27 before(async () => {28 page = await differencifyInstance.launchPage();29 await page.waitFor(1000);30 });31 it('should look the same', async () => {32 await page.differencify('example');33 });34});35const differencify = require('differencify');36const differencifyInstance = differencify.init();37differencifyInstance.setConfig({ autoSaveBaseline: true });38const { Before, Then } = require('cucumber');39Before(async () => {40 page = await differencifyInstance.launchPage();41 await page.waitFor(1000);42});43Then('the page should look the same', async () => {44 await page.differencify('example');45});46### differencify.init([

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const { chromium } = require('playwright');3differencify.init(chromium);4describe('Differencify', () => {5 it('should work', async () => {6 const browser = await chromium.launch();7 const page = await browser.newPage();8 await page.screenshot({ path: 'google.png' });9 await browser.close();10 });11});12{13 "scripts": {14 },15 "devDependencies": {16 }17}18const differencify = require('differencify');19const { chromium } = require('playwright');20differencify.init(chromium);21module.exports = {22 testEnvironment: differencify.getTestEnvironment()23}24### `differencify.init(browser: BrowserType, options?: Options)`25### `differencify.getTestEnvironment()`26### `differencify.getSnapshotState()`

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify');2const path = require('path');3const assert = require('assert');4const diff = differencify({5 args: [path.join(__dirname, 'index.js')],6});7const screenshot = await diff.screenshot();8const result = await diff.run(screenshot, 'reference.png');9assert.ok(result.equal, 'The images are different');10const differencify = require('differencify');11const path = require('path');12const assert = require('assert');13const diff = differencify({14 puppeteer: {15 },16});17const screenshot = await diff.screenshot();18const result = await diff.run(screenshot, 'reference.png');19assert.ok(result.equal, 'The images are different');20const differencify = require('differencify');21const path = require('path');22const assert = require('assert');23const diff = differencify({24 selenium: {25 },26});27const screenshot = await diff.screenshot();28const result = await diff.run(screenshot, 'reference.png');29assert.ok(result.equal, 'The images are different');

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 differencify 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