Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
miherlosev committed May 16, 2023
1 parent 9808995 commit c76c1ed
Show file tree
Hide file tree
Showing 49 changed files with 182 additions and 136 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"callsite-record": "^4.0.0",
"chai": "4.3.4",
"chalk": "^2.3.0",
"chrome-remote-interface": "^0.32.1",
"chrome-remote-interface": "^0.32.2",
"coffeescript": "^2.3.1",
"commander": "^8.3.0",
"debug": "^4.3.1",
Expand Down
5 changes: 1 addition & 4 deletions src/browser/connection/gateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class BrowserConnectionGateway extends EventEmitter {
proxy.GET(SERVICE_ROUTES.assets.index, { content: idlePageScript, contentType: 'application/x-javascript' });
proxy.GET(SERVICE_ROUTES.assets.styles, { content: idlePageStyle, contentType: 'text/css' });
proxy.GET(SERVICE_ROUTES.assets.logo, { content: idlePageLogo, contentType: 'image/svg+xml' });

proxy.GET(NATIVE_AUTOMATION_ERROR_ROUTE, (req: IncomingMessage, res: ServerResponse) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(EMPTY_PAGE_MARKUP);
Expand Down Expand Up @@ -352,9 +353,5 @@ export default class BrowserConnectionGateway extends EventEmitter {

this.emit('initialized');
}

public switchToNativeAutomation (): void {
this.proxy.switchToNativeAutomation();
}
}

2 changes: 1 addition & 1 deletion src/cli/argument-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class CLIArgumentParser {
.option('--test-meta <key=value[,key2=value2,...]>', 'filter tests by metadata')
.option('--fixture-meta <key=value[,key2=value2,...]>', 'filter fixtures by metadata')
.option('--debug-on-fail', 'pause tests on failure')
.option('--native-automation', 'enable native automation')
.option('--disable-native-automation', 'disable native automation')
.option('--app-init-delay <ms>', 'specify your application`s initialization time')
.option('--selector-timeout <ms>', 'specify the maximum Selector resolution time')
.option('--assertion-timeout <ms>', 'specify the maximum Assertion resolution time')
Expand Down
5 changes: 5 additions & 0 deletions src/cli/remotes-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import dedent from 'dedent';

import BrowserConnection from '../browser/connection';
import BrowserConnectionGateway from '../browser/connection/gateway';
import TestCafeConfiguration from '../configuration/testcafe-configuration';

interface TestCafe {
browserConnectionGateway: BrowserConnectionGateway;
createBrowserConnection(): Promise<BrowserConnection>;
initializeBrowserConnectionGateway(): Promise<void>;
configuration: TestCafeConfiguration;
}

export default async function (testCafe: TestCafe, remoteCount: number, showQRCode: boolean): Promise<BrowserConnection[]> {
Expand All @@ -29,6 +31,9 @@ export default async function (testCafe: TestCafe, remoteCount: number, showQRCo
if (showQRCode)
log.write('You can either enter the URL or scan the QR-code.');

// NOTE: 'remote' browser connection cannot be in the 'native automation' mode.
testCafe.configuration.mergeOptions({ disableNativeAutomation: true });

await testCafe.initializeBrowserConnectionGateway();

const connectionUrl = testCafe.browserConnectionGateway.connectUrl;
Expand Down
14 changes: 7 additions & 7 deletions src/configuration/default-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export const DEFAULT_CONCURRENCY_VALUE = 1;

export const DEFAULT_SOURCE_DIRECTORIES = ['tests', 'test'];

export const DEFAULT_DEVELOPMENT_MODE = false;
export const DEFAULT_RETRY_TEST_PAGES = false;
export const DEFAULT_DISABLE_HTTP2 = false;
export const DEFAULT_NATIVE_AUTOMATION = false;
export const DEFAULT_SCREENSHOT_THUMBNAILS = true;
export const DEFAULT_FILTER_FN = null;
export const DEFAULT_DISABLE_CROSS_DOMAIN = false;
export const DEFAULT_DEVELOPMENT_MODE = false;
export const DEFAULT_RETRY_TEST_PAGES = false;
export const DEFAULT_DISABLE_HTTP2 = false;
export const DEFAULT_DISABLE_NATIVE_AUTOMATION = false;
export const DEFAULT_SCREENSHOT_THUMBNAILS = true;
export const DEFAULT_FILTER_FN = null;
export const DEFAULT_DISABLE_CROSS_DOMAIN = false;

export const DEFAULT_TYPESCRIPT_COMPILER_OPTIONS: Dictionary<boolean | number> = {
experimentalDecorators: true,
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/option-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum OptionNames {
debugLogger = 'debugLogger',
disableMultipleWindows = 'disableMultipleWindows',
disableHttp2 = 'disableHttp2',
nativeAutomation = 'nativeAutomation',
disableNativeAutomation = 'disableNativeAutomation',
compilerOptions = 'compilerOptions',
pageRequestTimeout = 'pageRequestTimeout',
ajaxRequestTimeout = 'ajaxRequestTimeout',
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/run-option-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export default [
OPTION_NAMES.pageRequestTimeout,
OPTION_NAMES.ajaxRequestTimeout,
OPTION_NAMES.retryTestPages,
OPTION_NAMES.nativeAutomation,
OPTION_NAMES.disableNativeAutomation,
OPTION_NAMES.baseUrl,
];
8 changes: 4 additions & 4 deletions src/configuration/testcafe-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
DEFAULT_DISABLE_CROSS_DOMAIN,
DEFAULT_DISABLE_HTTP2,
DEFAULT_FILTER_FN,
DEFAULT_NATIVE_AUTOMATION,
DEFAULT_DISABLE_NATIVE_AUTOMATION,
DEFAULT_RETRY_TEST_PAGES,
DEFAULT_SCREENSHOT_THUMBNAILS,
DEFAULT_SOURCE_DIRECTORIES,
Expand Down Expand Up @@ -67,7 +67,7 @@ const OPTION_INIT_FLAG_NAMES = [
OPTION_NAMES.retryTestPages,
OPTION_NAMES.cache,
OPTION_NAMES.disableHttp2,
OPTION_NAMES.nativeAutomation,
OPTION_NAMES.disableNativeAutomation,
OPTION_NAMES.disableCrossDomain,
];

Expand Down Expand Up @@ -162,7 +162,7 @@ export default class TestCafeConfiguration extends Configuration {
cache: this.getOption(OPTION_NAMES.cache),
disableHttp2: this.getOption(OPTION_NAMES.disableHttp2),
disableCrossDomain: this.getOption(OPTION_NAMES.disableCrossDomain),
nativeAutomation: this.getOption(OPTION_NAMES.nativeAutomation),
nativeAutomation: !this.getOption(OPTION_NAMES.disableNativeAutomation),
};
}

Expand Down Expand Up @@ -278,7 +278,7 @@ export default class TestCafeConfiguration extends Configuration {
this._ensureOptionWithValue(OPTION_NAMES.developmentMode, DEFAULT_DEVELOPMENT_MODE, OptionSource.Configuration);
this._ensureOptionWithValue(OPTION_NAMES.retryTestPages, DEFAULT_RETRY_TEST_PAGES, OptionSource.Configuration);
this._ensureOptionWithValue(OPTION_NAMES.disableHttp2, DEFAULT_DISABLE_HTTP2, OptionSource.Configuration);
this._ensureOptionWithValue(OPTION_NAMES.nativeAutomation, DEFAULT_NATIVE_AUTOMATION, OptionSource.Configuration);
this._ensureOptionWithValue(OPTION_NAMES.disableNativeAutomation, DEFAULT_DISABLE_NATIVE_AUTOMATION, OptionSource.Configuration);
this._ensureOptionWithValue(OPTION_NAMES.disableCrossDomain, DEFAULT_DISABLE_CROSS_DOMAIN, OptionSource.Configuration);

this._ensureScreenshotOptions();
Expand Down
2 changes: 1 addition & 1 deletion src/errors/runtime/templates.js

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

2 changes: 1 addition & 1 deletion src/errors/test-run/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default {
`,

[TEST_RUN_ERRORS.multipleWindowsModeIsNotSupportedInNativeAutomationError]: () => `
The Native Automation mode does not support the use of multiple browser windows. Remove the "native automation" option to continue.
The Native Automation mode does not support the use of multiple browser windows. Use the "disable native automation" option to continue.
`,

[TEST_RUN_ERRORS.cannotCloseWindowWithoutParent]: () => `
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import exportableLib from './api/exportable-lib';
import TestCafeConfiguration from './configuration/testcafe-configuration';
import OPTION_NAMES from './configuration/option-names';
import userVariables from './api/user-variables';
import { getValidHostname, getValidPort } from './configuration/utils';
import { getValidPort } from './configuration/utils';

const lazyRequire = require('import-lazy')(require);
const TestCafe = lazyRequire('./testcafe');
Expand Down Expand Up @@ -45,8 +45,7 @@ async function getConfiguration (args) {
async function createTestCafe (...args) {
const configuration = await getConfiguration(args);

const [hostname, port1, port2] = await Promise.all([
getValidHostname(configuration.getOption(OPTION_NAMES.hostname)),
const [port1, port2] = await Promise.all([
getValidPort(configuration.getOption(OPTION_NAMES.port1)),
getValidPort(configuration.getOption(OPTION_NAMES.port2)),
]);
Expand All @@ -56,7 +55,7 @@ async function createTestCafe (...args) {
if (userVariablesOption)
userVariables.value = userVariablesOption;

configuration.mergeOptions({ hostname, port1, port2 });
configuration.mergeOptions({ port1, port2 });

const testcafe = new TestCafe(configuration);

Expand Down
4 changes: 3 additions & 1 deletion src/native-automation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export default class NativeAutomation {
}

public async start (): Promise<void> {
nativeAutomationLogger('starting');

for (const apiSystem of this.apiSystems)
await apiSystem.start();

this._addEventListeners();

nativeAutomationLogger('nativeAutomation initialized');
nativeAutomationLogger('started');
}

public async dispose (): Promise<void> {
Expand Down
29 changes: 14 additions & 15 deletions src/runner/bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default class Bootstrapper {
public tsConfigPath?: string;
public clientScripts: ClientScriptInit[];
public disableMultipleWindows: boolean;
public nativeAutomation: boolean;
public compilerOptions?: CompilerOptions;
public browserInitTimeout?: number;
public hooks?: GlobalHooks;
Expand All @@ -115,7 +114,6 @@ export default class Bootstrapper {
this.tsConfigPath = void 0;
this.clientScripts = [];
this.disableMultipleWindows = false;
this.nativeAutomation = false;
this.compilerOptions = void 0;
this.debugLogger = debug(DEBUG_SCOPE);
this.warningLog = new WarningLog(null, WarningLog.createAddWarningCallback(messageBus));
Expand Down Expand Up @@ -154,7 +152,7 @@ export default class Bootstrapper {
const options = {
disableMultipleWindows: this.disableMultipleWindows,
developmentMode: this.configuration.getOption(OPTION_NAMES.developmentMode) as boolean,
nativeAutomation: this.nativeAutomation,
nativeAutomation: !this.configuration.getOption(OPTION_NAMES.disableNativeAutomation),
};

const connection = new BrowserConnection(this.browserConnectionGateway, { ...browser }, false, options, this.messageBus);
Expand All @@ -174,22 +172,23 @@ export default class Bootstrapper {
}

private async _setupProxy (): Promise<void> {
if (this.browserConnectionGateway.status === BrowserConnectionGatewayStatus.uninitialized) {
await this.configuration.calculateHostname({ nativeAutomation: this.nativeAutomation });
if (this.browserConnectionGateway.status === BrowserConnectionGatewayStatus.initialized)
return;

this.browserConnectionGateway.initialize(this.configuration.startOptions);
}
await this.configuration.calculateHostname({ nativeAutomation: !this.configuration.getOption(OPTION_NAMES.disableNativeAutomation) });

if (this.nativeAutomation)
this.browserConnectionGateway.switchToNativeAutomation();
this.browserConnectionGateway.initialize(this.configuration.startOptions);
}

private _calculateIsNativeAutomation (remotes: BrowserConnection[]): void {
// If there are remote connections, we should switch to legacy run mode.
if (remotes.length)
this.configuration.mergeOptions({ nativeAutomation: false });
private _hasNotSupportedBrowserInNativeAutomation (browserInfos: BrowserInfo[]): boolean {
return browserInfos.some(browserInfo => {
return !browserInfo.provider.supportNativeAutomation();
});
}

this.nativeAutomation = !!this.configuration.getOption(OPTION_NAMES.nativeAutomation);
private _disableNativeAutomationIfNecessary (remotes: BrowserConnection[], automated: BrowserInfo[]): void {
if (remotes.length || this._hasNotSupportedBrowserInNativeAutomation(automated))
this.configuration.mergeOptions({ disableNativeAutomation: true });
}

private async _getBrowserConnections (browserInfo: BrowserInfoSource[]): Promise<BrowserSet> {
Expand All @@ -198,7 +197,7 @@ export default class Bootstrapper {
if (remotes && remotes.length % this.concurrency)
throw new GeneralError(RUNTIME_ERRORS.cannotDivideRemotesCountByConcurrency);

this._calculateIsNativeAutomation(remotes);
this._disableNativeAutomationIfNecessary(remotes, automated);

await this._setupProxy();

Expand Down
10 changes: 4 additions & 6 deletions src/runner/test-run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import { Quarantine } from '../utils/get-options/quarantine';
import MessageBus from '../utils/message-bus';
import TestRunHookController from './test-run-hook-controller';
import * as clientScriptsRouting from '../custom-client-scripts/routing';
import debug from 'debug';
import { RUNTIME_ERRORS } from '../errors/types';
import { GeneralError } from '../errors/runtime';
import { testRunControllerLogger } from '../utils/debug-loggers';

const DISCONNECT_THRESHOLD = 3;

const debugLogger = debug('testcafe:runner:test-run-controller');

export default class TestRunController extends AsyncEventEmitter {
private readonly _quarantine: null | Quarantine;
private _disconnectionCount: number;
Expand Down Expand Up @@ -187,7 +185,7 @@ export default class TestRunController extends AsyncEventEmitter {

await this.emit('test-run-done');

debugLogger('done');
testRunControllerLogger('done');
}

private async _emitTestRunStart (): Promise<void> {
Expand Down Expand Up @@ -239,7 +237,7 @@ export default class TestRunController extends AsyncEventEmitter {
}

private async _handleNativeAutomationMode (connection: BrowserConnection): Promise<void> {
this.isNativeAutomation = !!this._opts.nativeAutomation;
this.isNativeAutomation = !this._opts.disableNativeAutomation;

const supportNativeAutomation = connection.supportNativeAutomation();

Expand All @@ -252,7 +250,7 @@ export default class TestRunController extends AsyncEventEmitter {
}

public async start (connection: BrowserConnection, startRunExecutionTime?: Date): Promise<string | null> {
debugLogger('start');
testRunControllerLogger('start');

await this._handleNativeAutomationMode(connection);

Expand Down
4 changes: 3 additions & 1 deletion src/testcafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ export default class TestCafe {

// API
async createBrowserConnection () {
// NOTE: 'remote' browser connection cannot be native automation.
const browserInfo = await browserProviderPool.getBrowserInfo('remote');

// NOTE: 'remote' browser connection cannot be in the 'native automation' mode.
this.configuration.mergeOptions({ disableNativeAutomation: true });

await this.initializeBrowserConnectionGateway();

const connection = new BrowserConnection(this.browserConnectionGateway, browserInfo, true, this.configuration.remoteBrowserConnectionOptions);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/debug-loggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const browserLogger = testcafeLogger.extend('browser');
const browserProviderLogger = browserLogger.extend('provider');
const chromeBrowserProviderLogger = browserProviderLogger.extend('chrome');

const runnerLogger = testcafeLogger.extend('runner');

const testRunControllerLogger = runnerLogger.extend('test-run-controller');

export {
nativeAutomationLogger,
requestPipelineLogger,
Expand All @@ -28,4 +32,5 @@ export {
requestPipelineServiceRequestLogger,
requestPipelineOtherRequestLogger,
requestPipelineContextLogger,
testRunControllerLogger,
};
2 changes: 1 addition & 1 deletion test/functional/fixtures/api/es-next/global-hooks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const runTestsLocal = (testName) => {
.filter(test => {
return testName ? test === testName : true;
})
.run({ nativeAutomation: config.nativeAutomation })
.run({ disableNativeAutomation: !config.nativeAutomation })
.then(failedCount => {
const taskReport = JSON.parse(stream.data);
const testReport = taskReport.fixtures.length === 1 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ createTestCafe()
return testName === 'Should log error on browser disconnect';
})
.reporter(shouldAttachReporter ? reporter : [])
.run({ nativeAutomation: config.nativeAutomation });
.run({ disableNativeAutomation: !config.nativeAutomation });
})
.catch(function () {
return testcafe.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function run (pathToTest, filter, initializeConnection = initializeConnectionLow
.filter(testName => testName === filter)
.reporter(reporter)
.browsers(connection)
.run({ nativeAutomation: config.nativeAutomation });
.run({ disableNativeAutomation: !config.nativeAutomation });
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (config.useLocalBrowsers && config.hasBrowser('chrome')) {
.filter(fixtureName => fixtureName === 'Check presence of touch event handlers')
.reporter('minimal', createNullStream())
.browsers(browserAlias)
.run({ nativeAutomation: config.nativeAutomation });
.run({ disableNativeAutomation: !config.nativeAutomation });

expect(failedCount).eql(0);
}
Expand Down Expand Up @@ -50,7 +50,7 @@ if (config.useLocalBrowsers && config.hasBrowser('chrome')) {
.src(path.join(__dirname, './testcafe-fixtures/index-test.js'))
.reporter(reporter)
.browsers('chrome:headless:emulation:device=iphone X --no-sandbox')
.run({ nativeAutomation: config.nativeAutomation });
.run({ disableNativeAutomation: !config.nativeAutomation });

expect(prettyUserAgents.length).eql(1);
expect(prettyUserAgents[0]).endsWith('(Emulating iPhone X)');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (config.useLocalBrowsers && !config.useHeadlessBrowsers && !config.hasBrowser
.src(path.join(__dirname, './testcafe-fixtures/index-test.js'))
.reporter('minimal', createNullStream())
.browsers('chrome:userProfile', 'firefox:userProfile')
.run({ nativeAutomation: config.nativeAutomation })
.run({ disableNativeAutomation: !config.nativeAutomation })
.then(failedCount => {
expect(failedCount).eql(0);
});
Expand All @@ -30,7 +30,7 @@ if (config.useLocalBrowsers && !config.useHeadlessBrowsers && !config.hasBrowser
.src(path.join(__dirname, './testcafe-fixtures/index-test.js'))
.reporter('minimal', createNullStream())
.browsers(`chrome --user-data-dir=${chromeProfile.name}`, `firefox -profile ${firefoxProfile.name}`)
.run({ nativeAutomation: config.nativeAutomation });
.run({ disableNativeAutomation: !config.nativeAutomation });
})
.then(failedCount => {
expect(failedCount).eql(0);
Expand Down
Loading

0 comments on commit c76c1ed

Please sign in to comment.