Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Improve E2E test stability #58150

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
52 changes: 9 additions & 43 deletions packages/react-native-editor/__device-tests__/pages/editor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 ];
Expand All @@ -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 ];
Expand Down Expand Up @@ -668,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
// =========================
Expand Down
Loading