-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RNMobile] - Add waits to fix editor test flakiness #39668
Changes from all commits
8885da0
dc4337d
1e6fcbc
9541748
8fb37dc
c1c5296
1b6d50c
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 | ||||
---|---|---|---|---|---|---|
|
@@ -258,29 +258,33 @@ class EditorPage { | |||||
// ========================= | ||||||
|
||||||
async addNewBlock( blockName, relativePosition ) { | ||||||
// Click add button. | ||||||
let identifier = 'Add block'; | ||||||
if ( isAndroid() ) { | ||||||
identifier = 'Add block, Double tap to add a block'; | ||||||
} | ||||||
const addButton = await this.driver.elementByAccessibilityId( | ||||||
identifier | ||||||
const addBlockButtonLocator = isAndroid() | ||||||
? '//android.widget.Button[@content-desc="Add block, Double tap to add a block"]' | ||||||
: '//XCUIElementTypeButton[@name="add-block-button"]'; | ||||||
|
||||||
const addButton = await waitForVisible( | ||||||
this.driver, | ||||||
addBlockButtonLocator | ||||||
); | ||||||
|
||||||
if ( relativePosition === 'before' ) { | ||||||
await longPressMiddleOfElement( this.driver, addButton ); | ||||||
const addBlockBeforeButtonLocator = isAndroid() | ||||||
? '//android.widget.Button[@content-desc="Add Block Before"]' | ||||||
: '//XCUIElementTypeButton[@name="Add Block Before"]'; | ||||||
|
||||||
const addBlockBeforeButton = await this.driver.elementByAccessibilityId( | ||||||
'Add Block Before' | ||||||
const addBlockBeforeButton = await waitForVisible( | ||||||
this.driver, | ||||||
addBlockBeforeButtonLocator | ||||||
); | ||||||
|
||||||
await addBlockBeforeButton.click(); | ||||||
} else { | ||||||
await addButton.click(); | ||||||
} | ||||||
|
||||||
// Click on block of choice. | ||||||
const blockButton = await this.findBlockButton( blockName ); | ||||||
|
||||||
if ( isAndroid() ) { | ||||||
await blockButton.click(); | ||||||
} else { | ||||||
|
@@ -299,6 +303,12 @@ class EditorPage { | |||||
|
||||||
// Attempts to find the given block button in the block inserter control. | ||||||
async findBlockButton( blockName ) { | ||||||
// Wait for the first block, Paragraph block, to load before looking for other blocks | ||||||
const paragraphBlockLocator = isAndroid() | ||||||
? '//android.widget.Button[@content-desc="Paragraph block"]/android.widget.TextView' | ||||||
: '//XCUIElementTypeButton[@name="Paragraph block"]'; | ||||||
Comment on lines
+306
to
+309
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. For now, I've set that it waits for the Paragraph block to load because it's the first one on the blocks list, I'm not sure how often the list changes so this has the potential to fail in the future. Another option is to wait for the search box. What do you all think? 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. The block picker view has a
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. Ah ok but looks like that is before the block picker view: After some investigation, looks like we can actually create another wait helper that uses IDs! But it has to be an ID defined like this (i.e For Android, There is an open issue for this here. Appium doc how to use this here. I am not sure where this is defined (looks like not on the I think, for now, I will leave it to wait for Paragraph block before continuing the test. Future improvements (i.e. add id and use it for the test) to be done in a separate PR. Is that ok? 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 sorry, I'm afraid I referenced the wrong test ID. The one I'm wanted to share is
In any case, I think it's quite reliable to use the Paragraph block as it's a block that will be always present. |
||||||
|
||||||
await waitForVisible( this.driver, paragraphBlockLocator ); | ||||||
const blockAccessibilityLabel = `${ blockName } block`; | ||||||
const blockAccessibilityLabelNewBlock = `${ blockAccessibilityLabel }, newly available`; | ||||||
|
||||||
|
@@ -611,10 +621,16 @@ class EditorPage { | |||||
|
||||||
async closePicker() { | ||||||
if ( isAndroid() ) { | ||||||
// Wait for media block picker to load before closing | ||||||
const locator = | ||||||
'//android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup'; | ||||||
await waitForVisible( this.driver, locator ); | ||||||
|
||||||
await swipeDown( this.driver ); | ||||||
} else { | ||||||
const cancelButton = await this.driver.elementByAccessibilityId( | ||||||
'Cancel' | ||||||
const cancelButton = await waitForVisible( | ||||||
this.driver, | ||||||
'//XCUIElementTypeButton[@name="Cancel"]' | ||||||
); | ||||||
await cancelButton.click(); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to use
XPath
instead ofaccessibilityId
because if anaccessibilityId
is not found, the Appium session is immediately terminated giving no chance to wait and retry. While XPaths are not recommended locators, it is the workaround for this case for now.Let me know if anyone knows of a better alternative!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it's generally not recommended to use
XPaths
but I wouldn't oppose using it if there's no other option. I haven't investigated other approaches, but I recall that WebDriver automatically finishes the session upon some failures, even if the call is wrapped withtry-catch
😞 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried wrapping it in a try-catch, hoping to bypass the error but it didn't work 😞 I also checked if it was configurable but looks like it isn't.