Skip to content

Commit

Permalink
fix: Add workaround for setting the window position (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Aug 9, 2024
1 parent 4e09c1e commit 6720df5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,33 @@ commands.getWindowSize = async function getWindowSize () {
// a workaround for https://github.com/appium/appium/issues/15923
commands.getWindowRect = async function getWindowRect () {
const {width, height} = await this.getWindowSize();
return {x: 0, y: 0, width, height};
let [x, y] = [0, 0];
try {
const handle = await this.winAppDriver.sendCommand('/window_handle', 'GET');
({x, y} = await this.winAppDriver.sendCommand(`/window/${handle}/position`, 'GET'));
} catch (e) {
this.log.warn(
`Cannot fetch the window position. Defaulting to zeroes. Original error: ${e.message}`
);
}
return {x, y, width, height};
};

// a workaround for https://github.com/appium/appium/issues/15923
commands.setWindowRect = async function setWindowRect (x, y, width, height) {
await this.winAppDriver.sendCommand('/window/size', 'POST', {width, height});
let didProcess = false;
if (!_.isNil(width) && !_.isNil(height)) {
await this.winAppDriver.sendCommand('/window/size', 'POST', {width, height});
didProcess = true;
}
if (!_.isNil(x) && !_.isNil(y)) {
const handle = await this.winAppDriver.sendCommand('/window_handle', 'GET');
await this.winAppDriver.sendCommand(`/window/${handle}/position`, 'POST', {x, y});
didProcess = true;
}
if (!didProcess) {
this.log.info('Either x and y or width and height must be defined. Doing nothing');
}
};

commands.getScreenshot = async function getScreenshot () {
Expand Down

0 comments on commit 6720df5

Please sign in to comment.