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: Update E2E utilities #55322

Merged
merged 10 commits into from
Oct 16, 2023
2 changes: 2 additions & 0 deletions packages/react-native-editor/__device-tests__/helpers/caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ios = {
exports.iosLocal = ( { iPadDevice = false } ) => ( {
...ios,
deviceName: ! iPadDevice ? 'iPhone 13' : 'iPad Pro (9.7-inch)',
devicePixelRatio: ! iPadDevice ? 3 : 2,
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved
usePrebuiltWDA: true,
} );

Expand All @@ -19,6 +20,7 @@ exports.iosServer = ( { iPadDevice = false } ) => ( {
deviceName: ! iPadDevice
? 'iPhone 13 Simulator'
: 'iPad Pro (9.7 inch) Simulator',
devicePixelRatio: ! iPadDevice ? 3 : 2,
} );

exports.android = {
Expand Down
10 changes: 6 additions & 4 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,18 @@ const toggleOrientation = async ( driver ) => {
*/
const toggleDarkMode = ( driver, darkMode = true ) => {
if ( isAndroid() ) {
return driver.execute( 'mobile: shell', [
return driver.executeScript( 'mobile: shell', [
{
command: `cmd uimode night ${ darkMode ? 'yes' : 'no' }`,
},
] );
}

return driver.execute( 'mobile: setAppearance', {
style: darkMode ? 'dark' : 'light',
} );
return driver.executeScript( 'mobile: setAppearance', [
{
style: darkMode ? 'dark' : 'light',
},
] );
};

const isEditorVisible = async ( driver ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class EditorPage {
}

async getAddBlockButton() {
const elements =
await this.driver.elementsByAccessibilityId( ADD_BLOCK_ID );
const elements = await this.driver.$$( `~${ ADD_BLOCK_ID }` );
return elements[ 0 ];
}

Expand Down Expand Up @@ -302,7 +301,10 @@ class EditorPage {
async waitForKeyboardToBeHidden() {
const { addButtonLocation } = this.initialValues;
const addButton = await this.getAddBlockButton();
const location = await addButton.getLocation();
Copy link
Member Author

Choose a reason for hiding this comment

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

Occasionally, this query would fail with Appium 2 with the following error. Guarding against an empty query return avoids this error and results in the recursive loop of waitForKeyboardToBeHidden to occur.

TypeError: Cannot read properties of undefined (reading 'getLocation')

let location;
if ( addButton ) {
location = await addButton.getLocation();
}
let YLocation = addButtonLocation?.y;
const currentOrientation = await this.driver.getOrientation();
const isLandscape = currentOrientation === 'LANDSCAPE';
Expand All @@ -316,7 +318,7 @@ class EditorPage {
);
}

if ( location.y < YLocation ) {
if ( ! addButton || location?.y < YLocation ) {
await this.waitForKeyboardToBeHidden();
}
}
Expand Down
Loading