Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update to electron 10.1.5 #3599

Merged
merged 34 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
be749ea
update electron dep
karanbirsingh Oct 27, 2020
fde8c4b
Merge branch 'master' of https://github.com/microsoft/accessibility-i…
karanbirsingh Oct 27, 2020
b3e5088
electron10, spectron broken, issue spectron@720
karanbirsingh Oct 27, 2020
fa1bb51
unit test updates
karanbirsingh Oct 28, 2020
d705b74
update asset number
karanbirsingh Oct 28, 2020
1db1807
fix merge conflict
karanbirsingh Oct 28, 2020
3f13dc3
some cleaning
karanbirsingh Oct 28, 2020
faafcfe
remove errant spacing introduced by manual merge
karanbirsingh Oct 28, 2020
d030231
add caret
karanbirsingh Oct 28, 2020
e145094
make selctor required param
karanbirsingh Oct 28, 2020
aa176b0
update comment
karanbirsingh Oct 28, 2020
d5ee412
Merge branch 'master' of https://github.com/microsoft/accessibility-i…
karanbirsingh Oct 28, 2020
e226464
merge
karanbirsingh Oct 29, 2020
ee025b4
remove comment
karanbirsingh Oct 29, 2020
7d77ff1
double timeout on waitforselectortodisappear to allow for implicit ti…
karanbirsingh Oct 29, 2020
1e6aef4
Add same webPreferences to codec test app that we add in main applica…
karanbirsingh Oct 31, 2020
1e2a5ce
merge with main
karanbirsingh Oct 31, 2020
460cfd8
merge with upstream changes
karanbirsingh Nov 2, 2020
874f32d
omit CG for test builds
karanbirsingh Nov 2, 2020
1440f0f
manually port changes from #3591
karanbirsingh Nov 2, 2020
fdb4bdf
Revert "manually port changes from #3591"
karanbirsingh Nov 2, 2020
8e32bab
pull in upstream changes
karanbirsingh Nov 2, 2020
e2dc000
add comment about remote module usage
karanbirsingh Nov 2, 2020
f370a24
re-add CG now that test builds are done
karanbirsingh Nov 2, 2020
9be2f85
use explicit waitFor timeout parametmer
karanbirsingh Nov 2, 2020
45b0329
check if retry catches webdriver ECONNRESETissue
karanbirsingh Nov 3, 2020
58b70a3
Revert "check if retry catches webdriver ECONNRESETissue"
karanbirsingh Nov 3, 2020
247623b
Try adding agent-base resolution to work around ECONNRESET issue ment…
karanbirsingh Nov 3, 2020
6152b40
Revert global waitForTimeout to implicit 5 and double wrapping timeou…
karanbirsingh Nov 3, 2020
eaf0e34
merge w upstream
karanbirsingh Nov 3, 2020
759bef3
retry econnreset
karanbirsingh Nov 3, 2020
c58aa36
merge with upstream
karanbirsingh Nov 3, 2020
594be0a
combine msgs
karanbirsingh Nov 3, 2020
4a92556
remove agent base resolution in favor of retry
karanbirsingh Nov 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"serve-static": "^1.13.2",
"simple-git": "^2.21.0",
"source-map-loader": "^1.1.2",
"spectron": "^10.0.1",
"spectron": "^12.0.0",
"terser-webpack-plugin": "^4.2.3",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.7",
Expand All @@ -163,7 +163,7 @@
"axe-core": "4.0.2",
"axios": "^0.21.0",
"classnames": "^2.2.6",
"electron": "8.4.1",
"electron": "10.1.5",
"electron-log": "^4.3.0",
"electron-updater": "^4.3.5",
"idb-keyval": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion pipeline/scripts/download-electron-mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
process.exit(1);
}

const assetNumber = '5424028';
const assetNumber = '6179765';

