Skip to content

Commit

Permalink
feat: Support ChromeHeadless, FirefoxHeadless and EdgeHeadless (shaka…
Browse files Browse the repository at this point in the history
  • Loading branch information
ppaneksamsung authored Feb 10, 2022
1 parent dba3ca4 commit b182d2f
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const url = require('url');
const wd = require('wd');

const {installWebDrivers} = require('webdriver-installer');
Expand All @@ -36,10 +35,10 @@ const PLATFORM_MAP = {
};

const LocalWebDriverBase = function(
browserName, driverCommand, argsFromPort, baseBrowserDecorator, logger) {
browserName, name, driverCommand, argsFromPort, baseBrowserDecorator, logger) {
baseBrowserDecorator(this);

this.name = `${this.browserName} via WebDriver`;
this.name = `${name} via WebDriver`;
const log = logger.create(this.name);

this.browserName = browserName;
Expand Down Expand Up @@ -76,7 +75,6 @@ const LocalWebDriverBase = function(
pathname: '/'
};

const webDriver = url.format(config);
log.debug('config:', JSON.stringify(config));

// These names ("browser" and "spec") are needed for compatibility with
Expand Down Expand Up @@ -197,39 +195,84 @@ const LocalWebDriverBase = function(

const LocalWebDriverChrome = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'Chrome', 'chromedriver', (port) => ['--port=' + port],
'Chrome', 'Chrome', 'chromedriver', (port) => ['--port=' + port],
baseBrowserDecorator, logger);
};

const LocalWebDriverChromeHeadless = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'Chrome', 'ChromeHeadless', 'chromedriver', (port) => ['--port=' + port],
baseBrowserDecorator, logger);

this.spec['goog:chromeOptions'] = {
args: [
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
],
};
};

// TODO: Add Chrome on android?

const LocalWebDriverEdge = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'MSEdge', 'msedgedriver', (port) => ['--port=' + port],
'MSEdge', 'MSEdge', 'msedgedriver', (port) => ['--port=' + port],
baseBrowserDecorator, logger);
};

const LocalWebDriverEdgeHeadless = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'MSEdge', 'MSEdgeHeadless', 'msedgedriver', (port) => ['--port=' + port],
baseBrowserDecorator, logger);

this.spec['ms:edgeOptions'] = {
args: [
'--headless',
'--disable-gpu',
],
};
};

const LocalWebDriverFirefox = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'Firefox', 'geckodriver', (port) => ['-p', port],
'Firefox', 'Firefox', 'geckodriver', (port) => ['-p', port],
baseBrowserDecorator, logger);
};

const LocalWebDriverFirefoxHeadless = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'Firefox', 'FirefoxHeadless', 'geckodriver', (port) => ['-p', port],
baseBrowserDecorator, logger);

this.spec['moz:firefoxOptions'] = {
args: [
'-headless',
],
};
};

const LocalWebDriverSafari = function(baseBrowserDecorator, logger) {
LocalWebDriverBase.call(this,
'Safari', '/usr/bin/safaridriver', (port) => ['-p', port],
'Safari', 'Safari', '/usr/bin/safaridriver', (port) => ['-p', port],
baseBrowserDecorator, logger);
};

LocalWebDriverChrome.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverChromeHeadless.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverEdge.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverEdgeHeadless.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverFirefox.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverFirefoxHeadless.$inject = ['baseBrowserDecorator', 'logger'];
LocalWebDriverSafari.$inject = ['baseBrowserDecorator', 'logger'];

module.exports = {
'launcher:Chrome': ['type', LocalWebDriverChrome],
'launcher:ChromeHeadless': ['type', LocalWebDriverChromeHeadless],
'launcher:Edge': ['type', LocalWebDriverEdge],
'launcher:EdgeHeadless': ['type', LocalWebDriverEdgeHeadless],
'launcher:Firefox': ['type', LocalWebDriverFirefox],
'launcher:FirefoxHeadless': ['type', LocalWebDriverFirefoxHeadless],
};

// Safari is only supported on Mac.
Expand Down

0 comments on commit b182d2f

Please sign in to comment.