How to use findEdgeExecutables method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

Run Webdriverio automation tests on LambdaTest cloud grid

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

edge.js

Source: edge.js Github

copy
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.default = void 0;
7
8var _path = _interopRequireDefault(require("path"));
9
10var _child_process = require("child_process");
11
12var _utils = require("@wdio/utils");
13
14var _utils2 = require("../utils");
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18/**
19 * @license Copyright 2016 Google Inc. All Rights Reserved.
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
22 */
23const newLineRegex = /\r?\n/;
24const EDGE_BINARY_NAMES = ['edge', 'msedge', 'microsoftedge'];
25const EDGE_REGEX = /((ms|microsoft))?edge/g;
26
27function darwin() {
28  const suffixes = ['/Contents/MacOS/Microsoft Edge'];
29  const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' + '/Versions/A/Frameworks/LaunchServices.framework' + '/Versions/A/Support/lsregister';
30  const installations = [];
31  (0, _child_process.execSync)(`${LSREGISTER} -dump` + ' | grep -i \'microsoft edge\\?.app.*$\'' + ' | awk \'{$1=""; print $0}\'').toString().split(newLineRegex).forEach(inst => {
32    suffixes.forEach(suffix => {
33      const execPath = _path.default.join(inst.substring(0, inst.indexOf('.app') + 4).trim(), suffix);
34
35      if ((0, _utils.canAccess)(execPath) && installations.indexOf(execPath) === -1) {
36        installations.push(execPath);
37      }
38    });
39  });
40  const priorities = [{
41    regex: new RegExp(`^${process.env.HOME}/Applications/.*Microsoft Edge.app`),
42    weight: 50
43  }, {
44    regex: /^\/Applications\/.*Microsoft Edge.app/,
45    weight: 100
46  }, {
47    regex: /^\/Volumes\/.*Microsoft Edge.app/,
48    weight: -2
49  }];
50  const whichFinds = (0, _utils2.findByWhich)(EDGE_BINARY_NAMES, [{
51    regex: EDGE_REGEX,
52    weight: 51
53  }]);
54  const installFinds = (0, _utils2.sort)(installations, priorities);
55  return [...installFinds, ...whichFinds];
56}
57
58function linux() {
59  let installations = [];
60  const desktopInstallationFolders = [_path.default.join(require('os').homedir(), '.local/share/applications/'), '/usr/share/applications/'];
61  desktopInstallationFolders.forEach(folder => {
62    installations = installations.concat(findEdgeExecutables(folder));
63  });
64  return (0, _utils2.findByWhich)(EDGE_BINARY_NAMES, [{
65    regex: EDGE_REGEX,
66    weight: 51
67  }]);
68}
69
70function win32() {
71  const installations = [];
72  const suffixes = [`${_path.default.sep}Microsoft${_path.default.sep}Edge${_path.default.sep}Application${_path.default.sep}edge.exe`];
73  const prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']].filter(Boolean);
74  prefixes.forEach(prefix => suffixes.forEach(suffix => {
75    const edgePath = _path.default.join(prefix, suffix);
76
77    if ((0, _utils.canAccess)(edgePath)) {
78      installations.push(edgePath);
79    }
80  }));
81  return installations;
82}
83
84function findEdgeExecutables(folder) {
85  const argumentsRegex = /(^[^ ]+).*/;
86  const edgeExecRegex = '^Exec=/.*/(edge)-.*';
87  let installations = [];
88
89  if ((0, _utils.canAccess)(folder)) {
90    let execPaths;
91
92    try {
93      execPaths = (0, _child_process.execSync)(`grep -ER "${edgeExecRegex}" ${folder} | awk -F '=' '{print $2}'`, {
94        stdio: 'pipe'
95      });
96    } catch (e) {
97      execPaths = (0, _child_process.execSync)(`grep -Er "${edgeExecRegex}" ${folder} | awk -F '=' '{print $2}'`, {
98        stdio: 'pipe'
99      });
100    }
101
102    execPaths = execPaths.toString().split(newLineRegex).map(execPath => execPath.replace(argumentsRegex, '$1'));
103    execPaths.forEach(execPath => (0, _utils.canAccess)(execPath) && installations.push(execPath));
104  }
105
106  return installations;
107}
108
109var _default = {
110  darwin,
111  linux,
112  win32
113};
114exports.default = _default;
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Webdriverio on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)