Skip to content

Commit

Permalink
add warning when use t.debug in headless browsers (closes DevExpress#…
Browse files Browse the repository at this point in the history
…2846) (DevExpress#3003)

* [WIP]add warning when use t.debug in headless browsers (closes DevExpress#2846)

* fix

* define IsHeadlessBrowser method only in pluginHost
  • Loading branch information
AlexKamaev authored and kirovboris committed Dec 18, 2019
1 parent 5819eaf commit 55b2f1a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ export default class BrowserConnection extends EventEmitter {
initScriptPromise.resolve(JSON.parse(data));
}

isHeadlessBrowser () {
return this.provider.isHeadlessBrowser(this.id);
}

async reportJobResult (status, data) {
await this.provider.reportJobResult(this.id, status, data);
}
Expand Down
6 changes: 6 additions & 0 deletions src/browser/provider/built-in/chrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export default {
return !config.headless;
},

isHeadlessBrowser (browserId) {
const config = this.openedBrowsers[browserId].config;

return config && config.headless;
},

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

Expand Down
6 changes: 6 additions & 0 deletions src/browser/provider/built-in/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export default {
return !config.headless;
},

isHeadlessBrowser (browserId) {
const config = this.openedBrowsers[browserId].config;

return config && config.headless;
},

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

Expand Down
4 changes: 4 additions & 0 deletions src/browser/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ export default class BrowserProvider {
return await this.plugin.isLocalBrowser(browserId, browserName);
}

isHeadlessBrowser (browserId) {
return this.plugin.isHeadlessBrowser(browserId);
}

async openBrowser (browserId, pageUrl, browserName) {
await this.plugin.openBrowser(browserId, pageUrl, browserName);

Expand Down
4 changes: 4 additions & 0 deletions src/browser/provider/plugin-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export default class BrowserProviderPluginHost {
return false;
}

isHeadlessBrowser () {
return false;
}

async hasCustomActionForBrowser (/* browserId */) {
return {
hasCloseBrowser: this.hasOwnProperty('closeBrowser'),
Expand Down
3 changes: 2 additions & 1 deletion src/notifications/warning-message.js

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

6 changes: 6 additions & 0 deletions src/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ClientFunctionBuilder from '../client-functions/client-function-builder';
import ReporterPluginHost from '../reporter/plugin-host';
import BrowserConsoleMessages from './browser-console-messages';
import { UNSTABLE_NETWORK_MODE_HEADER } from '../browser/connection/unstable-network-mode';
import WARNING_MESSAGE from '../notifications/warning-message';

import { TakeScreenshotOnFailCommand } from './commands/browser-manipulation';
import { SetNativeDialogHandlerCommand, SetTestSpeedCommand, SetPageLoadTimeoutCommand } from './commands/actions';
Expand Down Expand Up @@ -365,6 +366,11 @@ export default class TestRun extends EventEmitter {
}

async _enqueueSetBreakpointCommand (callsite, error) {
if (this.browserConnection.isHeadlessBrowser()) {
this.warningLog.addWarning(WARNING_MESSAGE.debugInHeadlessError);
return;
}

debugLogger.showBreakpoint(this.session.id, this.browserConnection.userAgent, callsite, error);

this.debugging = await this.executeCommand(new SetBreakpointCommand(!!error), callsite);
Expand Down
10 changes: 7 additions & 3 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ testingEnvironments[testingEnvironmentNames.localBrowsersIE] = {
};

testingEnvironments[testingEnvironmentNames.localBrowsersChromeFirefox] = {
isLocalBrowsers: true,
isHeadlessBrowsers: true,
isLocalBrowsers: true,

browsers: [
{
Expand All @@ -152,7 +151,8 @@ testingEnvironments[testingEnvironmentNames.localBrowsersChromeFirefox] = {
};

testingEnvironments[testingEnvironmentNames.localHeadlessBrowsers] = {
isLocalBrowsers: true,
isLocalBrowsers: true,
isHeadlessBrowsers: true,

browsers: [
{
Expand Down Expand Up @@ -232,6 +232,10 @@ module.exports = {
return this.currentEnvironment.isLocalBrowsers;
},

get useHeadlessBrowsers () {
return this.currentEnvironment.isHeadlessBrowsers;
},

get devMode () {
return !!process.env.DEV_MODE;
},
Expand Down
9 changes: 9 additions & 0 deletions test/functional/fixtures/regression/gh-2846/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>gh-2846</title>
</head>
<body>
</body>
</html>
14 changes: 14 additions & 0 deletions test/functional/fixtures/regression/gh-2846/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const config = require('../../../config');
const expect = require('chai').expect;

if (config.useHeadlessBrowsers) {
describe('[Regression](GH-2846)', function () {
it('Should add warning on t.debug', function () {
return runTests('./testcafe-fixtures/index.js')
.then(() => {
expect(testReport.warnings).eql(['It is not allowed to debug in Headless mode']);
});
});
});
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fixture `GH-2846`
.page `http://localhost:3000/fixtures/regression/gh-2846/pages/index.html`;

test(`Debug`, async t => {
await t.debug();
});

0 comments on commit 55b2f1a

Please sign in to comment.