diff --git a/test/sanity/src/server.test.ts b/test/sanity/src/server.test.ts index b07375800d8..f425826638f 100644 --- a/test/sanity/src/server.test.ts +++ b/test/sanity/src/server.test.ts @@ -101,19 +101,10 @@ export function setup(context: TestContext) { const port = /Extension host agent listening on (\d+)/.exec(text)?.[1]; if (port) { - (async function () { - try { - const url = `http://localhost:${port}/version`; - context.log(`Fetching ${url}`); - const response = await fetch(url); - assert.equal(response.status, 200); - assert.equal(await response.text(), context.commit); - } catch (error) { - assert.fail(error instanceof Error ? error.message : String(error)); - } finally { - context.killProcessTree(server.pid!); - } - })(); + const url = `http://localhost:${port}/version`; + runWebTest(url) + .catch(error => assert.fail(error instanceof Error ? error.message : String(error))) + .finally(() => context.killProcessTree(server.pid!)); } }); @@ -122,5 +113,12 @@ export function setup(context: TestContext) { server.on('exit', resolve); }); } + + async function runWebTest(url: string) { + context.log(`Fetching ${url}`); + const response = await fetch(url); + assert.equal(response.status, 200); + assert.equal(await response.text(), context.commit); + } }); } diff --git a/test/sanity/src/serverWeb.test.ts b/test/sanity/src/serverWeb.test.ts index f711bf4dac4..04726fcec4f 100644 --- a/test/sanity/src/serverWeb.test.ts +++ b/test/sanity/src/serverWeb.test.ts @@ -111,33 +111,10 @@ export function setup(context: TestContext) { const port = /Extension host agent listening on (\d+)/.exec(text)?.[1]; if (port) { - (async function () { - try { - const browser = await context.launchBrowser(); - const page = await browser.newPage(); - - const url = `http://localhost:${port}?tkn=${token}&folder=/${test.workspaceDir.replaceAll(path.sep, '/')}`; - context.log(`Navigating to ${url}`); - await page.goto(url, { waitUntil: 'networkidle' }); - - context.log('Waiting for the workbench to load'); - await page.waitForSelector('.monaco-workbench'); - - context.log('Verifying page title contains "Visual Studio Code"'); - assert.match(await page.title(), /Visual Studio Code/); - - await test.run(page); - - context.log('Closing browser'); - await browser.close(); - - test.validate(); - } catch (error) { - assert.fail(error instanceof Error ? error.message : String(error)); - } finally { - context.killProcessTree(server.pid!); - } - })(); + const url = `http://localhost:${port}?tkn=${token}&folder=/${test.workspaceDir.replaceAll(path.sep, '/')}`; + runUITest(url, test) + .catch(error => assert.fail(error instanceof Error ? error.message : String(error))) + .finally(() => context.killProcessTree(server.pid!)); } }); @@ -146,5 +123,26 @@ export function setup(context: TestContext) { server.on('exit', resolve); }); } + + async function runUITest(url: string, test: UITest) { + const browser = await context.launchBrowser(); + const page = await browser.newPage(); + + context.log(`Navigating to ${url}`); + await page.goto(url, { waitUntil: 'networkidle' }); + + context.log('Waiting for the workbench to load'); + await page.waitForSelector('.monaco-workbench'); + + context.log('Verifying page title contains "Visual Studio Code"'); + assert.match(await page.title(), /Visual Studio Code/); + + await test.run(page); + + context.log('Closing browser'); + await browser.close(); + + test.validate(); + } }); } diff --git a/test/sanity/src/uiTest.ts b/test/sanity/src/uiTest.ts index c79127c4178..94f7aba5c7c 100644 --- a/test/sanity/src/uiTest.ts +++ b/test/sanity/src/uiTest.ts @@ -52,7 +52,7 @@ export class UITest { /** * Validate the results of the UI test actions. */ - public async validate() { + public validate() { this.verifyTextFileCreated(); this.verifyExtensionInstalled(); } @@ -66,18 +66,27 @@ export class UITest { await page.waitForTimeout(500); } + /** + * Run a command from the command palette. + */ + private async runCommand(page: Page, command: string) { + this.context.log(`Running command: ${command}`); + await page.keyboard.press('F1'); + await page.getByPlaceholder(/^Type the name of a command/).fill(`>${command}`); + await page.locator('span.monaco-highlighted-label', { hasText: new RegExp(`^${command}$`) }).click(); + } + /** * Create a new text file in the editor with some content and save it. */ private async createTextFile(page: Page) { - this.context.log('Focusing Explorer view'); - await page.keyboard.press('Control+Shift+E'); + await this.runCommand(page, 'View: Show Explorer'); this.context.log('Clicking New File button'); await page.getByLabel('New File...').click(); this.context.log('Typing file name'); - await page.locator('input').fill('helloWorld.txt'); + await page.getByRole('textbox', { name: /^Type file name/ }).fill('helloWorld.txt'); await page.keyboard.press('Enter'); this.context.log('Focusing the code editor'); @@ -86,8 +95,7 @@ export class UITest { this.context.log('Typing some content into the file'); await page.keyboard.type('Hello, World!'); - this.context.log('Saving the file'); - await page.keyboard.press('Control+S'); + await this.runCommand(page, 'File: Save'); await page.waitForTimeout(1000); } @@ -105,15 +113,14 @@ export class UITest { * Install GitHub Pull Requests extension from the Extensions view. */ private async installExtension(page: Page) { - this.context.log('Opening Extensions view'); - await page.keyboard.press('Control+Shift+X'); - await page.waitForSelector('.extension-list-item'); + await this.runCommand(page, 'View: Show Extensions'); this.context.log('Typing extension name to search for'); + await page.getByText('Search Extensions in Marketplace').focus(); await page.keyboard.type('GitHub Pull Requests'); - await page.waitForTimeout(2000); this.context.log('Clicking Install on the first extension in the list'); + await page.locator('.extension-list-item').getByText(/^GitHub Pull Requests$/).waitFor(); await page.locator('.extension-action:not(.disabled)', { hasText: /Install/ }).first().click(); this.context.log('Waiting for extension to be installed');