Skip to content

Commit 14f3b62

Browse files
committed
chore: wip
1 parent e7edc4f commit 14f3b62

14 files changed

+233
-112
lines changed

package-lock.json

Lines changed: 136 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
},
1818
"homepage": "https://github.com/forcedotcom/salesforcedx-vscode-automation-tests-redhat#readme",
1919
"devDependencies": {
20+
"@salesforce/kit": "^3.2.1",
21+
"@types/chai": "^4.3.17",
22+
"@types/cross-spawn": "^6.0.6",
23+
"@types/mocha": "^10.0.7",
24+
"@types/mocha-steps": "^1.3.3",
25+
"chai": "^5.1.1",
26+
"cross-spawn": "^7.0.3",
2027
"fast-glob": "^3.3.2",
28+
"mocha": "^10.7.3",
29+
"mocha-steps": "^1.3.0",
2130
"vscode-extension-tester": "^8.5.0"
2231
}
2332
}

test/specs/apexLsp.e2e.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { step } from 'mocha-steps';
87
import { TestSetup } from '../testSetup.ts';
98
import * as utilities from '../utilities/index.ts';
109
import { EnvironmentSettings } from '../environmentSettings.ts';
10+
import { Key } from 'vscode-extension-tester';
11+
import { expect } from 'chai';
1112

12-
import { Key } from 'webdriverio';
13-
const CMD_KEY = process.platform === 'darwin' ? Key.Command : Key.Control;
13+
const CMD_KEY = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL;
1414

