From 8feb3916d6dc72f10b965d4bd92109e6152f7f2b Mon Sep 17 00:00:00 2001 From: Drapich Piotr Date: Tue, 4 Aug 2020 13:49:48 +0200 Subject: [PATCH] [RNMobile] E2E Android - Use swipe gesture to scroll inserter menu (#24338) --- .../__device-tests__/helpers/utils.js | 21 ++++++++++++------- .../__device-tests__/pages/editor-page.js | 9 +++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 283e0ed0f7254..878b0cf57f503 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -446,10 +446,19 @@ const swipeUp = async ( driver, element = undefined ) => { const endX = startX; const endY = startY + startY * -1 * 0.5; + await swipeFromTo( driver, { x: startX, y: startY }, { x: endX, y: endY } ); +}; + +const defaultCoordinates = { x: 0, y: 0 }; +const swipeFromTo = async ( + driver, + from = defaultCoordinates, + to = defaultCoordinates +) => { const action = await new wd.TouchAction( driver ); - action.press( { x: startX, y: startY } ); + action.press( from ); action.wait( 3000 ); - action.moveTo( { x: endX, y: endY } ); + action.moveTo( to ); action.release(); await action.perform(); }; @@ -464,12 +473,7 @@ const swipeDown = async ( driver ) => { const endX = startX; const endY = startY - startY * -1 * 0.5; - const action = await new wd.TouchAction( driver ); - action.press( { x: startX, y: startY } ); - action.wait( 3000 ); - action.moveTo( { x: endX, y: endY } ); - action.release(); - await action.perform(); + await swipeFromTo( driver, { x: startX, y: startY }, { x: endX, y: endY } ); }; const toggleHtmlMode = async ( driver, toggleOn ) => { @@ -526,6 +530,7 @@ module.exports = { tapPasteAboveElement, swipeDown, swipeUp, + swipeFromTo, stopDriver, toggleHtmlMode, toggleOrientation, 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 6e3b93d26c02f..d9f327c2188f7 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -7,6 +7,7 @@ import { swipeDown, typeString, toggleHtmlMode, + swipeFromTo, } from '../helpers/utils'; export default class EditorPage { @@ -197,11 +198,17 @@ export default class EditorPage { // Attempts to find the given block button in the block inserter control. async findBlockButton( blockName ) { if ( isAndroid() ) { + const size = await this.driver.getWindowSize(); + const x = size.width / 2; // Checks if the Block Button is available, and if not will scroll to the second half of the available buttons. while ( ! ( await this.driver.hasElementByAccessibilityId( blockName ) ) ) { - await this.driver.pressKeycode( 20 ); // Press the Down arrow to force a scroll. + swipeFromTo( + this.driver, + { x, y: size.height - 100 }, + { x, y: size.height - 450 } + ); } return await this.driver.elementByAccessibilityId( blockName );