Skip to content

Commit

Permalink
Merge pull request #117 from webdriverio-community/custom-chromeargs
Browse files Browse the repository at this point in the history
  • Loading branch information
goosewobbler authored Jul 18, 2023
2 parents 6f34414 + aa5acd3 commit afaf51a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 234 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ The version of electron that the app to be tested was built with. The service us

### `appArgs`: _`string[]`_

An array of string arguments to be passed through to the app on execution of the test run.
An array of string arguments to be passed through to the app on execution of the test run. Electron [command line switches](https://www.electronjs.org/docs/latest/api/command-line-switches) and some [Chromium switches](https://peter.sh/experiments/chromium-command-line-switches) can be used here.

### `customApiBrowserCommand`: _`string`_

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"dependencies": {
"@electron/get": "^2.0.2",
"@wdio/logger": "^8.11.0",
"ci-info": "^3.8.0",
"cross-dirname": "^0.1.0",
"extract-zip": "^2.0.1",
"import-meta-resolve": "^3.0.0",
Expand Down
4 changes: 1 addition & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cjs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 8 additions & 24 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Capabilities, Options, Services } from '@wdio/types';
import { Browser } from 'webdriverio';
import { isCI } from 'ci-info';
import { log } from './utils.js';

type WdioElectronWindowObj = {
Expand Down Expand Up @@ -79,7 +78,13 @@ export default class ElectronWorkerService implements Services.ServiceInstance {
{ name: 'mainProcess', bridgeProp: 'mainProcess' },
{ name: 'mock', bridgeProp: 'mock' },
];
const { appPath, appName, appArgs, binaryPath, customApiBrowserCommand = 'api' } = options as ElectronWorkerOptions;
const {
appPath,
appName,
appArgs = [],
binaryPath,
customApiBrowserCommand = 'api',
} = options as ElectronWorkerOptions;
const validPathOpts = binaryPath !== undefined || (appPath !== undefined && appName !== undefined);

if (!validPathOpts) {
Expand Down Expand Up @@ -117,31 +122,10 @@ export default class ElectronWorkerService implements Services.ServiceInstance {
public _browser?: WebdriverIO.Browser;

beforeSession(_config: Omit<Options.Testrunner, 'capabilities'>, capabilities: Capabilities.Capabilities): void {
const chromeArgs: string[] = [];

if (isCI) {
chromeArgs.push('window-size=1280,800');
chromeArgs.push('enable-automation');
chromeArgs.push('disable-infobars');
chromeArgs.push('disable-extensions');

if (process.platform !== 'win32') {
chromeArgs.push('no-sandbox');
chromeArgs.push('disable-gpu');
chromeArgs.push('disable-dev-shm-usage');
chromeArgs.push('disable-setuid-sandbox');
}
}

const { appPath, appName, appArgs, binaryPath } = this.options;

if (appArgs) {
chromeArgs.push(...appArgs);
}

const chromeOptions = {
binary: binaryPath || getBinaryPath(appPath as string, appName as string),
args: chromeArgs,
args: appArgs,
windowTypes: ['app', 'webview'],
};

Expand Down
204 changes: 0 additions & 204 deletions test/service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest';
import { Capabilities } from '@wdio/types';
import * as ciInfo from 'ci-info';

import { BrowserExtension } from '../src/index';
import ElectronWorkerService from '../src/service';
Expand All @@ -15,12 +14,6 @@ interface CustomBrowserExtension extends BrowserExtension {
let WorkerService: typeof ElectronWorkerService;
let instance: ElectronWorkerService | undefined;

vi.mock('ci-info');

function mockIsCI(isCI: boolean) {
vi.spyOn(ciInfo, 'isCI', 'get').mockReturnValue(isCI);
}

describe('options validation', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'darwin');
Expand Down Expand Up @@ -60,10 +53,6 @@ describe('options validation', () => {
});

describe('beforeSession', () => {
beforeEach(() => {
mockIsCI(false);
});

afterEach(() => {
instance = undefined;
revertProcessProperty('platform');
Expand Down Expand Up @@ -209,105 +198,6 @@ describe('beforeSession', () => {
});
});

describe('providing appArgs running on CI', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'darwin');
mockProcessProperty('arch', 'arm64');
mockIsCI(true);
WorkerService = (await import('../src/service')).default;
});

it('should set the expected capabilities', () => {
instance = new WorkerService({
appPath: 'workspace/my-test-app/dist',
appName: 'my-test-app',
appArgs: ['look', 'some', 'args'],
});
const capabilities = {};
instance.beforeSession({}, capabilities);
expect(capabilities).toEqual({
'browserName': 'chrome',
'goog:chromeOptions': {
args: [
'window-size=1280,800',
'enable-automation',
'disable-infobars',
'disable-extensions',
'no-sandbox',
'disable-gpu',
'disable-dev-shm-usage',
'disable-setuid-sandbox',
'look',
'some',
'args',
],
binary: 'workspace/my-test-app/dist/mac-arm64/my-test-app.app/Contents/MacOS/my-test-app',
windowTypes: ['app', 'webview'],
},
});
});

it('should set the expected capabilities when multiremote', () => {
instance = new WorkerService({
appPath: 'workspace/my-test-app/dist',
appName: 'my-test-app',
appArgs: ['look', 'some', 'args'],
});
const capabilities = {
firefox: {
capabilities: {
browserName: 'firefox',
},
},
myElectronProject: {
capabilities: {
browserName: 'electron',
},
},
chrome: {
capabilities: {
browserName: 'chrome',
},
},
};
instance.beforeSession({}, capabilities as Capabilities.Capabilities);
expect(capabilities).toEqual({
firefox: {
capabilities: {
browserName: 'firefox',
},
},
myElectronProject: {
capabilities: {
'browserName': 'chrome',
'goog:chromeOptions': {
args: [
'window-size=1280,800',
'enable-automation',
'disable-infobars',
'disable-extensions',
'no-sandbox',
'disable-gpu',
'disable-dev-shm-usage',
'disable-setuid-sandbox',
'look',
'some',
'args',
],
binary: 'workspace/my-test-app/dist/mac-arm64/my-test-app.app/Contents/MacOS/my-test-app',
windowTypes: ['app', 'webview'],
},
},
},
chrome: {
capabilities: {
browserName: 'chrome',
},
},
});
});
});

describe('providing appPath & appName', () => {
describe('on MacOS platforms', () => {
beforeEach(async () => {
Expand Down Expand Up @@ -398,41 +288,6 @@ describe('beforeSession', () => {
});
});

describe('on MacOS platforms running on CI', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'darwin');
mockProcessProperty('arch', 'arm64');
mockIsCI(true);
WorkerService = (await import('../src/service')).default;
});

it('should set the expected capabilities', () => {
instance = new WorkerService({
appPath: 'workspace/my-test-app/dist',
appName: 'my-test-app',
});
const capabilities = {};
instance.beforeSession({}, capabilities);
expect(capabilities).toEqual({
'browserName': 'chrome',
'goog:chromeOptions': {
args: [
'window-size=1280,800',
'enable-automation',
'disable-infobars',
'disable-extensions',
'no-sandbox',
'disable-gpu',
'disable-dev-shm-usage',
'disable-setuid-sandbox',
],
binary: 'workspace/my-test-app/dist/mac-arm64/my-test-app.app/Contents/MacOS/my-test-app',
windowTypes: ['app', 'webview'],
},
});
});
});

describe('on Linux platforms', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'linux');
Expand All @@ -457,40 +312,6 @@ describe('beforeSession', () => {
});
});

describe('on Linux platforms running on CI', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'linux');
mockIsCI(true);
WorkerService = (await import('../src/service')).default;
});

