From bac0848dc78e2a5254aa3d3c40cf8449b3b713c1 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Fri, 16 Dec 2022 18:46:40 +0100 Subject: [PATCH] Mobile - Fix block insertion flakiness on Android --- .../gutenberg-editor-block-insertion-2.test.js | 6 ++++-- .../__device-tests__/helpers/utils.js | 9 +++++++-- .../__device-tests__/pages/editor-page.js | 12 +++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js index e86439f20de168..44cc767ec5bfc3 100644 --- a/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js +++ b/packages/react-native-editor/__device-tests__/gutenberg-editor-block-insertion-2.test.js @@ -10,6 +10,7 @@ import { paragraphBlockEmpty, separatorBlockEmpty, } from './helpers/test-data'; +import { waitForMediaLibrary } from './helpers/utils'; describe( 'Gutenberg Editor tests for Block insertion 2', () => { it( 'adds new block at the end of post', async () => { @@ -65,14 +66,15 @@ describe( 'Gutenberg Editor tests for Block insertion 2', () => { await editorPage.addNewBlock( blockNames.image, 'before' ); + await waitForMediaLibrary( editorPage.driver ); + await editorPage.closePicker(); + const imageBlock = await editorPage.getBlockAtPosition( blockNames.image, 2 ); expect( imageBlock ).toBeTruthy(); - await editorPage.closePicker(); - const expectedHtml = [ headerBlockEmpty, imageBlockEmpty, diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 64d802f30dbec8..93f4e008ac0edf 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -313,12 +313,17 @@ const clickElementOutsideOfTextInput = async ( driver, element ) => { }; // Long press to activate context menu. -const longPressMiddleOfElement = async ( driver, element ) => { +const longPressMiddleOfElement = async ( + driver, + element, + customElementSize +) => { const location = await element.getLocation(); - const size = await element.getSize(); + const size = customElementSize || ( await element.getSize() ); const x = location.x + size.width / 2; const y = location.y + size.height / 2; + const action = new wd.TouchAction( driver ) .longPress( { x, y } ) .wait( 5000 ) // Setting to wait a bit longer because this is failing more frequently on the CI diff --git a/packages/react-native-editor/__device-tests__/pages/editor-page.js b/packages/react-native-editor/__device-tests__/pages/editor-page.js index 2f5aae6de9cbf3..c7e6e6fe1f18d5 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -305,7 +305,17 @@ class EditorPage { ); if ( relativePosition === 'before' ) { - await longPressMiddleOfElement( this.driver, addButton ); + // On Android it doesn't get the right size of the button + const customElementSize = { + width: 43, + height: 43, + }; + + await longPressMiddleOfElement( + this.driver, + addButton, + customElementSize + ); const addBlockBeforeButtonLocator = isAndroid() ? '//android.widget.Button[@content-desc="Add Block Before"]' : '//XCUIElementTypeButton[@name="Add Block Before"]';