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

test: add auto case Generate HTTP File #256

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/test/e2e/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -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',
});

};
44 changes: 44 additions & 0 deletions src/test/e2e/tests/validateGenerateHTTPFile.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
8 changes: 8 additions & 0 deletions src/test/e2e/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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";
}
23 changes: 23 additions & 0 deletions src/test/e2e/utils/vscodeOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]`);
}

}
Loading