it('should set the expected capabilities', () => {
instance = new WorkerService({
appPath: 'workspace/my-test-app/dist',
appName: 'my-test-app',
});
const capabilities = {};
instance.beforeSession({}, capabilities);
expect(capabilities).toEqual({
'browserName': 'chrome',
'goog:chromeOptions': {
args: [
'window-size=1280,800',
'enable-automation',
'disable-infobars',
'disable-extensions',
'no-sandbox',
'disable-gpu',
'disable-dev-shm-usage',
'disable-setuid-sandbox',
],
binary: 'workspace/my-test-app/dist/linux-unpacked/my-test-app',
windowTypes: ['app', 'webview'],
},
});
});
});

describe('on Windows platforms', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'win32');
Expand All @@ -515,31 +336,6 @@ describe('beforeSession', () => {
});
});

describe('on Windows platforms running on CI', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'win32');
mockIsCI(true);
WorkerService = (await import('../src/service')).default;
});

it('should set the expected capabilities', () => {
instance = new WorkerService({
appPath: 'workspace/my-test-app/dist',
appName: 'my-test-app',
});
const capabilities = {};
instance.beforeSession({}, capabilities);
expect(capabilities).toEqual({
'browserName': 'chrome',
'goog:chromeOptions': {
args: ['window-size=1280,800', 'enable-automation', 'disable-infobars', 'disable-extensions'],
binary: 'workspace/my-test-app/dist/win-unpacked/my-test-app.exe',
windowTypes: ['app', 'webview'],
},
});
});
});

describe('on unsupported platforms', () => {
beforeEach(async () => {
mockProcessProperty('platform', 'unsupported');
Expand Down

0 comments on commit afaf51a

Please sign in to comment.