-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[RNMobile] - Add optional wait in getBlockAtPosition #40078
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,9 +51,31 @@ class EditorPage { | |||||||||||||||||||||||||
| async getBlockAtPosition( | ||||||||||||||||||||||||||
| blockName, | ||||||||||||||||||||||||||
| position = 1, | ||||||||||||||||||||||||||
| options = { autoscroll: false } | ||||||||||||||||||||||||||
| options = { autoscroll: false, useWaitForVisible: false } | ||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||
| const blockLocator = `//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")]`; | ||||||||||||||||||||||||||
| let blockLocator; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Make it optional to use waitForVisible() so we can handle this test by test. | ||||||||||||||||||||||||||
| // This condition can be removed once we have gone through all test cases. | ||||||||||||||||||||||||||
| if ( options.useWaitForVisible ) { | ||||||||||||||||||||||||||
| let elementType; | ||||||||||||||||||||||||||
| switch ( blockName ) { | ||||||||||||||||||||||||||
| case blockNames.cover: | ||||||||||||||||||||||||||
| elementType = 'XCUIElementTypeButton'; | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| elementType = 'XCUIElementTypeOther'; | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| blockLocator = isAndroid() | ||||||||||||||||||||||||||
| ? `//android.view.ViewGroup[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")]` | ||||||||||||||||||||||||||
| : `(//${ elementType }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")])[1]`; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
| await waitForVisible( this.driver, blockLocator ); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| blockLocator = `//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")]`; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| const elements = await this.driver.elementsByXPath( blockLocator ); | ||||||||||||||||||||||||||
| const lastElementFound = elements[ elements.length - 1 ]; | ||||||||||||||||||||||||||
| if ( elements.length === 0 && options.autoscroll ) { | ||||||||||||||||||||||||||
|
|
@@ -429,6 +451,10 @@ class EditorPage { | |||||||||||||||||||||||||
| : '//XCUIElementTypeButton'; | ||||||||||||||||||||||||||
| const blockActionsMenuButtonIdentifier = `Open Block Actions Menu`; | ||||||||||||||||||||||||||
| const blockActionsMenuButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockActionsMenuButtonIdentifier }")]`; | ||||||||||||||||||||||||||
| const blockActionsMenuButton = await waitForVisible( | ||||||||||||||||||||||||||
| this.driver, | ||||||||||||||||||||||||||
| blockActionsMenuButtonLocator | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
Comment on lines
+454
to
+457
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that the following code block handles the case where the Block Actions Menu button is not visible. The buttons is displayed at the bottom of the block, so it tries to scroll down the block list until it's visible. Not sure why this behavior is only applied on Android since it might also happen on iOS 🤔 . In any case, I'm wondering if we could use the gutenberg/packages/react-native-editor/__device-tests__/pages/editor-page.js Lines 459 to 470 in eda2d66
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, I can try that, this one I will try in the next PR instead of here as this is something that the paragraph tests use a lot and testing could take a while. Good point about being Android only, not sure why but I'll try to remove it to see if it will work for both platforms in the next PR as well. |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if ( isAndroid() ) { | ||||||||||||||||||||||||||
| const block = await this.getBlockAtPosition( blockName, position ); | ||||||||||||||||||||||||||
|
|
@@ -443,14 +469,12 @@ class EditorPage { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const blockActionsMenuButton = await this.driver.elementByXPath( | ||||||||||||||||||||||||||
| blockActionsMenuButtonLocator | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| await blockActionsMenuButton.click(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const removeActionButtonIdentifier = 'Remove block'; | ||||||||||||||||||||||||||
| const removeActionButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ removeActionButtonIdentifier }")]`; | ||||||||||||||||||||||||||
| const removeActionButton = await this.driver.elementByXPath( | ||||||||||||||||||||||||||
| const removeActionButton = await waitForVisible( | ||||||||||||||||||||||||||
| this.driver, | ||||||||||||||||||||||||||
| removeActionButtonLocator | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.