-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { browser } from "@wdio/globals"; | ||
import type { Workbench } from "wdio-vscode-service"; | ||
|
||
import { TestingViewControl } from "./testing/view-control"; | ||
import { TestingSideBar } from "./testing/side-bar"; | ||
|
||
export class VSCodePO { | ||
private _workbench: Workbench; | ||
|
||
static async create<T extends VSCodePO>(this: new (workbench: Workbench) => T): Promise<T> { | ||
const workbench = await browser.getWorkbench(); | ||
|
||
return new this(workbench); | ||
} | ||
|
||
constructor(workbench: Workbench) { | ||
this._workbench = workbench; | ||
} | ||
|
||
getTestingViewControl(): TestingViewControl { | ||
return new TestingViewControl(this._workbench); | ||
} | ||
|
||
getTestingSideBar(): TestingSideBar { | ||
return new TestingSideBar(this._workbench); | ||
} | ||
} | ||
|
||
export * from "./testing"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./side-bar"; | ||
export * from "./tree-item"; | ||
export * from "./view-control"; | ||
export * from "./view-section"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { browser } from "@wdio/globals"; | ||
import type { Workbench, SideBarView, ViewContent } from "wdio-vscode-service"; | ||
|
||
import { TestingViewSection } from "./view-section"; | ||
|
||
export class TestingSideBar { | ||
private _workbench: Workbench; | ||
private _sidebar: SideBarView<unknown>; | ||
private _sidebarView: ViewContent; | ||
|
||
constructor(workbench: Workbench) { | ||
this._workbench = workbench; | ||
this._sidebar = this._workbench.getSideBar(); | ||
this._sidebarView = this._sidebar.getContent(); | ||
} | ||
|
||
async getSections(): Promise<TestingViewSection[]> { | ||
const sections = await this._sidebarView.getSections(); | ||
|
||
return sections.map(section => new TestingViewSection(section)); | ||
} | ||
|
||
async waitTestsRead(): Promise<void> { | ||
await browser.waitUntil(async () => { | ||
const sections = await this._sidebarView.getSections(); | ||
const firstTreeItemText = await sections[0].elem.$(".label").getText(); | ||
|
||
return firstTreeItemText !== "Reading Testplane Tests..."; | ||
}); | ||
} | ||
|
||
async runAllTests(): Promise<void> { | ||
const runTestsBtn = await this._sidebarView.elem.$("aria/Run Tests"); | ||
await runTestsBtn.click(); | ||
} | ||
|
||
async waitTestsRunComplete(timeout: number = 30000): Promise<void> { | ||
await browser.waitUntil( | ||
async () => { | ||
const loadingItem = await this._sidebarView.elem.$(".result-summary .codicon-loading"); | ||
const isExisting = await loadingItem.isExisting(); | ||
|
||
return !isExisting; | ||
}, | ||
{ timeout }, | ||
); | ||
} | ||
|
||
async getTestsRunStats(): Promise<string> { | ||
return (await this._sidebarView.elem.$(".result-summary > [custom-hover]")).getText(); | ||
} | ||
|
||
async collapseAllTests(): Promise<void> { | ||
// Views and More Actions... | ||
|
||
const moreActionBtn = await this._sidebarView.elem.$("aria/Views and More Actions..."); | ||
console.log("moreActionBtn:", moreActionBtn); | ||
await moreActionBtn.click(); | ||
|
||
await browser.pause(1000); | ||
|
||
// await browser.performActions([{ | ||
// // type: "key", | ||
// // id: "keyboard", | ||
// type: "pointer", | ||
// id: "finger", | ||
// actions: [ | ||
// { type: "keyDown", value: Key.ArrowDown }, | ||
// { type: "keyUp", value: Key.ArrowDown }, | ||
// { type: "keyDown", value: Key.ArrowDown }, | ||
// { type: "keyUp", value: Key.ArrowDown }, | ||
// { | ||
// "parameters": {"pointerType": "touch"}, | ||
// "actions": [ | ||
// {"type": "pointerMove", "duration": 0, "x": 100, "y": 100}, | ||
// {"type": "pointerDown", "button": 0}, | ||
// {"type": "pause", "duration": 500}, | ||
// {"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": 50, "y": 0}, | ||
// {"type": "pointerUp", "button": 0} | ||
// ] | ||
// } | ||
// ], | ||
// }]); | ||
// await browser.performActions([{ | ||
// type: "key", | ||
// id: "keyboard", | ||
// actions: [{ type: "keyUp", value: Key.ArrowDown }], | ||
// }]); | ||
|
||
await browser.pause(10000); | ||
|
||
// const collapseBtn = await this._sidebarView.elem.$('aria/Collapse All Tests'); | ||
// console.log('collapseBtn;', collapseBtn); | ||
// await collapseBtn.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { browser } from "@wdio/globals"; | ||
import { Key } from "webdriverio"; | ||
import _ from "lodash"; | ||
import type { TreeItem, ViewItemAction } from "wdio-vscode-service"; | ||
|
||
export class TestingTreeItem { | ||
private _treeItem: TreeItem; | ||
|
||
constructor(treeItem: TreeItem) { | ||
this._treeItem = treeItem; | ||
} | ||
|
||
async expandAll(): Promise<void> { | ||
await browser.performActions([ | ||
{ | ||
type: "key", | ||
id: "keyboard", | ||
actions: [{ type: "keyDown", value: Key.Alt }], | ||
}, | ||
]); | ||
await this._treeItem.elem.click(); | ||
await browser.performActions([ | ||
{ | ||
type: "key", | ||
id: "keyboard", | ||
actions: [{ type: "keyUp", value: Key.Alt }], | ||
}, | ||
]); | ||
} | ||
|
||
async getLabel(): Promise<string> { | ||
return this._treeItem.elem.$(".label").getText(); | ||
} | ||
|
||
async getTestsFullTitle(): Promise<string[]> { | ||
return getFullTitles([this._treeItem]); | ||
} | ||
|
||
async getAriaLabelAttr(): Promise<string> { | ||
return (await this._treeItem.elem).getAttribute("aria-label"); | ||
} | ||
|
||
async getActionButton(label: string): Promise<ViewItemAction | undefined> { | ||
return this._treeItem.getActionButton(label); | ||
} | ||
} | ||
|
||
async function getFullTitles(treeItems: TreeItem[]): Promise<string[]> { | ||
return _.flatten( | ||
await Promise.all( | ||
treeItems.map(async (treeItem: TreeItem): Promise<string | string[]> => { | ||
const treeItemLabel = await treeItem.elem.$(".label").getText(); | ||
|
||
if (await treeItem.hasChildren()) { | ||
const labels = await getFullTitles(await treeItem.getChildren()); | ||
return labels.map(label => `${treeItemLabel} ${label}`); | ||
} | ||
|
||
return treeItemLabel; | ||
}), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { browser, expect } from "@wdio/globals"; | ||
import type { Workbench, ViewControl } from "wdio-vscode-service"; | ||
|
||
const VIEW_CONTROL_NAME = "Testing"; | ||
|
||
export class TestingViewControl { | ||
private _workbench: Workbench; | ||
|
||
constructor(workbench: Workbench) { | ||
this._workbench = workbench; | ||
} | ||
|
||
async open(): Promise<void> { | ||
const activityBar = this._workbench.getActivityBar(); | ||
const testingViewControl = (await browser.waitUntil(() => | ||
activityBar.getViewControl(VIEW_CONTROL_NAME), | ||
)) as ViewControl; | ||
|
||
await testingViewControl.openView(); | ||
|
||
const selectedView = await this._workbench.getActivityBar().getSelectedViewAction(); | ||
expect(await selectedView.getTitle()).toBe(VIEW_CONTROL_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { ViewSection, CustomTreeItem } from "wdio-vscode-service"; | ||
import { TestingTreeItem } from "../"; | ||
|
||
export class TestingViewSection { | ||
private _section: ViewSection; | ||
|
||
constructor(section: ViewSection) { | ||
this._section = section; | ||
} | ||
|
||
async getLabel(): Promise<string> { | ||
return this._section.elem.$(".label").getText(); | ||
} | ||
|
||
async getVisibleItems(): Promise<TestingTreeItem[]> { | ||
const items = (await this._section.getVisibleItems()) as CustomTreeItem[]; | ||
|
||
return items.map(item => new TestingTreeItem(item)); | ||
} | ||
|
||
async getVisibleItemByLabel(label: string): Promise<TestingTreeItem | null> { | ||
const items = await this.getVisibleItems(); | ||
const itemsLabel = await Promise.all( | ||
items.map(async item => { | ||
const itemLabel = await item.getLabel(); | ||
|
||
return itemLabel === label ? item : null; | ||
}), | ||
).then(res => res.filter(Boolean)); | ||
|
||
return itemsLabel[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from "@wdio/globals"; | ||
import { VSCodePO } from "../page-objects"; | ||
|
||
describe("Testing view in sidebar", () => { | ||
describe("before read tests", () => { | ||
it("should render loader item in tree", async () => { | ||
const vscodePO = await VSCodePO.create(); | ||
const testingViewControl = vscodePO.getTestingViewControl(); | ||
await testingViewControl.open(); | ||
|
||
const sidebar = vscodePO.getTestingSideBar(); | ||
const [firstSection] = await sidebar.getSections(); | ||
const firstItemLabel = await firstSection.getLabel(); | ||
|
||
expect(firstItemLabel).toBe("Reading Testplane Tests..."); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from "@wdio/globals"; | ||
import { VSCodePO } from "../page-objects"; | ||
|
||
describe("Testing view in sidebar", () => { | ||
describe("after read tests", () => { | ||
it("should replace loader item on main folder item in tree", async () => { | ||
const vscodePO = await VSCodePO.create(); | ||
const testingViewControl = vscodePO.getTestingViewControl(); | ||
await testingViewControl.open(); | ||
|
||
const sidebar = vscodePO.getTestingSideBar(); | ||
await sidebar.waitTestsRead(); | ||
|
||
const [firstSection] = await sidebar.getSections(); | ||
const firstItemLabel = await firstSection.getLabel(); | ||
|
||
expect(firstItemLabel).toBe("tests"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect } from "@wdio/globals"; | ||
import { VSCodePO } from "../page-objects"; | ||
|
||
describe("Testing view in sidebar", () => { | ||
describe("after read tests", () => { | ||
it("should correctly render tests tree", async () => { | ||
const vscodePO = await VSCodePO.create(); | ||
const testingViewControl = vscodePO.getTestingViewControl(); | ||
await testingViewControl.open(); | ||
|
||
const sidebar = vscodePO.getTestingSideBar(); | ||
await sidebar.waitTestsRead(); | ||
|
||
const [firstSection] = await sidebar.getSections(); | ||
const [mainTreeItem] = await firstSection.getVisibleItems(); | ||
|
||
await mainTreeItem.expandAll(); | ||
const testsFullTitle = await mainTreeItem.getTestsFullTitle(); | ||
|
||
expect(testsFullTitle).toEqual([ | ||
"tests test.testplane.ts suite success chrome", | ||
"tests test.testplane.ts suite fail chrome", | ||
"tests test.testplane.ts suite skipped chrome", | ||
"tests test.testplane.ts test without suite chrome", | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect } from "@wdio/globals"; | ||
import { VSCodePO } from "../page-objects"; | ||
|
||
describe("Testing view in sidebar", () => { | ||
describe("run tests", () => { | ||
it("should correctly show test statistics after run all tests", async () => { | ||
const vscodePO = await VSCodePO.create(); | ||
const testingViewControl = vscodePO.getTestingViewControl(); | ||
await testingViewControl.open(); | ||
|
||
const sidebar = vscodePO.getTestingSideBar(); | ||
await sidebar.waitTestsRead(); | ||
await sidebar.runAllTests(); | ||
await sidebar.waitTestsRunComplete(); | ||
|
||
await expect(await sidebar.getTestsRunStats()).toBe("2/3"); | ||
|
||
const [firstSection] = await sidebar.getSections(); | ||
const [mainTreeItem] = await firstSection.getVisibleItems(); | ||
await mainTreeItem.expandAll(); | ||
|
||
const items = await firstSection.getVisibleItems(); | ||
|
||
await expect(items).toHaveLength(11); | ||
await expect(await items[0].getAriaLabelAttr()).toContain("tests (Failed)"); | ||
await expect(await items[1].getAriaLabelAttr()).toContain("test.testplane.ts (Failed)"); | ||
await expect(await items[2].getAriaLabelAttr()).toContain("suite (Failed)"); | ||
await expect(await items[3].getAriaLabelAttr()).toContain("success (Passed)"); | ||
await expect(await items[4].getAriaLabelAttr()).toContain("chrome (Passed)"); | ||
await expect(await items[5].getAriaLabelAttr()).toContain("fail (Failed)"); | ||
await expect(await items[6].getAriaLabelAttr()).toContain("chrome (Failed)"); | ||
await expect(await items[7].getAriaLabelAttr()).toContain("skipped (Skipped)"); | ||
await expect(await items[8].getAriaLabelAttr()).toContain("chrome (Skipped)"); | ||
await expect(await items[9].getAriaLabelAttr()).toContain("test without suite (Passed)"); | ||
await expect(await items[10].getAriaLabelAttr()).toContain("chrome (Passed)"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect } from "@wdio/globals"; | ||
import { VSCodePO } from "../page-objects"; | ||
|
||
describe("Testing view in sidebar", () => { | ||
describe("run tests", () => { | ||
it("should run only child tests by click on suite item", async () => { | ||
const vscodePO = await VSCodePO.create(); | ||
const testingViewControl = vscodePO.getTestingViewControl(); | ||
await testingViewControl.open(); | ||
|
||
const sidebar = vscodePO.getTestingSideBar(); | ||
await sidebar.waitTestsRead(); | ||
|
||
const [firstSection] = await sidebar.getSections(); | ||
const [mainTreeItem] = await firstSection.getVisibleItems(); | ||
|
||
await mainTreeItem.expandAll(); | ||
const suiteTreeItem = await firstSection.getVisibleItemByLabel("suite"); | ||
|
||
const runTestButton = await suiteTreeItem!.getActionButton("Run Test"); | ||
await runTestButton?.elem.click(); | ||
await sidebar.waitTestsRunComplete(); | ||
|
||
await expect(await sidebar.getTestsRunStats()).toBe("1/2"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.