Skip to content

Commit

Permalink
Contain side-effects from tests in C/I (#99)
Browse files Browse the repository at this point in the history
* Break out specs into seperate files

* Enable retries for flakes

* Imperative style seems more robust

* Use polling strategy

* Give Windows some extra time

* Something odd about Windows makes this fail
  • Loading branch information
sourishkrout authored Jan 17, 2024
1 parent 1b50504 commit fc9e263
Show file tree
Hide file tree
Showing 18 changed files with 736 additions and 700 deletions.
8 changes: 4 additions & 4 deletions src/pageobjects/bottomBar/BottomBarPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class BottomBarPanel extends BasePage<typeof BottomBarPanelLocators> {
*/
async openProblemsView (): Promise<ProblemsView> {
await this.openTab(this.locators.problemsTab)
return new ProblemsView(this.locatorMap, this).wait()
return new ProblemsView(this.locatorMap, this).poll()
}

/**
Expand All @@ -73,7 +73,7 @@ export class BottomBarPanel extends BasePage<typeof BottomBarPanelLocators> {
*/
async openOutputView (): Promise<OutputView> {
await this.openTab(this.locators.outputTab)
return new OutputView(this.locatorMap, this).wait()
return new OutputView(this.locatorMap, this).poll()
}

/**
Expand All @@ -82,7 +82,7 @@ export class BottomBarPanel extends BasePage<typeof BottomBarPanelLocators> {
*/
async openDebugConsoleView (): Promise<DebugConsoleView> {
await this.openTab(this.locators.debugTab)
return new DebugConsoleView(this.locatorMap, this).wait()
return new DebugConsoleView(this.locatorMap, this).poll()
}

/**
Expand All @@ -91,7 +91,7 @@ export class BottomBarPanel extends BasePage<typeof BottomBarPanelLocators> {
*/
async openTerminalView (): Promise<TerminalView> {
await this.openTab(this.locators.terminalTab)
return new TerminalView(this.locatorMap, this).wait()
return new TerminalView(this.locatorMap, this).poll()
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/pageobjects/editor/EditorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ export class EditorView extends BasePage<typeof EditorViewLocators> {
* @returns promise resolving to an array of EditorGroup objects
*/
async getEditorGroups (): Promise<EditorGroup[]> {
const elements = await this.editorGroup$$
const groups = await Promise.all(
elements.map(async (element) => (
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
new EditorGroup(this.locatorMap, element as any, this).wait()
))
)
const groups: EditorGroup[] = []
for await (const elements of this.editorGroup$$) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
groups.push(await (new EditorGroup(this.locatorMap, elements as any, this).poll()))
}

// sort the groups by x coordinates, so the leftmost is always at index 0
for (let i = 0; i < groups.length - 1; i += 1) {
Expand Down
11 changes: 11 additions & 0 deletions src/pageobjects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ export abstract class BasePage<PageLocators, LocatorMap extends Record<string, L
await this.elem.waitForDisplayed({ timeout })
return this
}

/**
* Poll for the element to become visible
* @param timeout custom timeout for the wait
* @param interval custom interval to control polling
* @returns thenable self reference
*/
async poll (timeout = 10000, interval = 2000): Promise<this> {
await this.elem.waitForDisplayed({ timeout, interval })
return this
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pageobjects/workbench/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class Workbench extends BasePage<typeof WorkbenchLocators> {
await this.executeCommand('Preferences: Open User Settings')
await new EditorView(this.locatorMap).openEditor('Settings')
await this.elem.$(this.locatorMap.Editor.elem as string).waitForExist()
await sleep(500)
await sleep(1500)
return new SettingsEditor(this.locatorMap)
}

Expand Down
50 changes: 50 additions & 0 deletions test/specs/activitybar.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../dist/service.d.ts" />

import { browser, expect } from '@wdio/globals'

describe('activity bar', () => {
it('should show all activity bar items', async () => {
const workbench = await browser.getWorkbench()
const viewControls = await workbench.getActivityBar().getViewControls()
expect(await Promise.all(viewControls.map((vc) => vc.getTitle()))).toEqual([
'Explorer',
'Search',
'Source Control',
'Run and Debug',
'Extensions'
])
})

it('can open extension view and check that first installed extension is our guinea pig', async () => {
const workbench = await browser.getWorkbench()
const extensionView = await workbench.getActivityBar().getViewControl('Extensions')
await extensionView?.openView()

const selectedView = await workbench.getActivityBar().getSelectedViewAction()
expect(await selectedView.getTitle()).toBe('Extensions')

const sidebar = workbench.getSideBar()
const sidebarView = sidebar.getContent()
await sidebarView.getSection('INSTALLED')

/**
* for some reason the developed extension doesn't show up
* in the installed extension section when running in a
* pristine environment
*/
// const installedExtensions = await extensionViewSection.getVisibleItems()
// expect(await installedExtensions[0].getTitle()).toBe('Guinea Pig')
})

it('should be able to get global options', async () => {
const workbench = await browser.getWorkbench()
const viewControls = await workbench.getActivityBar().getGlobalActions()
expect(await Promise.all(viewControls.map((vc) => vc.getTitle()))).toEqual([
'Accounts',
'Manage'
])
})
})
Loading

0 comments on commit fc9e263

Please sign in to comment.