Skip to content

Commit

Permalink
fix: Adjust Firefox height
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Dani committed Sep 2, 2024
1 parent 6a60336 commit a4f8872
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/browsers/browser-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import merge from 'lodash/merge';

import { BrowserError } from '../exceptions';
import { Capabilities } from './capabilities';
import { addFirefoxOffset } from './utils';

export interface WebDriverOptions {
width: number;
Expand Down Expand Up @@ -52,8 +53,14 @@ export default abstract class BrowserCreator {
await browser.setTimeout({ implicit: options.implicitTimeout, script: options.scriptTimeout });

if (!browser.isMobile) {
let adjustedSizeOptions = options;

await browser.$('body').then(body => body.moveTo({ xOffset: 0, yOffset: 0 }));
await browser.setWindowSize(options.width, options.height);

if (browser.isFirefox) {
adjustedSizeOptions = addFirefoxOffset(options);
}
await browser.setWindowSize(adjustedSizeOptions.width, adjustedSizeOptions.height);
}

return browser;
Expand Down
14 changes: 14 additions & 0 deletions src/browsers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { WebDriverOptions } from './browser-creator';

// added after release of Firefox 129 to mitigate viewport shrinking
export const FIREFOX_VIEWPORT_OFFSET = 134;

export const addFirefoxOffset = (options: WebDriverOptions): WebDriverOptions => {
const updatedHeight = options.height + FIREFOX_VIEWPORT_OFFSET;
return {
...options,
height: updatedHeight,
};
};
4 changes: 3 additions & 1 deletion src/page-objects/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import EventsSpy from './events-spy';
import * as liveAnnouncements from '../browser-scripts/live-announcements';
import { getElementCenter } from './utils';
import { FIREFOX_VIEWPORT_OFFSET } from '../browsers/utils';

import { ElementRect } from './types';
import { waitForTimerAndAnimationFrame } from './browser-scripts';
Expand All @@ -30,7 +31,8 @@ export default class BasePageObject {
}

async setWindowSize({ width, height }: { width: number; height: number }) {
await this.browser.setWindowSize(width, height);
const adjustedHeight = this.browser.isFirefox ? height + FIREFOX_VIEWPORT_OFFSET : height;
await this.browser.setWindowSize(width, adjustedHeight);
}

async spyOnEvents(selector: string, events: string[]) {
Expand Down

0 comments on commit a4f8872

Please sign in to comment.