Skip to content

Commit

Permalink
fix: correctly switch between iframes on disable animation
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Dec 26, 2023
1 parent 3990aed commit e21a0e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ module.exports = class ExistingBrowser extends Browser {
for (const iframe of iframes) {
await this._session.switchToFrame(iframe);
await cb();
}
} finally {
if (!_.isEmpty(iframes)) {
// switchToParentFrame does not work in ios - https://github.com/appium/appium/issues/14882
await this._session.switchToFrame(null);
}
} catch (e) {
await this._session.switchToFrame(null);
throw e;
}
}

Expand Down
37 changes: 25 additions & 12 deletions test/src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,33 @@ describe("ExistingBrowser", () => {
);
});

it("should disable animations if 'disableAnimation: true' and 'automationProtocol: webdriver'", async () => {
const clientBridge = stubClientBridge_();
const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" }));
const iframeElement = { "element-12345": "67890_element_1" };
browser.publicAPI.findElements.withArgs("css selector", "iframe").resolves([iframeElement]);
describe("'disableAnimation: true' and 'automationProtocol: webdriver'", () => {
it("should disable animations", async () => {
const clientBridge = stubClientBridge_();
const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" }));
const iframeElement1 = { "element-12345": "67890_element_1" };
const iframeElement2 = { "element-54321": "09876_element_2" };
browser.publicAPI.findElements
.withArgs("css selector", "iframe")
.resolves([iframeElement1, iframeElement2]);

await browser.prepareScreenshot(".selector", { disableAnimation: true });
await browser.prepareScreenshot(".selector", { disableAnimation: true });

assert.calledWith(clientBridge.call, "prepareScreenshot", [
".selector",
sinon.match({ disableAnimation: true }),
]);
assert.calledWith(browser.publicAPI.switchToFrame, iframeElement);
assert.calledWith(clientBridge.call, "disableFrameAnimations");
assert.callOrder(
clientBridge.call.withArgs("prepareScreenshot", [
".selector",
sinon.match({ disableAnimation: true }),
]),

browser.publicAPI.switchToFrame.withArgs(iframeElement1),
clientBridge.call.withArgs("disableFrameAnimations"),
browser.publicAPI.switchToFrame.withArgs(null),

browser.publicAPI.switchToFrame.withArgs(iframeElement2),
clientBridge.call.withArgs("disableFrameAnimations"),
browser.publicAPI.switchToFrame.withArgs(null),
);
});
});

it("should not disable iframe animations if 'disableAnimation: true' and 'automationProtocol: devtools'", async () => {
Expand Down

0 comments on commit e21a0e4

Please sign in to comment.