diff --git a/src/test/e2e/globalSetup.ts b/src/test/e2e/globalSetup.ts index 40a3e49..b6d29fd 100644 --- a/src/test/e2e/globalSetup.ts +++ b/src/test/e2e/globalSetup.ts @@ -1,8 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } from '@vscode/test-electron'; +import { execSync } from 'child_process'; export default async () => { const vscodePath = await downloadAndUnzipVSCode('insiders'); - resolveCliArgsFromVSCodeExecutablePath(vscodePath); + const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodePath); + execSync(`${cli} ${args.join(' ')} --install-extension humao.rest-client`, { + encoding: 'utf-8', + }); + }; diff --git a/src/test/e2e/tests/validateGenerateHTTPFile.test.ts b/src/test/e2e/tests/validateGenerateHTTPFile.test.ts new file mode 100644 index 0000000..eb464f9 --- /dev/null +++ b/src/test/e2e/tests/validateGenerateHTTPFile.test.ts @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { expect, test } from '../baseTest'; +import { RestClient, Timeout, VSCode } from '../utils/constants'; +import VscodeOperator from '../utils/vscodeOperator'; + +test('validate Generate HTTP File', { tag: ["@26611996"] }, async ({ workbox }) => { + //set test timeout + test.setTimeout(160000); + await workbox.waitForTimeout(Timeout.PREPARE_TEST); + // wait API Center extension installed on VS Code. + expect(await VscodeOperator.isSideTabItemExist(workbox, "API Center")).toBeTruthy(); + await VscodeOperator.activeSideTab(workbox, VSCode.TAB_API_CENTER, Timeout.PREPARE_EXT); + //expand and validate + await VscodeOperator.clickTreeItemChildLinkByText(workbox, "Teams Cloud - E2E Testing with TTL = 1 Days", "Teams Cloud - E2E Testing with TTL = 1 Days"); + expect(await VscodeOperator.isTreeItemExist(workbox, "apicentertest001")).toBeTruthy(); + await VscodeOperator.clickTreeItem(workbox, "apicentertest001"); + expect(await VscodeOperator.isTreeItemExist(workbox, "APIs")).toBeTruthy(); + await VscodeOperator.clickTreeItemChildLinkByText(workbox, "APIs", "APIs"); + expect(await VscodeOperator.isTreeItemExist(workbox, "callback-example")).toBeTruthy(); + await VscodeOperator.clickTreeItem(workbox, "callback-example"); + expect(await VscodeOperator.isTreeItemExist(workbox, "Versions")).toBeTruthy(); + await VscodeOperator.clickTreeItem(workbox, "Versions"); + expect(await VscodeOperator.isTreeItemExist(workbox, "1-0-0")).toBeTruthy(); + await VscodeOperator.clickTreeItem(workbox, "1-0-0"); + expect(await VscodeOperator.isTreeItemExist(workbox, "Definitions")).toBeTruthy(); + await VscodeOperator.clickTreeItem(workbox, "Definitions"); + expect(await VscodeOperator.isTreeItemExist(workbox, "openapi")).toBeTruthy(); + //right click on openai + await VscodeOperator.rightClickTreeItem(workbox, "openapi"); + expect(await VscodeOperator.isMenuItemExist(workbox, "Generate HTTP File")).toBeTruthy(); + await VscodeOperator.clickMenuItem(workbox, "Generate HTTP File"); + await workbox.waitForTimeout(Timeout.LONG_WAIT); + //validate the http file is opened + expect(await VscodeOperator.isSideTabItemExist(workbox, "1-0-0-tempFile.http")).toBeTruthy(); + // trigger command palette. + await VscodeOperator.execCommandInCommandPalette(workbox, RestClient.SEND_REQUEST); + await workbox.waitForTimeout(Timeout.PREPARE_EXT); + // check http result + const requestFrame = await VscodeOperator.getHttpRequestFrame(workbox); + expect(requestFrame.locator('span.hljs-number')).toContainText('200'); + console.log("[finsish] validate Generate HTTP File test"); +}); diff --git a/src/test/e2e/utils/constants.ts b/src/test/e2e/utils/constants.ts index 51f3714..c8aacd6 100644 --- a/src/test/e2e/utils/constants.ts +++ b/src/test/e2e/utils/constants.ts @@ -9,6 +9,7 @@ export class Timeout { public static readonly PREPARE_TEST = 5000; public static readonly PREPARE_EXT = 10000; public static readonly SHORT_WAIT = 5000; + public static readonly LONG_WAIT = 20000; } export class VSCode { @@ -31,6 +32,8 @@ export class VSCode { public static readonly ENTER = "Enter"; //toolbar public static readonly Toolbar = "toolbar"; + // menu item + public static readonly MENU_ITEM = "menuitem"; } export class APICenter { @@ -52,3 +55,8 @@ export class TestENV { public static readonly AZURE_SUBSCRIPTION_NAME = process.env["AZURE_SUBSCRIPTION_NAME"] || "Teams Cloud - E2E Testing with TTL = 1 Days"; public static readonly AZURE_TENANT_ID_2 = process.env["AZURE_TENANT_ID"] || "af46c703-f714-4f4c-af42-835a673c2b13"; } + +export class RestClient { + // commands + public static readonly SEND_REQUEST = ">Rest Client: Send Request"; +} diff --git a/src/test/e2e/utils/vscodeOperator.ts b/src/test/e2e/utils/vscodeOperator.ts index e6c3715..27c0a23 100644 --- a/src/test/e2e/utils/vscodeOperator.ts +++ b/src/test/e2e/utils/vscodeOperator.ts @@ -76,4 +76,27 @@ export default class VscodeOperator { await page.getByRole(VSCode.CMD_PALETTE_LIST, { name: listItemName }).locator(VSCode.LINK).filter({ hasText: linkName }).click(); await page.waitForTimeout(Timeout.CLICK_WAIT); } + + + static async rightClickTreeItem(page: Page, treeItemName: string) { + await page.getByRole(VSCode.TREE_ITEM, { name: treeItemName }).locator(VSCode.LINK).click({ + button: 'right' + }); + await page.waitForTimeout(Timeout.CLICK_WAIT); + } + + static async isMenuItemExist(page: Page, menuItemName: string) { + return await page.getByRole(VSCode.MENU_ITEM, { name: menuItemName }).isVisible(); + } + + static async clickMenuItem(page: Page, menuItemName: string) { + await page.getByRole(VSCode.MENU_ITEM, { name: menuItemName }).locator("span.action-label").click(); + await page.waitForTimeout(Timeout.PREPARE_EXT); + } + + static async getHttpRequestFrame(page: Page) { + const webviewFrame = page.frameLocator(`.webview`); + return webviewFrame.frameLocator(`iframe[id="active-frame"]`); + } + }