const downloadMirrors = async () => {
await downloadElectronArtifact('electron', 'node_modules/electron/dist');
Expand Down
3 changes: 2 additions & 1 deletion src/electron/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const electronAutoUpdateCheck = new AutoUpdaterClient(autoUpdater);
const createWindow = () => {
mainWindow = new BrowserWindow({
show: false,
webPreferences: { nodeIntegration: true },
// enableRemoteModule required for spectron (https://github.com/electron-userland/spectron/issues/693#issuecomment-696957538)
webPreferences: { nodeIntegration: true, enableRemoteModule: true },
titleBarStyle: 'hidden',
width: mainWindowConfig.defaultWidth,
height: mainWindowConfig.defaultHeight,
Expand Down
4 changes: 3 additions & 1 deletion src/tests/electron/common/create-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export async function createAppController(
operationLabel: 'app.start',
warnOnRetry: true,
maxRetries: DEFAULT_CHROMEDRIVER_START_RETRIES,
retryOnlyIfMatches: err => err?.message?.includes('ChromeDriver did not start within'),
retryOnlyIfMatches: err =>
err?.message?.includes('ChromeDriver did not start within') ||
err?.message?.includes('Failed to create session.\nread ECONNRESET'),
},
);

Expand Down
7 changes: 1 addition & 6 deletions src/tests/electron/common/scan-for-accessibility-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function runAxeScan(
},
};

const executeOutput = await spectronClient.executeAsync(
const axeResults = await spectronClient.executeAsync(
(options, selectorInEvaluate, done) => {
const elementContext =
selectorInEvaluate === null ? document : { include: [selectorInEvaluate] };
Expand All @@ -55,11 +55,6 @@ async function runAxeScan(
selector,
);

// This is how webdriverio indicates success
expect(executeOutput).toHaveProperty('status', 0);

const axeResults = executeOutput.value;

return prettyPrintAxeViolations(axeResults);
}

Expand Down
35 changes: 21 additions & 14 deletions src/tests/electron/common/view-controllers/app-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { AndroidSetupStepId } from 'electron/platform/android/setup/android-setu
import { Application } from 'spectron';
import { AndroidSetupViewController } from 'tests/electron/common/view-controllers/android-setup-view-controller';
import { DeviceConnectionDialogController } from 'tests/electron/common/view-controllers/device-connection-dialog-controller';
import { SpectronAsyncClient } from 'tests/electron/common/view-controllers/spectron-async-client';
import {
getSpectronAsyncClient,
SpectronAsyncClient,
} from 'tests/electron/common/view-controllers/spectron-async-client';
import { DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS } from 'tests/electron/setup/timeouts';
import { AutomatedChecksViewController } from './automated-checks-view-controller';

export class AppController {
public client: SpectronAsyncClient;

constructor(public app: Application) {
this.client = app.client as any;
this.client = getSpectronAsyncClient(app.client, app.browserWindow);
}

public async stop(): Promise<void> {
Expand All @@ -28,8 +31,10 @@ export class AppController {
const title = await this.app.webContents.getTitle();
return title === expectedTitle;
},
timeout,
`was expecting window title to transition to ${expectedTitle} within ${timeout}ms`,
{
timeout,
timeoutMsg: `was expecting window title to transition to ${expectedTitle} within ${timeout}ms`,
},
);
}

Expand Down Expand Up @@ -77,13 +82,15 @@ export class AppController {

await this.client.waitUntil(
async () => {
const classes = await this.client.getAttribute<string>('body', 'class');
const classes = await this.client.getAttribute('body', 'class');
return expectedHighContrastMode === classes.includes(highContrastThemeClass);
},
DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS,
`was expecting body element ${
expectedHighContrastMode ? 'with' : 'without'
} class high-contrast-theme`,
{
timeout: DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS,
timeoutMsg: `was expecting body element ${
expectedHighContrastMode ? 'with' : 'without'
} class high-contrast-theme`,
},
);
}

Expand All @@ -108,14 +115,14 @@ export class AppController {
): Promise<void> {
await this.client.waitUntil(
async () => {
const executeOutput = await this.client.executeAsync((prop, done) => {
return await this.client.executeAsync((prop, done) => {
done((window as any)[prop] != null);
}, propertyName);

return executeOutput.status === 0 && executeOutput.value === true;
},
DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS,
`was expecting window.${propertyName} to be defined`,
{
timeout: DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS,
timeoutMsg: `was expecting window.${propertyName} to be defined`,
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AutomatedChecksViewController extends ViewController {

public async setToggleState(toggleSelector: string, newState: boolean): Promise<void> {
await this.waitForSelector(toggleSelector);
const oldState = await this.client.getAttribute<string>(toggleSelector, 'aria-checked');
const oldState = await this.client.getAttribute(toggleSelector, 'aria-checked');

const oldStateBool = oldState.toLowerCase() === 'true';
if (oldStateBool !== newState) {
Expand Down
91 changes: 71 additions & 20 deletions src/tests/electron/common/view-controllers/spectron-async-client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { SpectronWindow } from 'spectron';
import { SpectronClient, SpectronWindow } from 'spectron';
import * as WebDriverIO from 'webdriverio';

// spectron 10.0.1 includes @types/webdriverio, whose absence
// we worked around when initially consuming spectron.
// @types/webdriver lacks promises, so this file adds
// promise-based signatures that our e2e code can rely on.
// @types/webdriver has been superceded by improved types
// in webdriverio 5 directly, but Spectron has not consumed them
// This file worked around incorrect or missing spectron/webdriverio
// typings in the past. webdriverio types are improved in spectron 12.0.0,
// so parts of this file can be removed by updating individual end-to-end
// tests/controllers to consume SpectronClient directly. SpectronAsyncWindow
// works around github issue spectron@343

export function getSpectronAsyncClient(client: SpectronClient, browserWindow: SpectronWindow) {
const typedAsyncClient: SpectronAsyncClient = {
browserWindow: (browserWindow as unknown) as SpectronAsyncWindow,
$: (selector: string) => client.$(selector),
$$: (selector: string) => client.$$(selector),
click: async (selector: string) => {
const element = await client.$(selector);
return await element.click();
},
execute: (script: string | ((...args: any[]) => void), ...args: any[]) =>
client.execute(script, ...args),
executeAsync: (script: string | ((...args: any[]) => void), ...args: any[]) =>
client.executeAsync(script, ...args),
getAttribute: async (selector: string, attributeName: string) => {
const element = await client.$(selector);
return await element.getAttribute(attributeName);
},
getText: async (selector: string) => {
const element = await client.$(selector);
return await element.getText();
},
isEnabled: async (selector: string) => {
const element = await client.$(selector);
return await element.isEnabled();
},
keys: (keys: string) => client.keys(keys),
pause: (milliseconds: number) => client.pause(milliseconds),
waitForEnabled: async (selector: string, milliseconds?: number, reverse?: boolean) => {
const element = await client.$(selector);
return await element.waitForEnabled({
timeout: milliseconds,
reverse,
});
},
waitForExist: async (
selector: string,
milliseconds?: number,
reverse?: boolean,
timeoutMsg?: string,
) => {
const element = await client.$(selector);
return await element.waitForExist({
timeout: milliseconds,
reverse,
timeoutMsg,
});
},
waitUntil: (condition: () => Promise<Boolean>, options?: WebDriverIO.WaitUntilOptions) =>
client.waitUntil(condition, options),
};
return typedAsyncClient;
}

export interface SpectronAsyncWindow {
restore(): Promise<void>;
Expand All @@ -20,26 +72,25 @@ export interface SpectronAsyncWindow {
export interface SpectronAsyncClient {
// https://github.com/electron-userland/spectron/blob/cd733c4bc6b28eb5a1041ed79eef5563e75432ae/lib/api.js#L311
browserWindow: SpectronAsyncWindow;

$(selector: string): Promise<WebDriverIO.RawResult<any>>;
$$(selector: string): Promise<WebDriverIO.RawResult<any>[]>;
click(selector?: string): Promise<void>;
$(selector: string): Promise<WebDriverIO.Element>;
$$(selector: string): Promise<WebDriverIO.Element[]>;
click(selector: string): Promise<void>;
executeAsync(script: string | ((...args: any[]) => void), ...args: any[]): Promise<any>;
execute(script: string | ((...args: any[]) => void), ...args: any[]): Promise<any>;
getAttribute<P>(selector: string, attributeName: string): Promise<P>;
getAttribute(selector: string, attributeName: string): Promise<string>;
getText(selector?: string): Promise<string>;
isEnabled(selector?: string): Promise<boolean>;
keys(keys: string): Promise<void>;
pause(milliseconds: number): Promise<void>;
waitForEnabled(selector: string, milliseconds?: number, reverse?: boolean): Promise<boolean>;
waitForExist(selector: string, milliseconds?: number, reverse?: boolean): Promise<boolean>;
waitUntil(
condition: () =>
| boolean
| Promise<boolean>
| (WebDriverIO.Client<WebDriverIO.RawResult<any>> & WebDriverIO.RawResult<any>),
timeout?: number,
waitForExist(
selector: string,
milliseconds?: number,
reverse?: boolean,
timeoutMsg?: string,
interval?: number,
): Promise<boolean>;
waitUntil(
condition: () => Promise<Boolean>,
options?: WebDriverIO.WaitUntilOptions,
): Promise<boolean>;
}
19 changes: 11 additions & 8 deletions src/tests/electron/common/view-controllers/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ export abstract class ViewController {
async () => {
return (await this.client.$$(selector)).length === expectedNumber;
},
timeout,
`expected to find ${expectedNumber} matches for selector ${selector} within ${timeout}ms`,
{
timeout,
timeoutMsg: `expected to find ${expectedNumber} matches for selector ${selector} within ${timeout}ms`,
},
);
});
}

// Webdriver waits the full implicit waitForTimeout before returning not-found.
// This means we need to wrap the waitForExist call with a longer timeout when
// reverse is true. See webdriverio@2082 and ai-web@3599.
public async waitForSelectorToDisappear(
selector: string,
timeout: number = DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS,
timeout: number = DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS * 2,
): Promise<void> {
await this.screenshotOnError(async () =>
this.client.waitUntil(
async () => {
const selected = await this.client.$(selector);
return selected.value === null;
},
this.client.waitForExist(
selector,
timeout,
true,
`was expecting element by selector ${selector} to disappear`,
),
);
Expand Down
9 changes: 3 additions & 6 deletions src/tests/electron/tests/automated-checks-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { AutomatedChecksViewController } from 'tests/electron/common/view-contro
import { commonAdbConfigs, setupMockAdb } from 'tests/miscellaneous/mock-adb/setup-mock-adb';
import { testResourceServerConfig } from '../setup/test-resource-server-config';
import { androidTestConfigs } from 'electron/platform/android/test-configs/android-test-configs';
import { RawResult } from 'webdriverio';

describe('AutomatedChecksView', () => {
let app: AppController;
Expand Down Expand Up @@ -151,7 +150,7 @@ describe('AutomatedChecksView', () => {
'data:image/png;base64,' + axeRuleResultExample.axeContext.screenshot;

await automatedChecksView.waitForSelector(ScreenshotViewSelectors.screenshotImage);
const actualScreenshotImage = await automatedChecksView.client.getAttribute<string>(
const actualScreenshotImage = await automatedChecksView.client.getAttribute(
ScreenshotViewSelectors.screenshotImage,
'src',
);
Expand All @@ -161,11 +160,9 @@ describe('AutomatedChecksView', () => {

it('ScreenshotView renders expected number/size of highlight boxes in expected positions', async () => {
await automatedChecksView.waitForSelector(ScreenshotViewSelectors.highlightBox);
const styles = await automatedChecksView.client.getAttribute<string[]>(
ScreenshotViewSelectors.highlightBox,
'style',
);

const boxes = await automatedChecksView.client.$$(ScreenshotViewSelectors.highlightBox);
const styles = await Promise.all(boxes.map(async b => await b.getAttribute('style')));
const actualHighlightBoxStyles = styles.map(extractPositionStyles);
verifyHighlightBoxStyles(actualHighlightBoxStyles, [
{ width: 10.7407, height: 6.04167, top: 3.28125, left: 89.2593 },
Expand Down
7 changes: 6 additions & 1 deletion src/tests/miscellaneous/codecs/codecs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const { app, BrowserWindow } = require('electron');

app.whenReady().then(() => {
const win = new BrowserWindow();
const win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
});
win.loadFile('codecs.html');
});
Loading