1515
describe('Apex LSP', async () => {
1616
let testSetup: TestSetup;
@@ -29,16 +29,16 @@ describe('Apex LSP', async () => {
2929
utilities.log(`${testSetup.testSuiteSuffixName} - Verify Extension is Running`);
3030

3131
// Using the Command palette, run Developer: Show Running Extensions
32-
await utilities.showRunningExtensions();
32+
const re = await utilities.showRunningExtensions();
3333
await utilities.zoom('Out', 4, utilities.Duration.seconds(1));
3434
// Verify Apex extension is present and running
3535
const foundExtensions = await utilities.verifyExtensionsAreRunning(
3636
utilities.getExtensionsToVerifyActive((ext) => ext.extensionId === 'salesforcedx-vscode-apex')
3737
);
3838
await utilities.zoomReset();
39-
await expect(foundExtensions).toBe(true);
39+
expect(foundExtensions).to.be.true;
4040
// Close running extensions view
41-
await browser.keys([CMD_KEY, 'w']);
41+
await re?.close();
4242
});
4343

4444
step('Verify LSP finished indexing', async () => {
@@ -125,3 +125,7 @@ describe('Apex LSP', async () => {
125125
await testSetup?.tearDown();
126126
});
127127
});
128+
function step(arg0: string, arg1: () => Promise<void>) {
129+
throw new Error('Function not implemented.');
130+
}
131+

test/utilities/apexUtils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8+
import { Key } from 'vscode-extension-tester';
89
import { executeQuickPick } from './commandPrompt.ts';
910
import { Duration, getTextEditor, pause } from './miscellaneous.ts';
10-
import { getBrowser, getWorkbench } from './workbench.ts';
11+
import { getWorkbench } from './workbench.ts';
1112

1213
export async function createApexClass(
1314
name: string,
@@ -22,11 +23,11 @@ export async function createApexClass(
2223
// Set the name of the new Apex Class
2324
await inputBox.setText(name);
2425
await pause(Duration.seconds(1));
25-
await getBrowser().keys(['Enter']);
26+
await inputBox.sendKeys(Key.ENTER);
2627
await pause(Duration.seconds(1));
2728

2829
// Select the default directory (press Enter/Return).
29-
await browser.keys(['Enter']);
30+
await inputBox.sendKeys(Key.ENTER);
3031
await pause(Duration.seconds(1));
3132

3233
// Modify class content
@@ -104,18 +105,18 @@ export async function createApexClassWithBugs(): Promise<void> {
104105
}
105106

106107
export async function createAnonymousApexFile(): Promise<void> {
107-
const workbench = await getWorkbench();
108+
const workbench = getWorkbench();
108109
const editorView = workbench.getEditorView();
109110

110111
// Using the Command palette, run File: New File...
111112
const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1));
112113

113114
// Set the name of the new Anonymous Apex file
114115
await inputBox.setText('Anonymous.apex');
115-
await browser.keys(['Enter']);
116-
await browser.keys(['Enter']);
116+
await inputBox.sendKeys(Key.ENTER);
117+
await inputBox.sendKeys(Key.ENTER);
117118

118-
const textEditor = (await editorView.openEditor('Anonymous.apex')) as TextEditor;
119+
const textEditor = await getTextEditor(workbench, 'Anonymous.apex');
119120
await textEditor.setText("System.debug('¡Hola mundo!');");
120121
await textEditor.save();
121122
await pause(Duration.seconds(1));

test/utilities/commandPrompt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { debug, Duration, log, pause } from './miscellaneous.ts';
99
import { getBrowser, getWorkbench } from './workbench.ts';
10-
import { By, InputBox, QuickOpenBox, Workbench } from 'vscode-extension-tester';
10+
import { By, InputBox, Key, QuickOpenBox, Workbench } from 'vscode-extension-tester';
1111

1212
export async function openCommandPromptWithCommand(
1313
workbench: Workbench,
@@ -169,6 +169,8 @@ export async function clickFilePathOkButton(): Promise<void> {
169169
}
170170

171171
await pause(Duration.milliseconds(500));
172+
okButton.sendKeys(Key.ENTER);
173+
await pause(Duration.seconds(1));
172174

173175
const buttons = await browser.findElements(By.css('a.monaco-button.monaco-text-button'));
174176
for (const item of buttons) {

test/utilities/jsonUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getTextEditor, pause } from './miscellaneous.ts';
2+
import { getWorkbench } from './workbench.ts';
23

34
export async function createSfdxProjectJsonWithAllFields(): Promise<void> {
4-
const workbench = await (await browser.getWorkbench()).wait();
55
const sfdxConfig = [
66
`{`,
77
`\t"packageDirectories": [`,
@@ -15,7 +15,7 @@ export async function createSfdxProjectJsonWithAllFields(): Promise<void> {
1515
`\t"sourceBehaviorOptions": ["decomposeCustomLabelsBeta", "decomposePermissionSetBeta", "decomposeWorkflowBeta", "decomposeSharingRulesBeta"]`,
1616
`}`
1717
].join('\n');
18-
const textEditor = await getTextEditor(workbench, 'sfdx-project.json');
18+
const textEditor = await getTextEditor(getWorkbench(), 'sfdx-project.json');
1919
await textEditor.setText(sfdxConfig);
2020
await textEditor.save();
2121
await pause();

test/utilities/lwcUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8+
import { Key } from 'vscode-extension-tester';
89
import { executeQuickPick } from './commandPrompt.ts';
910
import { Duration, getTextEditor, log, pause } from './miscellaneous.ts';
10-
import { getWorkbench } from './workbench.ts';
11+
import { getBrowser, getWorkbench } from './workbench.ts';
1112

12-
import { Key } from 'webdriverio';
13-
const CMD_KEY = process.platform === 'darwin' ? Key.Command : Key.Control;
13+
const CMD_KEY = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL;
1414

1515
export async function createLwc(name: string): Promise<void> {
1616
log('createLwc() - calling browser.getWorkbench()');
@@ -103,8 +103,9 @@ export async function createLwc(name: string): Promise<void> {
103103
await textEditor.save();
104104
await pause(Duration.seconds(1));
105105

106+
const browser = getBrowser();
106107
// Set breakpoints
107-
await browser.keys([CMD_KEY, 'f']);
108+
await browser.send([CMD_KEY, 'f']);
108109
await pause(Duration.seconds(1));
109110
await browser.keys(`await expect(div.textContent).toBe('Hello, World!');`);
110111
await browser.keys(['Escape']);

test/utilities/miscellaneous.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*/
77

88
import os from 'os';
9-
import { TextEditor, Workbench, sleep } from 'wdio-vscode-service';
109
import { EnvironmentSettings } from '../environmentSettings.ts';
1110
import { attemptToFindOutputPanelText, clearOutputView } from './outputView.ts';
1211
import { executeQuickPick, findQuickPickItem } from './commandPrompt.ts';
1312
import { notificationIsPresentWithTimeout } from './notifications.ts';
1413
import * as DurationKit from '@salesforce/kit';
1514
import path from 'path';
1615
import { PredicateWithTimeout } from './predicates.ts';
16+
import { By, TextEditor, WebElement, Workbench } from 'vscode-extension-tester';
17+
import { getBrowser, getWorkbench } from './workbench.ts';
18+
import { expect } from 'chai';
1719

1820
export async function pause(duration: Duration = Duration.seconds(1)): Promise<void> {
1921
await sleep(duration.milliseconds);
@@ -73,22 +75,24 @@ export async function findElementByText(
7375
reverse?: boolean;
7476
timeoutMsg?: string;
7577
}
76-
): Promise<WebdriverIO.Element> {
78+
): Promise<WebElement> {
7779
if (!labelText) {
7880
throw new Error('labelText must be defined');
7981
}
8082
debug(`findElementByText ${type}[${attribute}="${labelText}"]`);
81-
const element = await $(`${type}[${attribute}="${labelText}"]`);
83+
const element = await getWorkbench().findElement(By.xpath(`${type}[${attribute}="${labelText}"]`));
8284
if (!element) {
8385
throw new Error(`Element with selector: "${type}[${attribute}=\"${labelText}\"]" not found}`);
8486
}
8587
if (waitForClickable) {
86-
await element.waitForClickable({
87-
timeout: waitOptions?.timeout?.milliseconds ?? Duration.seconds(5).milliseconds,
88-
interval: waitOptions?.interval?.milliseconds ?? Duration.milliseconds(500).milliseconds,
89-
reverse: waitOptions?.reverse,
90-
timeoutMsg: waitOptions?.timeoutMsg
91-
});
88+
await getBrowser().wait(async () => {
89+
const isDisplayedAndEnabled = await element.isDisplayed() && await element.isEnabled();
90+
return waitOptions?.reverse ? !isDisplayedAndEnabled : isDisplayedAndEnabled;
91+
},
92+
waitOptions?.timeout?.milliseconds ?? Duration.seconds(5).milliseconds,
93+
waitOptions?.timeoutMsg,
94+
waitOptions?.interval?.milliseconds ?? Duration.milliseconds(500).milliseconds,
95+
);
9296
}
9397

9498
return element;
@@ -130,16 +134,16 @@ export async function createCommand(
130134
`SFDX: Create ${type} successfully ran`,
131135
Duration.minutes(10)
132136
);
133-
await expect(successNotificationWasFound).toBe(true);
137+
expect(successNotificationWasFound).to.be.true;
134138

135139
const outputPanelText = await attemptToFindOutputPanelText(
136140
`Salesforce CLI`,
137141
`Finished SFDX: Create ${type}`,
138142
10
139143
);
140-
await expect(outputPanelText).not.toBeUndefined();
144+
expect(outputPanelText).not.to.be.ok;
141145
const typePath = path.join(`force-app`, `main`, `default`, folder, `${name}.${extension}`);
142-
await expect(outputPanelText).toContain(`create ${typePath}`);
146+
expect(outputPanelText).to.include(`create ${typePath}`);
143147

144148
const metadataPath = path.join(
145149
`force-app`,
@@ -148,7 +152,7 @@ export async function createCommand(
148152
folder,
149153
`${name}.${extension}-meta.xml`
150154
);
151-
await expect(outputPanelText).toContain(`create ${metadataPath}`);
155+
expect(outputPanelText).to.include(`create ${metadataPath}`);
152156
return outputPanelText;
153157
}
154158

@@ -238,3 +242,9 @@ export class Duration extends DurationKit.Duration {
238242
return new Duration(quantity, Unit.WEEKS);
239243
}
240244
}
245+
246+
export async function sleep(duration: number): Promise<void> {
247+
return new Promise((resolve) => {
248+
setTimeout(resolve, duration);
249+
});
250+
}

test/utilities/notifications.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { Notification } from 'wdio-vscode-service';
98
import { Duration } from './miscellaneous.ts';
10-
import { getWorkbench } from './workbench.ts';
9+
import { getBrowser, getWorkbench } from './workbench.ts';
1110
import { executeQuickPick } from './commandPrompt.ts';
1211

1312
export async function waitForNotificationToGoAway(
@@ -60,7 +59,7 @@ export async function dismissNotification(
6059
timeout = Duration.seconds(1)
6160
): Promise<void> {
6261
const notification = await findNotification(notificationMessage, true, timeout, true);
63-
await notification?.dismiss();
62+
notification?.close();
6463
}
6564

6665
export async function acceptNotification(
@@ -90,10 +89,10 @@ async function findNotification(
9089
timeout: Duration = Duration.milliseconds(500),
9190
throwOnTimeout: boolean = false // New parameter to control throwing on timeout
9291
): Promise<Notification | null> {
93-
const workbench = await getWorkbench();
92+
const workbench = getWorkbench();
9493

9594
try {
96-
const foundNotification = await browser.waitUntil(
95+
const foundNotification = await getBrowser().wait(
9796
async () => {
9897
const notifications = await workbench.getNotifications();
9998
let bestMatch: Notification | null = null;
@@ -111,11 +110,8 @@ async function findNotification(
111110
} else {
112111
return bestMatch === null;
113112
}
114-
},
115-
{
116-
timeout: timeout.milliseconds,
117-
timeoutMsg: `Notification with message "${message}" ${shouldBePresent ? 'not found' : 'still present'} within the specified timeout of ${timeout.seconds} seconds.`
118-
}
113+
}, timeout.milliseconds,
114+
`Notification with message "${message}" ${shouldBePresent ? 'not found' : 'still present'} within the specified timeout of ${timeout.seconds} seconds.`
119115
);
120116

121117
return shouldBePresent ? foundNotification : null;

test/utilities/orgBrowser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7+
import { WebElement } from 'vscode-extension-tester';
78
import { executeQuickPick } from './commandPrompt.ts';
89
import { Duration, findElementByText } from './miscellaneous.ts';
10+
import { expect } from 'chai';
911

1012
export async function openOrgBrowser(wait: Duration = Duration.seconds(1)): Promise<void> {
1113
await executeQuickPick('View: Show Org Browser', wait);
@@ -17,9 +19,9 @@ export async function verifyOrgBrowserIsOpen(label: string): Promise<void> {
1719
'aria-label',
1820
label
1921
);
20-
await expect(orgBrowserLabelEl).toBeTruthy();
22+
expect(orgBrowserLabelEl).to.be.ok;
2123
}
2224

23-
export async function findTypeInOrgBrowser(type: string): Promise<WebdriverIO.Element> {
25+
export async function findTypeInOrgBrowser(type: string): Promise<WebElement> {
2426
return await findElementByText('div', 'aria-label', type);
2527
}

0 commit comments

Comments
 (0)