Skip to content

Commit

Permalink
e2e-test: remove iwindowdriver dep (#5880)
Browse files Browse the repository at this point in the history
### Summary
* removed IWindowDriver dependency
* cleaned up PlaywrightDriver
   * removed some unnecessary wrapper functions
   * replaced deprecated `frameLocator()` with `frameContent()` 

### QA Notes

Ran [full
suite](https://github.com/posit-dev/positron/actions/runs/12633393653)
and everything checks out.
  • Loading branch information
midleman authored Jan 6, 2025
1 parent 66aa3fb commit 925e428
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 41 deletions.
74 changes: 46 additions & 28 deletions test/automation/src/playwrightDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import * as playwright from '@playwright/test';
import type { Protocol } from 'playwright-core/types/protocol';
import { dirname, join } from 'path';
import { promises } from 'fs';
import { IWindowDriver } from './driver';
// --- Start Positron ---
// removed IWindowDriver import
// --- End Positron ---
import { PageFunction } from 'playwright-core/types/structs';
import { measureAndLog } from './logger';
import { LaunchOptions } from './code';
Expand All @@ -19,7 +21,6 @@ export class PlaywrightDriver {
private static traceCounter = 1;
private static screenShotCounter = 1;


// --- Start Positron ---
// Removed declaration
// --- End Positron ---
Expand Down Expand Up @@ -247,31 +248,6 @@ export class PlaywrightDriver {
}

// --- Start Positron ---
async typeKeys(locator: string, text: string): Promise<void> {
return this.page.locator(locator).pressSequentially(text);
}

getLocator(selector: string): playwright.Locator {
return this.page.locator(selector);
}

getKeyboard() {
return this.page.keyboard;
}

getFrame(frameSelector: string): playwright.FrameLocator {
return this.page.frameLocator(frameSelector);
}

/**
* Set the size of the browser window for more predicable test results.
* @param opts.width Width in pixels
* @param opts.height Height in pixels
*/
async setViewportSize(opts: { width: number; height: number }) {
await this.page.setViewportSize(opts);
}

/**
* Click and drag from one point to another.
* @param opts.from The starting point of the drag as x-y coordinates
Expand All @@ -288,6 +264,48 @@ export class PlaywrightDriver {
await this.page.mouse.move(to.x, to.y);
await this.page.mouse.up();
}

// --- End Positron ---
}

// --- Start Positron ---
export interface IWindowDriver {
setValue(selector: string, text: string): Promise<void>;
isActiveElement(selector: string): Promise<boolean>;
getElements(selector: string, recursive: boolean): Promise<IElement[]>;
getElementXY(selector: string, xoffset?: number, yoffset?: number): Promise<{ x: number; y: number }>;
typeInEditor(selector: string, text: string): Promise<void>;
getTerminalBuffer(selector: string): Promise<string[]>;
writeInTerminal(selector: string, text: string): Promise<void>;
getLocaleInfo(): Promise<ILocaleInfo>;
getLocalizedStrings(): Promise<ILocalizedStrings>;
getLogs(): Promise<ILogFile[]>;
whenWorkbenchRestored(): Promise<void>;
exitApplication(): Promise<void>;
}

export interface IElement {
readonly tagName: string;
readonly className: string;
readonly textContent: string;
readonly attributes: { [name: string]: string };
readonly children: IElement[];
readonly top: number;
readonly left: number;
}

export interface ILocaleInfo {
readonly language: string;
readonly locale?: string;
}

export interface ILocalizedStrings {
readonly open: string;
readonly close: string;
readonly find: string;
}

export interface ILogFile {
readonly relativePath: string;
readonly contents: string;
}
// --- End Positron ---
6 changes: 3 additions & 3 deletions test/automation/src/positron/positronEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class PositronEditor {
constructor(private code: Code) { }

async pressPlay(): Promise<void> {
await this.code.driver.getLocator(PLAY_BUTTON).click();
await this.code.driver.page.locator(PLAY_BUTTON).click();

// await appearance and disappearance of the toast
await expect(this.code.driver.page.locator('.notifications-toasts')).toBeVisible({ timeout: 30000 });
Expand All @@ -40,7 +40,7 @@ export class PositronEditor {
const editor = EDITOR(filename);
const line = `${editor} .view-lines > .view-line:nth-child(${lineNumber})`;

const lineLocator = this.code.driver.getLocator(line);
const lineLocator = this.code.driver.page.locator(line);

await lineLocator.press(press);
}
Expand All @@ -57,7 +57,7 @@ export class PositronEditor {
let retries = 20;
let topValue: number = NaN;

const currentLine = this.code.driver.getLocator(CURRENT_LINE);
const currentLine = this.code.driver.page.locator(CURRENT_LINE);
// Note that '..' is used to get the parent of the current-line div
const currentLineParent = currentLine.locator('..');

Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/positron/positronHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PositronHelp {
constructor(private code: Code) { }

async getHelpFrame(nth: number): Promise<FrameLocator> {
const outerFrame = this.code.driver.getFrame(OUTER_FRAME).nth(nth);
const outerFrame = this.code.driver.page.locator(OUTER_FRAME).nth(nth).contentFrame();
const innerFrame = outerFrame.frameLocator(MIDDLE_FRAME);
const innerInnerFrame = innerFrame.frameLocator(INNER_FRAME);
return innerInnerFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class PositronInterpreterDropdown {
*/
async closeInterpreterDropdown() {
if (await this.interpreterGroups.isVisible()) {
await this.code.driver.getKeyboard().press('Escape');
await this.code.driver.page.keyboard.press('Escape');
await this.interpreterGroups.waitFor({ state: 'detached', timeout: 10_000 });
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/positron/positronNewProjectWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ProjectWizardPythonConfigurationStep {
// There should be one dropdown item with the interpreterPath.
if ((await dropdownItem.count()) !== 1) {
// Close the interpreter dropdown.
await this.code.driver.getKeyboard().press('Escape');
await this.code.driver.page.keyboard.press('Escape');

// Fail the test.
fail(`Could not find interpreter path ("${interpreterPath}") in ("${subtitles}") project wizard dropdown`);
Expand Down
11 changes: 9 additions & 2 deletions test/automation/src/positron/positronPlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ export class PositronPlots {
}

getWebviewPlotLocator(selector: string): Locator {
return this.code.driver.getFrame(OUTER_WEBVIEW_FRAME).last().frameLocator(INNER_WEBVIEW_FRAME).last().locator(selector);
return this.code.driver.page
.locator(OUTER_WEBVIEW_FRAME).last().contentFrame()
.locator(INNER_WEBVIEW_FRAME).last().contentFrame()
.locator(selector);
}

getRWebWebviewPlotLocator(selector: string): Locator {
return this.code.driver.getFrame(OUTER_WEBVIEW_FRAME).last().frameLocator(INNER_WEBVIEW_FRAME).last().frameLocator('//iframe').last().locator(selector);
return this.code.driver.page
.locator(OUTER_WEBVIEW_FRAME).last().contentFrame()
.locator(INNER_WEBVIEW_FRAME).last().contentFrame()
.locator('//iframe').last().contentFrame()
.locator(selector);
}

async waitForWebviewPlot(selector: string, state: 'attached' | 'visible' = 'visible', RWeb = false) {
Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/positron/positronTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class PositronTerminal {
}

async sendKeysToTerminal(key: string) {
await this.code.driver.getKeyboard().press(key);
await this.code.driver.page.keyboard.press(key);
}

async clickTerminalTab() {
Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/positron/positronVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class PositronVariables {
const isMac = os.platform() === 'darwin';
const modifier = isMac ? 'Meta' : 'Control';

await this.code.driver.getKeyboard().press(`${modifier}+Alt+B`);
await this.code.driver.page.keyboard.press(`${modifier}+Alt+B`);
}

async toggleVariable({ variableName, action }: { variableName: string; action: 'expand' | 'collapse' }) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/areas/editor/fast-execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test.describe('R Fast Execution', { tag: [tags.WEB, tags.EDITOR, tags.WIN] }, ()

previousTop = currentTop;

await app.code.driver.getKeyboard().press('Control+Enter');
await app.code.driver.page.keyboard.press('Control+Enter');
}

await app.workbench.positronVariables.waitForVariableRow('c');
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/areas/layouts/layouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.describe('Layouts', { tag: [tags.WEB, tags.LAYOUTS, tags.WIN] }, () => {
test('Verify stacked layout puts stuff in appropriate places [C656294]', async function ({ app }) {
const layouts = app.workbench.positronLayouts;

await app.code.driver.setViewportSize({ width: 1400, height: 1000 });
await app.code.driver.page.setViewportSize({ width: 1400, height: 1000 });

// Enter layout with help pane docked in session panel
await layouts.enterLayout('stacked');
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/areas/plots/plots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test.describe('Plots', { tag: [tags.PLOTS, tags.EDITOR] }, () => {
test.beforeEach(async function ({ app, interpreter }) {
// Set the viewport to a size that ensures all the plots view actions are visible
if (process.platform === 'linux') {
await app.code.driver.setViewportSize({ width: 1280, height: 800 });
await app.code.driver.page.setViewportSize({ width: 1280, height: 800 });
}

await interpreter.set('Python');
Expand Down

0 comments on commit 925e428

Please sign in to comment.