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

[RN Mobile] - Add helper to wait for screen to load before continuing test #39377

Merged
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
36 changes: 31 additions & 5 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const strToKeycode = {
[ backspace ]: 67,
};

const editorReadyTimeout = 8000;

const timer = ( ms ) => new Promise( ( res ) => setTimeout( res, ms ) );

const isAndroid = () => {
Expand Down Expand Up @@ -159,9 +157,6 @@ const setupDriver = async () => {
// eslint-disable-next-line no-console
console.log( status );

await driver.setImplicitWaitTimeout( editorReadyTimeout );
await timer( editorReadyTimeout );

await driver.setOrientation( 'PORTRAIT' );
return driver;
};
Expand Down Expand Up @@ -454,6 +449,35 @@ const toggleOrientation = async ( driver ) => {
}
};

const isEditorVisible = async ( driver ) => {
const postTitleLocator = isAndroid()
? `//android.widget.EditText[contains(@content-desc, "Post title")]`
: `(//XCUIElementTypeScrollView/XCUIElementTypeOther/XCUIElementTypeOther[contains(@name, "Post title")])`;

await waitForVisible( driver, postTitleLocator );
};

const waitForVisible = async ( driver, elementLocator, iteration = 0 ) => {
const maxIteration = 25;
const timeout = 1000;

if ( iteration >= maxIteration ) {
throw new Error(
`"${ elementLocator }" is still not visible after ${ iteration } retries!`
);
} else if ( iteration !== 0 ) {
// wait before trying to locate element again
await driver.sleep( timeout );
}

const locator = await driver.elementsByXPath( elementLocator );
if ( locator.length !== 1 ) {
// if locator is not visible, try again
return waitForVisible( driver, elementLocator, iteration + 1 );
}
return locator[ 0 ];
jostnes marked this conversation as resolved.
Show resolved Hide resolved
};

module.exports = {
backspace,
timer,
Expand All @@ -474,4 +498,6 @@ module.exports = {
toggleHtmlMode,
toggleOrientation,
doubleTap,
isEditorVisible,
waitForVisible,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ const {
swipeFromTo,
longPressMiddleOfElement,
doubleTap,
isEditorVisible,
waitForVisible,
} = require( '../helpers/utils' );

const initializeEditorPage = async () => {
const driver = await setupDriver();
await isEditorVisible( driver );
return new EditorPage( driver );
};

Expand All @@ -36,8 +39,6 @@ class EditorPage {
this.accessibilityIdXPathAttrib = 'content-desc';
this.accessibilityIdKey = 'contentDescription';
}

driver.setImplicitWaitTimeout( 5000 );
}

async getBlockList() {
Expand Down Expand Up @@ -159,12 +160,11 @@ class EditorPage {

async getTextViewForHtmlViewContent() {
const accessibilityId = 'html-view-content';
let blockLocator = `//*[@${ this.accessibilityIdXPathAttrib }="${ accessibilityId }"]`;
const htmlViewLocator = isAndroid()
? `//*[@${ this.accessibilityIdXPathAttrib }="${ accessibilityId }"]`
: `//XCUIElementTypeTextView[starts-with(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityId }")]`;

if ( ! isAndroid() ) {
blockLocator = `//XCUIElementTypeTextView[starts-with(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityId }")]`;
}
return await this.driver.elementByXPath( blockLocator );
return await waitForVisible( this.driver, htmlViewLocator );
}

// Returns html content
Expand Down