Skip to content

Commit

Permalink
Fix error messages when can't find firefox & chrome (closes DevExpres…
Browse files Browse the repository at this point in the history
…s#3534) (DevExpress#3540)

* Fix error messages when can't find firefox & chrome

* Fix tests on Node 6
  • Loading branch information
AndreyBelym authored and kirovboris committed Dec 18, 2019
1 parent 132724e commit 0122e74
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 67 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"npm-auditor": "^1.1.1",
"openssl-self-signed-certificate": "^1.1.6",
"opn": "^4.0.2",
"proxyquire": "^2.1.0",
"publish-please": "^5.4.3",
"recursive-copy": "^2.0.5",
"request": "^2.58.0",
Expand Down
37 changes: 37 additions & 0 deletions src/browser/provider/built-in/dedicated/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { getBrowserInfo } from 'testcafe-browser-tools';
import getMaximizedHeadlessWindowSize from '../../utils/get-maximized-headless-window-size';

export default {
openedBrowsers: {},

isMultiBrowser: false,

_getConfig () {
throw new Error('Not implemented');
},

_getBrowserName () {
return this.providerName.replace(':', '');
},

async isValidBrowserName (browserName) {
const config = await this._getConfig(browserName);
const browserInfo = await getBrowserInfo(config.path || this._getBrowserName());

return !!browserInfo;
},

async isLocalBrowser () {
return true;
},

isHeadlessBrowser (browserId) {
return this.openedBrowsers[browserId].config.headless;
},

async maximizeWindow (browserId) {
const maximumSize = getMaximizedHeadlessWindowSize();

await this.resizeWindow(browserId, maximumSize.width, maximumSize.height, maximumSize.width, maximumSize.height);
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import remoteChrome from 'chrome-remote-interface';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../utils/client-functions';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../../utils/client-functions';


async function getActiveTab (cdpPort, browserId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import emulatedDevices from 'chrome-emulated-devices-list';
import { pickBy as filterProperties } from 'lodash';
import {
hasMatch, findMatch, isMatchTrue, getModes, splitEscaped, getPathFromParsedModes, parseConfig
} from '../../utils/argument-parsing';
} from '../../../utils/argument-parsing';


const HEADLESS_DEFAULT_WIDTH = 1280;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import makeDir from 'make-dir';
import TempDirectory from '../../../../utils/temp-directory';
import { writeFile } from '../../../../utils/promisified-functions';
import TempDirectory from '../../../../../utils/temp-directory';
import { writeFile } from '../../../../../utils/promisified-functions';


export default async function (proxyHostName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import OS from 'os-family';
import { parse as parseUrl } from 'url';
import dedicatedProviderBase from '../base';
import getRuntimeInfo from './runtime-info';
import getConfig from './config';
import { start as startLocalChrome, stop as stopLocalChrome } from './local-chrome';
import * as cdp from './cdp';
import getMaximizedHeadlessWindowSize from '../../utils/get-maximized-headless-window-size';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../utils/client-functions';
import { cropScreenshot } from '../../../../screenshots/crop';
import { writePng } from '../../../../screenshots/utils';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../../utils/client-functions';
import { cropScreenshot } from '../../../../../screenshots/crop';
import { writePng } from '../../../../../screenshots/utils';

const MIN_AVAILABLE_DIMENSION = 50;

export default {
openedBrowsers: {},
...dedicatedProviderBase,

isMultiBrowser: false,
_getConfig (name) {
return getConfig(name);
},

async openBrowser (browserId, pageUrl, configString) {
const runtimeInfo = await getRuntimeInfo(parseUrl(pageUrl).hostname, configString);
const browserName = this.providerName.replace(':', '');

runtimeInfo.browserName = this._getBrowserName();
runtimeInfo.browserId = browserId;
runtimeInfo.browserName = browserName;

runtimeInfo.providerMethods = {
resizeLocalBrowserWindow: (...args) => this.resizeLocalBrowserWindow(...args)
Expand Down Expand Up @@ -56,14 +58,6 @@ export default {
delete this.openedBrowsers[browserId];
},

async isLocalBrowser () {
return true;
},

isHeadlessBrowser (browserId) {
return this.openedBrowsers[browserId].config.headless;
},

async takeScreenshot (browserId, path) {
const runtimeInfo = this.openedBrowsers[browserId];
const viewport = await cdp.getPageViewport(runtimeInfo);
Expand Down Expand Up @@ -95,12 +89,6 @@ export default {
await cdp.resizeWindow({ width, height }, runtimeInfo);
},

async maximizeWindow (browserId) {
const maximumSize = getMaximizedHeadlessWindowSize();

await this.resizeWindow(browserId, maximumSize.width, maximumSize.height, maximumSize.width, maximumSize.height);
},

async getVideoFrameData (browserId) {
return await cdp.getScreenshotData(this.openedBrowsers[browserId]);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import browserTools from 'testcafe-browser-tools';
import { killBrowserProcess } from '../../../../utils/process';
import BrowserStarter from '../../utils/browser-starter';
import { killBrowserProcess } from '../../../../../utils/process';
import BrowserStarter from '../../../utils/browser-starter';
import { buildChromeArgs } from './build-chrome-args';

const browserStarter = new BrowserStarter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findMatch, isMatchTrue, splitEscaped, parseConfig, getModes, getPathFromParsedModes } from '../../utils/argument-parsing';
import { findMatch, isMatchTrue, splitEscaped, parseConfig, getModes, getPathFromParsedModes } from '../../../utils/argument-parsing';


const AVAILABLE_MODES = ['userProfile', 'headless'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import TempDirectory from '../../../../utils/temp-directory';
import { writeFile } from '../../../../utils/promisified-functions';
import TempDirectory from '../../../../../utils/temp-directory';
import { writeFile } from '../../../../../utils/promisified-functions';


async function generatePreferences (profileDir, { marionettePort, config }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import OS from 'os-family';
import dedicatedProviderBase from '../base';
import getRuntimeInfo from './runtime-info';
import getConfig from './config';
import { start as startLocalFirefox, stop as stopLocalFirefox } from './local-firefox';
import MarionetteClient from './marionette-client';
import getMaximizedHeadlessWindowSize from '../../utils/get-maximized-headless-window-size';


export default {
openedBrowsers: {},
...dedicatedProviderBase,

isMultiBrowser: false,
_getConfig (name) {
return getConfig(name);
},

async _createMarionetteClient (runtimeInfo) {
try {
Expand All @@ -25,10 +28,9 @@ export default {

async openBrowser (browserId, pageUrl, configString) {
const runtimeInfo = await getRuntimeInfo(configString);
const browserName = this.providerName.replace(':', '');

runtimeInfo.browserName = this._getBrowserName();
runtimeInfo.browserId = browserId;
runtimeInfo.browserName = browserName;

await startLocalFirefox(pageUrl, runtimeInfo);

Expand Down Expand Up @@ -58,14 +60,6 @@ export default {
delete this.openedBrowsers[browserId];
},

async isLocalBrowser () {
return true;
},

isHeadlessBrowser (browserId) {
return this.openedBrowsers[browserId].config.headless;
},

async takeScreenshot (browserId, path) {
const { marionetteClient } = this.openedBrowsers[browserId];

Expand All @@ -78,12 +72,6 @@ export default {
await marionetteClient.setWindowSize(width, height);
},

async maximizeWindow (browserId) {
const maximumSize = getMaximizedHeadlessWindowSize();

await this.resizeWindow(browserId, maximumSize.width, maximumSize.height);
},

async getVideoFrameData (browserId) {
const { marionetteClient } = this.openedBrowsers[browserId];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OS from 'os-family';
import browserTools from 'testcafe-browser-tools';
import { killBrowserProcess } from '../../../../utils/process';
import BrowserStarter from '../../utils/browser-starter';
import { killBrowserProcess } from '../../../../../utils/process';
import BrowserStarter from '../../../utils/browser-starter';


const browserStarter = new BrowserStarter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Promise from 'pinkie';
import { Socket } from 'net';
import promisifyEvent from 'promisify-event';
import EventEmitter from 'events';
import { writeFile } from '../../../../../utils/promisified-functions';
import delay from '../../../../../utils/delay';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../../utils/client-functions';
import { writeFile } from '../../../../../../utils/promisified-functions';
import delay from '../../../../../../utils/delay';
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../../../utils/client-functions';
import COMMANDS from './commands';


Expand Down
4 changes: 2 additions & 2 deletions src/browser/provider/built-in/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pathBrowserProvider from './path';
import locallyInstalledBrowserProvider from './locally-installed';
import remoteBrowserProvider from './remote';
import firefoxProvider from './firefox';
import chromeProvider from './chrome';
import firefoxProvider from './dedicated/firefox';
import chromeProvider from './dedicated/chrome';

export default Object.assign(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const { expect } = require('chai');
const Promise = require('pinkie');
const config = require('../../../config');
const { createNullStream } = require('../../../utils/stream');
const createChromeProfile = require('../../../../../lib/browser/provider/built-in/chrome/create-temp-profile');
const createFirefoxProfile = require('../../../../../lib/browser/provider/built-in/firefox/create-temp-profile');
const createChromeProfile = require('../../../../../lib/browser/provider/built-in/dedicated/chrome/create-temp-profile');
const createFirefoxProfile = require('../../../../../lib/browser/provider/built-in/dedicated/firefox/create-temp-profile');


if (config.useLocalBrowsers && !config.isTravisEnvironment) {
Expand Down
15 changes: 10 additions & 5 deletions test/functional/fixtures/browser-provider/job-reporting/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path');
const Promise = require('pinkie');
const expect = require('chai').expect;
const config = require('../../../config');
const chromeBrowserProvider = require('../../../../../lib/browser/provider/built-in/chrome');
const chromeBrowserProvider = require('../../../../../lib/browser/provider/built-in/dedicated/chrome');
const browserProviderPool = require('../../../../../lib/browser/provider/pool');
const BrowserConnection = require('../../../../../lib/browser/connection');

Expand All @@ -16,7 +17,7 @@ if (config.useLocalBrowsers) {
state: {},
idNameMap: {},

openBrowser: function (browserId, pageUrl, name) {
openBrowser (browserId, pageUrl, name) {
const self = this;

this.idNameMap[browserId] = name;
Expand All @@ -31,11 +32,15 @@ if (config.useLocalBrowsers) {
return chromeBrowserProvider.openBrowser.call(this, browserId, pageUrl, 'headless --no-sandbox');
},

closeBrowser: function (browserId) {
closeBrowser (browserId) {
return chromeBrowserProvider.closeBrowser.call(this, browserId);
},

reportJobResult: function (browserId, result, data) {
isValidBrowserName () {
return Promise.resolve(true);
},

reportJobResult (browserId, result, data) {
const name = this.idNameMap[browserId];

this.state[name].result = result;
Expand All @@ -44,7 +49,7 @@ if (config.useLocalBrowsers) {
return Promise.resolve();
},

simulateError: function (browserId) {
simulateError (browserId) {
const bc = BrowserConnection.getById(browserId);

bc.emit('error', new Error('Connection error'));
Expand Down
53 changes: 53 additions & 0 deletions test/server/browser-provider-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const expect = require('chai').expect;
const Promise = require('pinkie');
const proxyquire = require('proxyquire');
const testcafeBrowserTools = require('testcafe-browser-tools');
const browserProviderPool = require('../../lib/browser/provider/pool');
const parseProviderName = require('../../lib/browser/provider/parse-provider-name');
Expand Down Expand Up @@ -197,5 +198,57 @@ describe('Browser provider', function () {
});
});
});

describe('Dedicated providers base', () => {
describe('isValidBrowserName', function () {
it('Should return false if a browser is not found', () => {
const dedicatedBrowserProviderBase = proxyquire('../../lib/browser/provider/built-in/dedicated/base', {
'testcafe-browser-tools': {
getBrowserInfo () {
return null;
}
}
});

const testProvider = Object.assign({}, dedicatedBrowserProviderBase, {
providerName: 'browser',

_getConfig () {
return {};
}
});

return testProvider
.isValidBrowserName('browser')
.then(result => {
expect(result).to.be.false;
});
});

it('Should return true if a browser is found', () => {
const dedicatedBrowserProviderBase = proxyquire('../../lib/browser/provider/built-in/dedicated/base', {
'testcafe-browser-tools': {
getBrowserInfo () {
return { alias: 'browser' };
}
}
});

const testProvider = Object.assign({}, dedicatedBrowserProviderBase, {
providerName: 'browser',

_getConfig () {
return {};
}
});

return testProvider
.isValidBrowserName('browser')
.then(result => {
expect(result).to.be.true;
});
});
});
});
});

2 changes: 1 addition & 1 deletion test/server/chrome-provider-config-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const expect = require('chai').expect;
const OS = require('os-family');
const getChromeConfig = require('../../lib/browser/provider/built-in/chrome/config.js');
const getChromeConfig = require('../../lib/browser/provider/built-in/dedicated/chrome/config.js');


describe('Chrome provider config parser', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/server/firefox-provider-config-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const expect = require('chai').expect;
const OS = require('os-family');
const getFirefoxConfig = require('../../lib/browser/provider/built-in/firefox/config.js');
const getFirefoxConfig = require('../../lib/browser/provider/built-in/dedicated/firefox/config.js');


describe('Firefox provider config parser', function () {
Expand Down
Loading

0 comments on commit 0122e74

Please sign in to comment.