From 483a4f155e08ede8d7f013d2eb97a2a425735484 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 23 Jan 2024 12:25:22 -0500 Subject: [PATCH 1/2] test: Increase `swipeDown` swipe distance The larger swipe distance results in faster scrolling, which will reduce the time it takes to scroll. The reduced time will mitigate the need to await longer scroll durations before asserting expectations and reduce test durations in general. Additionally, refactor both `swipeUp` and `swipeDown` to use an options parameter to communicate each argument intent, as well as improve alignment between the utilities. --- .../__device-tests__/helpers/utils.js | 31 ++++++++++++++----- .../__device-tests__/pages/editor-page.js | 12 +++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 5af85b9e6847d0..c44bc277155e2c 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -418,13 +418,20 @@ const selectTextFromElement = async ( driver, element ) => { } }; -// Starts from the middle of the screen or the element(if specified) -// and swipes upwards. +/** + * Starts from the middle of the screen or the element(if specified) + * and swipes upwards. + * + * @param {Object} driver WebdriverIO driver + * @param {Object} element Element to swipe from + * @param {Object} options Options + * @param {number} options.delay Delay between the swipe and the next action + * @param {number} options.endYCoefficient Multiplier for the end Y coordinate + */ const swipeUp = async ( driver, element = undefined, - delay = 3000, - endYCoefficient = 0.5 + { delay = 3000, endYCoefficient = 0.5 } = {} ) => { let size = await driver.getWindowSize(); let y = 0; @@ -465,15 +472,25 @@ const swipeFromTo = async ( .pause( delay ) .perform(); -// Starts from the middle of the screen and swipes downwards -const swipeDown = async ( driver, delay = 3000 ) => { +/** + * Starts from the middle of the screen and swipes downwards + * + * @param {Object} driver WebdriverIO driver + * @param {Object} options Options + * @param {number} options.delay Delay between the swipe and the next action + * @param {number} options.endYCoefficient Multiplier for the end Y coordinate + */ +const swipeDown = async ( + driver, + { delay = 3000, endYCoefficient = 0.5 } = {} +) => { const size = await driver.getWindowSize(); const y = 0; const startX = size.width / 2; const startY = y + size.height / 3; const endX = startX; - const endY = startY - startY * -1 * 0.5; + const endY = startY - startY * -1 * endYCoefficient; await swipeFromTo( driver, 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 fe3f410601a8dc..201ea64f6edfd5 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -251,7 +251,7 @@ class EditorPage { if ( options.autoscroll ) { if ( isAndroid() ) { - await swipeDown( this.driver ); + await swipeDown( this.driver, { endYCoefficient: 2 } ); } else { await tapStatusBariOS( this.driver ); } @@ -288,7 +288,10 @@ class EditorPage { `//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityLabel }")]` ); if ( elements.length === 0 ) { - await swipeUp( this.driver, undefined, 100, 1 ); + await swipeUp( this.driver, undefined, { + delay: 100, + endYCoefficient: 1, + } ); return this.androidScrollAndReturnElement( accessibilityLabel ); } return elements[ elements.length - 1 ]; @@ -301,7 +304,10 @@ class EditorPage { const elements = await this.driver.$$( `~${ id }` ); if ( elements.length === 0 ) { - await swipeUp( this.driver, undefined, 100, 1 ); + await swipeUp( this.driver, undefined, { + delay: 100, + endYCoefficient: 1, + } ); return this.scrollAndReturnElementByAccessibilityId( id ); } return elements[ elements.length - 1 ]; From ef47386e1fe883dc86ff3b58a0f8b40bc763ebf6 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 23 Jan 2024 12:41:37 -0500 Subject: [PATCH 2/2] test: Remove unused `removeBlockAtPosition` utility All usage was removed in https://github.com/WordPress/gutenberg/pull/52289. Additionally, the utility may be outdated and incompatible with the current editor UI. --- .../__device-tests__/pages/editor-page.js | 40 ------------------- 1 file changed, 40 deletions(-) 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 201ea64f6edfd5..07b51d35f4ad9d 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -674,46 +674,6 @@ class EditorPage { await moveDownButton.click(); } - // Position of the block to remove - // Block will no longer be present if this succeeds. - async removeBlockAtPosition( blockName = '', position = 1 ) { - if ( ! ( await this.hasBlockAtPosition( position, blockName ) ) ) { - throw Error( `No Block at position ${ position }` ); - } - - const buttonElementName = isAndroid() - ? '//*' - : '//XCUIElementTypeButton'; - const blockActionsMenuButtonIdentifier = `Open Block Actions Menu`; - const blockActionsMenuButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockActionsMenuButtonIdentifier }")]`; - if ( isAndroid() ) { - const block = await this.getBlockAtPosition( blockName, position ); - let checkList = await this.driver.$$( - blockActionsMenuButtonLocator - ); - while ( checkList.length === 0 ) { - await swipeUp( this.driver, block ); // Swipe up to show remove icon at the bottom. - checkList = await this.driver.$$( - blockActionsMenuButtonLocator - ); - } - } - - const blockActionsMenuButton = await waitForVisible( - this.driver, - blockActionsMenuButtonLocator - ); - await blockActionsMenuButton.click(); - const removeActionButtonIdentifier = 'Remove block'; - const removeActionButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ removeActionButtonIdentifier }")]`; - const removeActionButton = await waitForVisible( - this.driver, - removeActionButtonLocator - ); - - await removeActionButton.click(); - } - // ========================= // Formatting toolbar functions // =========================