Skip to content
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
1 change: 1 addition & 0 deletions src/browser/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const customCommandFileNames = [
"switchToRepl",
"moveCursorTo",
"captureDomSnapshot",
"setWindowSize",
];
20 changes: 20 additions & 0 deletions src/browser/commands/setWindowSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Browser } from "../browser";

const setWindowSizeCommand = (browser: Browser): void => {
const { publicAPI: session } = browser;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
session.overwriteCommand("setWindowSize", async (origSetWindowSize: any, width: number, height: number) => {
browser.applyState({
currentWindowSize: {
width,
height,
},
});

const result = await origSetWindowSize(width, height);
return result;
});
};

export default setWindowSizeCommand;
9 changes: 9 additions & 0 deletions src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ module.exports = class TestRunner {
this._browser.state.isLastTestFailed = true;
}

const currentWindowSize = this._browser.state?.currentWindowSize;
const configSetWindowSize = this._browser.config.windowSize;

if (currentWindowSize) {
if (!_.isEqual(currentWindowSize, configSetWindowSize)) {
this._browser.publicAPI.setWindowSize(configSetWindowSize);
}
}

this._browserAgent.freeBrowser(this._browser);

if (error) {
Expand Down
46 changes: 46 additions & 0 deletions test/src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe("worker/runner/test-runner", () => {
moveToElement: sandbox.stub().named("moveToElement").resolves(),
action: sandbox.stub().named("getSize").returns(mkActionAPI_()),
isW3C: true,
setWindowSize: sandbox.stub().named("setWindowSize").resolves({ x: 0, y: 0, width: 1024, height: 768 }),
});
config = _.defaults(config, { resetCursor: true });

Expand Down Expand Up @@ -915,6 +916,51 @@ describe("worker/runner/test-runner", () => {
assert.isUndefined(err.history);
});
});

describe("setWindowSize override", () => {
it("should automatically reset currentSetWindowSize flag when creating browser", async () => {
const browser = mkBrowser_({ config: { windowSize: { width: 10, height: 10 } } });
browser.state.currentWindowSize = { width: 20, height: 20 };

BrowserAgent.prototype.getBrowser.resolves(browser);

await run_();

assert.calledWith(browser.publicAPI.setWindowSize, { width: 10, height: 10 });
});

it("should not reset currentSetWindowSize flag when creating browser with same value as in config", async () => {
const browser = mkBrowser_({ config: { windowSize: { width: 10, height: 10 } } });
browser.state.currentWindowSize = { width: 10, height: 10 };

BrowserAgent.prototype.getBrowser.resolves(browser);

await run_();

assert.notCalled(browser.publicAPI.setWindowSize);
});

it("should automatically reset currentSetWindowSize flag when creating browser without config", async () => {
const browser = mkBrowser_();
browser.state.currentWindowSize = { width: 20, height: 20 };

BrowserAgent.prototype.getBrowser.resolves(browser);

await run_();

assert.calledWith(browser.publicAPI.setWindowSize, undefined);
});

it("should not set currentSetWindowSize when setWindowSize not called", async () => {
const browser = mkBrowser_({ config: { windowSize: { width: 10, height: 10 } } });

BrowserAgent.prototype.getBrowser.resolves(browser);

await run_();

assert.notCalled(browser.publicAPI.setWindowSize);
});
});
});
});

Expand Down