From eba39f51f88f0323aeb6bf5ddc38009fdda9c481 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 14:09:36 -0700 Subject: [PATCH 1/6] chore: extract createFile func --- test/specs/manifestBuilder.e2e.ts | 14 +------------- test/specs/miscellaneous.e2e.ts | 18 +++--------------- test/utilities/apexUtils.ts | 13 ++++--------- test/utilities/miscellaneous.ts | 10 ++++++++++ 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/test/specs/manifestBuilder.e2e.ts b/test/specs/manifestBuilder.e2e.ts index e578ae01..ceae5390 100644 --- a/test/specs/manifestBuilder.e2e.ts +++ b/test/specs/manifestBuilder.e2e.ts @@ -30,19 +30,7 @@ describe('Manifest Builder', async () => { const workbench = await browser.getWorkbench(); // Using the Command palette, run File: New File... - const inputBox = await utilities.executeQuickPick( - 'Create: New File...', - utilities.Duration.seconds(1) - ); - - // Set the name of the new manifest file - const filePath = path.join('manifest', 'manifest.xml'); - await inputBox.setText(filePath); - - // The following 3 confirms are just confirming the file creation and the folder it will belong to - await inputBox.confirm(); - await inputBox.confirm(); - await inputBox.confirm(); + await utilities.createFile(path.join('manifest', 'manifest.xml')); const textEditor = await utilities.getTextEditor(workbench, 'manifest.xml'); const content = [ diff --git a/test/specs/miscellaneous.e2e.ts b/test/specs/miscellaneous.e2e.ts index a9b7eb3c..3ae01b32 100644 --- a/test/specs/miscellaneous.e2e.ts +++ b/test/specs/miscellaneous.e2e.ts @@ -44,7 +44,7 @@ describe('Miscellaneous', async () => { const workbench = await utilities.getWorkbench(); const commandName = EnvironmentSettings.getInstance().vscodeVersion === 'stable' || - semver.gte(EnvironmentSettings.getInstance().vscodeVersion, '1.92.0') + semver.gte(EnvironmentSettings.getInstance().vscodeVersion, '1.92.0') ? 'Snippets: Configure Snippets' : 'Snippets: Configure User Snippets'; @@ -96,13 +96,7 @@ describe('Miscellaneous', async () => { ].join('\n'); // Create simple lwc.html file - const inputBox = await utilities.executeQuickPick( - 'Create: New File...', - utilities.Duration.seconds(1) - ); - await inputBox.setText('lwc.html'); - await browser.keys(['Enter']); - await browser.keys(['Enter']); + await utilities.createFile('lwc.html'); // Type snippet "lwc-button" and check it inserted the right lwc const textEditor = await utilities.getTextEditor(workbench, 'lwc.html'); @@ -130,13 +124,7 @@ describe('Miscellaneous', async () => { const lwcSnippet = 'this.dispatchEvent(new CustomEvent("event-name"));'; // Create simple lwc.js file - const inputBox = await utilities.executeQuickPick( - 'Create: New File...', - utilities.Duration.seconds(1) - ); - await inputBox.setText('lwc.js'); - await browser.keys(['Enter']); - await browser.keys(['Enter']); + await utilities.createFile('lwc.js'); // Type snippet "lwc", select "lwc-event" and check it inserted the right thing const textEditor = await utilities.getTextEditor(workbench, 'lwc.js'); diff --git a/test/utilities/apexUtils.ts b/test/utilities/apexUtils.ts index bfc171c3..d0e04863 100644 --- a/test/utilities/apexUtils.ts +++ b/test/utilities/apexUtils.ts @@ -7,7 +7,7 @@ import { TextEditor } from 'wdio-vscode-service'; import { executeQuickPick } from './commandPrompt.ts'; -import { Duration, getTextEditor, pause } from './miscellaneous.ts'; +import { Duration, getTextEditor, pause, createFile } from './miscellaneous.ts'; import { getWorkbench } from './workbench.ts'; export async function createApexClass( @@ -107,16 +107,11 @@ export async function createApexClassWithBugs(): Promise { export async function createAnonymousApexFile(): Promise { const workbench = await getWorkbench(); const editorView = workbench.getEditorView(); + const anonymousApexFileName = 'Anonymous.apex'; - // Using the Command palette, run File: New File... - const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1)); + await createFile(anonymousApexFileName); - // Set the name of the new Anonymous Apex file - await inputBox.setText('Anonymous.apex'); - await browser.keys(['Enter']); - await browser.keys(['Enter']); - - const textEditor = (await editorView.openEditor('Anonymous.apex')) as TextEditor; + const textEditor = (await editorView.openEditor(anonymousApexFileName)) as TextEditor; await textEditor.setText("System.debug('¡Hola mundo!');"); await textEditor.save(); await pause(Duration.seconds(1)); diff --git a/test/utilities/miscellaneous.ts b/test/utilities/miscellaneous.ts index 4715d77c..81da5777 100644 --- a/test/utilities/miscellaneous.ts +++ b/test/utilities/miscellaneous.ts @@ -238,3 +238,13 @@ export class Duration extends DurationKit.Duration { return new Duration(quantity, Unit.WEEKS); } } + +export async function createFile(path: string): Promise { + // Using the Command palette, run File: New File... + const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1)); + + // Set the filepath + await inputBox.setText(path); + await browser.keys(['Enter']); + await browser.keys(['Enter']); +} \ No newline at end of file From 1f643d236ddbc482def8fa7794f02be10ea97190 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 14:38:06 -0700 Subject: [PATCH 2/6] fix: correct the path of manifest --- test/specs/manifestBuilder.e2e.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/specs/manifestBuilder.e2e.ts b/test/specs/manifestBuilder.e2e.ts index ceae5390..b85a234a 100644 --- a/test/specs/manifestBuilder.e2e.ts +++ b/test/specs/manifestBuilder.e2e.ts @@ -30,9 +30,10 @@ describe('Manifest Builder', async () => { const workbench = await browser.getWorkbench(); // Using the Command palette, run File: New File... - await utilities.createFile(path.join('manifest', 'manifest.xml')); + const manifestPath = path.join('manifest', 'manifest.xml'); + await utilities.createFile(manifestPath); - const textEditor = await utilities.getTextEditor(workbench, 'manifest.xml'); + const textEditor = await utilities.getTextEditor(workbench, manifestPath); const content = [ ``, ``, From 76b15342a71e5247e97073ef0a33f5cf269506e3 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 16:28:30 -0700 Subject: [PATCH 3/6] chore: add an extra enter hit button --- test/specs/manifestBuilder.e2e.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/specs/manifestBuilder.e2e.ts b/test/specs/manifestBuilder.e2e.ts index b85a234a..3ddfdf81 100644 --- a/test/specs/manifestBuilder.e2e.ts +++ b/test/specs/manifestBuilder.e2e.ts @@ -32,6 +32,7 @@ describe('Manifest Builder', async () => { // Using the Command palette, run File: New File... const manifestPath = path.join('manifest', 'manifest.xml'); await utilities.createFile(manifestPath); + await browser.keys(['Enter']); const textEditor = await utilities.getTextEditor(workbench, manifestPath); const content = [ From 2d47eb1496b11b64d10012fccd9549b590352a2c Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 16:49:08 -0700 Subject: [PATCH 4/6] chore: update name --- test/specs/manifestBuilder.e2e.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/specs/manifestBuilder.e2e.ts b/test/specs/manifestBuilder.e2e.ts index 3ddfdf81..c9d991dc 100644 --- a/test/specs/manifestBuilder.e2e.ts +++ b/test/specs/manifestBuilder.e2e.ts @@ -30,11 +30,10 @@ describe('Manifest Builder', async () => { const workbench = await browser.getWorkbench(); // Using the Command palette, run File: New File... - const manifestPath = path.join('manifest', 'manifest.xml'); - await utilities.createFile(manifestPath); - await browser.keys(['Enter']); + await utilities.createFile(path.join('manifest', 'manifest.xml')); + await browser.keys(['Enter']); // This extra step is necessary, otherwise the process to create file here doesn't finish. - const textEditor = await utilities.getTextEditor(workbench, manifestPath); + const textEditor = await utilities.getTextEditor(workbench, 'manifest.xml'); const content = [ ``, ``, From 9c83ee723e529bcb3c4f9141f87e589a270ff6aa Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 16:58:48 -0700 Subject: [PATCH 5/6] chore: add explanation for createFile function --- test/utilities/miscellaneous.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/utilities/miscellaneous.ts b/test/utilities/miscellaneous.ts index 81da5777..68dd9195 100644 --- a/test/utilities/miscellaneous.ts +++ b/test/utilities/miscellaneous.ts @@ -239,6 +239,12 @@ export class Duration extends DurationKit.Duration { } } + +/** + * The function is not the best practice. + * We have observed that the first time you specify the path with the command works, + * But it does not work for following file creation, it will ignore the path you specify but always follow the path from the first time + */ export async function createFile(path: string): Promise { // Using the Command palette, run File: New File... const inputBox = await executeQuickPick('Create: New File...', Duration.seconds(1)); From 3bf74f84d9ef1b37cd29c0e7c7ef3ac6872b235f Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 15 Aug 2024 17:00:01 -0700 Subject: [PATCH 6/6] chore: add explanation for createFile function --- test/utilities/miscellaneous.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utilities/miscellaneous.ts b/test/utilities/miscellaneous.ts index 68dd9195..6d234b1c 100644 --- a/test/utilities/miscellaneous.ts +++ b/test/utilities/miscellaneous.ts @@ -242,7 +242,7 @@ export class Duration extends DurationKit.Duration { /** * The function is not the best practice. - * We have observed that the first time you specify the path with the command works, + * We have observed that after installing the extension, the first time you specify the path with the command works, * But it does not work for following file creation, it will ignore the path you specify but always follow the path from the first time */ export async function createFile(path: string): Promise {