Skip to content

Commit

Permalink
feat: add support for Webdriver launcher to setViewportPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Dec 23, 2024
1 parent 17cfc0d commit 12731a8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/test-runner-commands/src/setViewportPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TestRunnerPlugin } from '@web/test-runner-core';
import type { ChromeLauncher } from '@web/test-runner-chrome';
import type { PlaywrightLauncher } from '@web/test-runner-playwright';
import type { WebdriverLauncher } from '@web/test-runner-webdriver';

export interface Viewport {
width: number;
Expand Down Expand Up @@ -50,6 +51,12 @@ export function setViewportPlugin(): TestRunnerPlugin {
return true;
}

if (session.browser.type === 'webdriver') {
const browser = session.browser as WebdriverLauncher;
await browser.setWindowSize(session.id, payload.width, payload.height);
return true;
}

throw new Error(
`Setting viewport is not supported for browser type ${session.browser.type}.`,
);
Expand Down
8 changes: 8 additions & 0 deletions packages/test-runner-webdriver/src/IFrameManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TestRunnerCoreConfig } from '@web/test-runner-core';
import { Browser, Element } from 'webdriverio';
import { validateBrowserResult } from './coverage.js';
import { setWindowSize } from 'webdriverio/build/commands/browser.js';

/**
* Manages tests to be executed in iframes on a page.
Expand Down Expand Up @@ -155,6 +156,13 @@ export class IFrameManager {
return this.driver.keys(keys);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setWindowSize(_: string, _width: number, _height: number) {
throw new Error(
'Unsupported operation. In order to set window size in Webdriver, set "concurrency" to 1.',
);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async performActions(_: string, _actions: object[]) {
throw new Error(
Expand Down
4 changes: 4 additions & 0 deletions packages/test-runner-webdriver/src/SessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export class SessionManager {
return { testCoverage: this.config.coverage ? testCoverage : undefined };
}

async setWindowSize(_: string, width: number, height: number) {
return this.driver.setWindowSize(width, height);
}

async performActions(_: string, actions: object[]) {
return this.driver.performActions(actions);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/test-runner-webdriver/src/webdriverLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ export class WebdriverLauncher implements BrowserLauncher {
return this.driverManager.sendKeys(sessionId, keys);
}

setWindowSize(sessionId: string, width: number, height: number) {
if (!this.driverManager) {
throw new Error('Not initialized');
}
return this.driverManager.setWindowSize(sessionId, width, height);
}

takeScreenshot(sessionId: string, locator: string) {
if (!this.driverManager) {
throw new Error('Not initialized');
Expand Down

0 comments on commit 12731a8

Please sign in to comment.