Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #66 from jupyterlab/fix_chrome_remote_connect
Browse files Browse the repository at this point in the history
fix remote connection to chromium browser
  • Loading branch information
mbektas authored Jul 25, 2021
2 parents 7500160 + 610f1ba commit ab2b9d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
12 changes: 9 additions & 3 deletions packages/galata/jest-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ class TestEnvironment extends NodeEnvironment {
let browser;

try {
browser = await pwBrowser.connect({
wsEndpoint: sessionInfo.wsEndpoint
});
if (browserType === 'chromium' && config.browserUrl !== '') {
browser = await pwBrowser.connectOverCDP({
endpointURL: sessionInfo.wsEndpoint
});
} else {
browser = await pwBrowser.connect({
wsEndpoint: sessionInfo.wsEndpoint
});
}
} catch (reason) {
const message = `Failed to connect to browser using wsEndpoint ${sessionInfo.wsEndpoint}`;
log('error', message);
Expand Down
21 changes: 16 additions & 5 deletions packages/galata/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ module.exports = async function () {
const headless = config.headless;
const slowMo = config.slowMo;
let browser;
let wsEndpoint;

if (config.browserUrl !== '') {
try {
const apiUrl = `${config.browserUrl}/json/version`;
const response = await axios.get(apiUrl);
browser = await pwBrowser.connect({
wsEndpoint: response.data.webSocketDebuggerUrl,
slowMo: slowMo
});
wsEndpoint = response.data.webSocketDebuggerUrl;
if (browserType === 'chromium') {
browser = await pwBrowser.connectOverCDP({
endpointURL: wsEndpoint,
slowMo: slowMo
});
} else {
browser = await pwBrowser.connect({
wsEndpoint: wsEndpoint,
slowMo: slowMo
});
}
} catch (reason) {
await logAndExit(
'error',
Expand Down Expand Up @@ -104,6 +113,7 @@ module.exports = async function () {
},
slowMo: slowMo
});
wsEndpoint = browser.wsEndpoint();
} catch (reason) {
await logAndExit(
'error',
Expand All @@ -119,6 +129,7 @@ module.exports = async function () {
const sessionInfo = {
testId: config.testId,
browserType: config.browserType,
browserUrl: config.browserUrl,
testOutputDir: config.testOutputDir,
referenceDir: config.referenceDir,
jlabBaseUrl: config.jlabBaseUrl,
Expand All @@ -127,7 +138,7 @@ module.exports = async function () {
skipVisualRegression: config.skipVisualRegression === true,
skipHtmlRegression: config.skipHtmlRegression === true,
discardMatchedCaptures: config.discardMatchedCaptures !== false,
wsEndpoint: browser.wsEndpoint(),
wsEndpoint: wsEndpoint,
buildJlabVersion: getBuildJlabVersion(),
imageMatchThreshold: config.imageMatchThreshold
};
Expand Down
8 changes: 2 additions & 6 deletions packages/galata/jest-teardown.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// Copyright (c) Bloomberg Finance LP.
// Distributed under the terms of the Modified BSD License.

const { getConfig, saveLogsToFile } = require('./util');

const config = getConfig();
const { saveLogsToFile } = require('./util');

module.exports = async function () {
if (config.browserUrl === '') {
await global.__BROWSER_GLOBAL__.close();
}
await global.__BROWSER_GLOBAL__.close();

saveLogsToFile('jest-logs.json');
};

0 comments on commit ab2b9d1

Please sign in to comment.