Skip to content

Commit

Permalink
Mobile - Fix block insertion flakiness on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo committed Dec 16, 2022
1 parent 538d7df commit bac0848
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]';
Expand Down

1 comment on commit bac0848

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3715332202
📝 Reported issues:

Please sign in to comment.