From d53c157ac7bd5f91ba285f0241e0ad21a7c34d9a Mon Sep 17 00:00:00 2001 From: DudaGod Date: Wed, 29 Nov 2023 14:37:05 +0300 Subject: [PATCH] fix: correctly disable animations in inframes for ios --- src/browser/existing-browser.js | 5 ++- test/src/browser/existing-browser.js | 63 ++++++++++++++++++++-------- test/src/browser/utils.js | 6 +-- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/browser/existing-browser.js b/src/browser/existing-browser.js index f29ce63d6..9e56e786b 100644 --- a/src/browser/existing-browser.js +++ b/src/browser/existing-browser.js @@ -302,7 +302,10 @@ module.exports = class ExistingBrowser extends Browser { await cb(); } } finally { - await this._session.switchToParentFrame(); + if (!_.isEmpty(iframes)) { + // switchToParentFrame does not work in ios - https://github.com/appium/appium/issues/14882 + await this._session.switchToFrame(null); + } } } diff --git a/test/src/browser/existing-browser.js b/test/src/browser/existing-browser.js index 2e214753c..62d8bb911 100644 --- a/test/src/browser/existing-browser.js +++ b/test/src/browser/existing-browser.js @@ -725,7 +725,8 @@ describe("ExistingBrowser", () => { it("should disable animations if 'disableAnimation: true' and 'automationProtocol: webdriver'", async () => { const clientBridge = stubClientBridge_(); const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" })); - const [wdElement] = await browser.publicAPI.findElements("css selector", ".some-selector"); + const iframeElement = { "element-12345": "67890_element_1" }; + browser.publicAPI.findElements.withArgs("css selector", "iframe").resolves([iframeElement]); await browser.prepareScreenshot(".selector", { disableAnimation: true }); @@ -733,7 +734,7 @@ describe("ExistingBrowser", () => { ".selector", sinon.match({ disableAnimation: true }), ]); - assert.calledOnceWith(browser.publicAPI.switchToFrame, wdElement); + assert.calledWith(browser.publicAPI.switchToFrame, iframeElement); assert.calledWith(clientBridge.call, "disableFrameAnimations"); }); @@ -754,7 +755,8 @@ describe("ExistingBrowser", () => { it("should not disable animations if 'disableAnimation: false'", async () => { const clientBridge = stubClientBridge_(); const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" })); - const [wdElement] = await browser.publicAPI.findElements("css selector", ".some-selector"); + const iframeElement = { "element-12345": "67890_element_1" }; + browser.publicAPI.findElements.withArgs("css selector", "iframe").resolves([iframeElement]); await browser.prepareScreenshot(".selector", { disableAnimation: false }); @@ -762,7 +764,7 @@ describe("ExistingBrowser", () => { ".selector", sinon.match({ disableAnimation: true }), ]); - assert.neverCalledWith(browser.publicAPI.switchToFrame, wdElement); + assert.neverCalledWith(browser.publicAPI.switchToFrame, iframeElement); assert.neverCalledWith(clientBridge.call, "disableFrameAnimations"); }); }); @@ -786,27 +788,52 @@ describe("ExistingBrowser", () => { assert.neverCalledWith(clientBridge.call, "cleanupFrameAnimations"); }); - it("should cleanup animations in iframe if 'automationProtocol: webdriver'", async () => { - const clientBridge = stubClientBridge_(); - const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" })); - const [wdElement] = await browser.publicAPI.findElements("css selector", ".some-selector"); + it("should not cleanup animations in iframe if 'automationProtocol: devtools'", async () => { + stubClientBridge_(); + const browser = await initBrowser_(mkBrowser_({ automationProtocol: "devtools" })); await browser.cleanupScreenshot({ disableAnimation: true }); - assert.calledOnceWith(browser.publicAPI.switchToFrame, wdElement); - assert.calledWith(clientBridge.call, "cleanupFrameAnimations"); - assert.callOrder(browser.publicAPI.switchToFrame, clientBridge.call); + assert.notCalled(browser.publicAPI.switchToFrame); }); - it("should not cleanup animations in iframe if 'automationProtocol: devtools'", async () => { - const clientBridge = stubClientBridge_(); - const browser = await initBrowser_(mkBrowser_({ automationProtocol: "devtools" })); - const [wdElement] = await browser.publicAPI.findElements("css selector", ".some-selector"); + describe("'automationProtocol: webdriver'", () => { + it("should cleanup animations in iframe", 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]); - await browser.cleanupScreenshot({ disableAnimation: true }); + await browser.cleanupScreenshot({ disableAnimation: true }); - assert.notCalled(browser.publicAPI.switchToFrame); - assert.neverCalledWith(clientBridge.call, "cleanupFrameAnimations", wdElement); + assert.calledWith(browser.publicAPI.switchToFrame, iframeElement); + assert.calledWith(clientBridge.call, "cleanupFrameAnimations"); + assert.callOrder(browser.publicAPI.switchToFrame, clientBridge.call); + }); + + it("should switch to parent frame after clean animations in iframe", async () => { + stubClientBridge_(); + const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" })); + const iframeElement = { "element-12345": "67890_element_1" }; + browser.publicAPI.findElements.withArgs("css selector", "iframe").resolves([iframeElement]); + + await browser.cleanupScreenshot({ disableAnimation: true }); + + assert.callOrder( + browser.publicAPI.switchToFrame.withArgs(iframeElement), + browser.publicAPI.switchToFrame.withArgs(null), + ); + }); + + it("should not switch to any frame if there are no iframes on the page ", async () => { + stubClientBridge_(); + const browser = await initBrowser_(mkBrowser_({ automationProtocol: "webdriver" })); + browser.publicAPI.findElements.withArgs("css selector", "iframe").resolves([]); + + await browser.cleanupScreenshot({ disableAnimation: true }); + + assert.notCalled(browser.publicAPI.switchToFrame); + }); }); }); diff --git a/test/src/browser/utils.js b/test/src/browser/utils.js index e66c184c0..e6e569c8b 100644 --- a/test/src/browser/utils.js +++ b/test/src/browser/utils.js @@ -63,9 +63,6 @@ exports.mkSessionStub_ = () => { click: sinon.stub().named("click").resolves(), waitForExist: sinon.stub().named("waitForExist").resolves(), }; - const wdElement = { - "element-6066-11e4-a52e-4f735466cecf": "95777D6590AF653A2FD8EB0ADD20B333_element_1", - }; session.sessionId = "1234567890"; session.isW3C = false; @@ -89,9 +86,8 @@ exports.mkSessionStub_ = () => { session.$ = sinon.stub().named("$").resolves(wdioElement); session.getWindowHandles = sinon.stub().named("getWindowHandles").resolves([]); session.switchToWindow = sinon.stub().named("switchToWindow").resolves(); - session.findElements = sinon.stub().named("findElements").resolves([wdElement]); + session.findElements = sinon.stub().named("findElements").resolves([]); session.switchToFrame = sinon.stub().named("switchToFrame").resolves(); - session.switchToParentFrame = sinon.stub().named("switchToParentFrame").resolves(); session.addCommand = sinon.stub().callsFake((name, command, isElement) => { const target = isElement ? wdioElement : session;