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

[Mobile] - Appium 2 Migration - Updating more utils #55420

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Changes from 1 commit
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: 32 additions & 4 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,42 @@ const tapStatusBariOS = async ( driver ) => {
};

const selectTextFromElement = async ( driver, element ) => {
await longPressMiddleOfElement( driver, element );
const timeout = 1000;

// On Android we can't "locate" the context menu options,
// To avoid having fixed coordinates to be able to
// select all text, it just selects all text by
// long-pressing and dragging.
if ( isAndroid() ) {
await element.click();

const location = await element.getLocation();
const size = await element.getSize();
const paddingPercentage = 0.2;
const leftPaddingOffset = size.width * paddingPercentage;
const startX = location.x + leftPaddingOffset;
const endX = location.x + size.width;
const centerY = location.y + size.height / 2;

await driver
.action( 'pointer', {
parameters: { pointerType: 'touch' },
} )
.move( { x: startX, y: centerY } )
.down()
.pause( timeout )
.move( { x: endX, y: centerY, duration: timeout } )
.up()
.pause( timeout )
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved
.perform();
} else {
// On iOS we can use the context menu to "Select all" text.
await longPressMiddleOfElement( driver, element );

// On iOS long-pressing doesn't select the text automatically
if ( ! isAndroid() ) {
const selectAllElement = await driver.$(
'//XCUIElementTypeMenuItem[@name="Select All"]'
);
await selectAllElement.waitForDisplayed( { timeout: 1000 } );
await selectAllElement.waitForDisplayed( { timeout } );
await selectAllElement.click();
}
};
Expand Down