Skip to content

Commit

Permalink
Mobile - E2E Tests - Adds selectTextFromTextInput util, toggleFormatt…
Browse files Browse the repository at this point in the history
…ing, openLintSettings, getButtonBlockTextInputAtPosition, addButtonWithInlineAppender and waitForElementToBeDisplayedByXPath helpers
  • Loading branch information
Gerardo committed Feb 22, 2023
1 parent 1c5da84 commit ac47b97
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ const tapPasteAboveElement = async ( driver, element ) => {
}
};

const selectTextFromTextInput = async ( driver, element ) => {
if ( isAndroid() ) {
await longPressMiddleOfElement( driver, element, 0 );
} else {
await doubleTap( driver, element );
}
};

// Starts from the middle of the screen or the element(if specified)
// and swipes upwards.
const swipeUp = async (
Expand Down Expand Up @@ -684,6 +692,7 @@ module.exports = {
longPressMiddleOfElement,
setClipboard,
setupDriver,
selectTextFromTextInput,
stopDriver,
swipeDown,
swipeFromTo,
Expand Down
56 changes: 43 additions & 13 deletions packages/react-native-editor/__device-tests__/pages/editor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,28 @@ class EditorPage {
await removeActionButton.click();
}

// =========================
// Formatting toolbar functions
// =========================

async toggleFormatting( formatting ) {
const identifier = isAndroid()
? `//android.widget.Button[@content-desc="${ formatting }"]/android.view.ViewGroup`
: `//XCUIElementTypeButton[@name="${ formatting }"]`;
const toggleElement = await this.waitForElementToBeDisplayedByXPath(
identifier
);
return await toggleElement.click();
}

async openLinkToSettings() {
const element = await this.waitForElementToBeDisplayedById(
'Link to, Search or type URL'
);

await element.click();
}

// =========================
// Paragraph Block functions
// =========================
Expand Down Expand Up @@ -846,23 +868,21 @@ class EditorPage {
// Button Block functions
// =========================

async getButtonBlockTextInputAtPosition( blockName, position = 1 ) {
// iOS needs a click to get the text element
if ( ! isAndroid() ) {
const textBlockLocator = `(//XCUIElementTypeButton[contains(@name, "Button Block. Row ${ position }")])`;

const textBlock = await waitForVisible(
this.driver,
textBlockLocator
);
await textBlock.click();
}

async getButtonBlockTextInputAtPosition( position = 1 ) {
const blockLocator = isAndroid()
? `//android.view.ViewGroup[@content-desc="Button Block. Row ${ position }"]/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.widget.EditText`
: `//XCUIElementTypeButton[contains(@name, "Button Block. Row ${ position }")]//XCUIElementTypeTextView`;

return await waitForVisible( this.driver, blockLocator );
return await this.waitForElementToBeDisplayedByXPath( blockLocator );
}

async addButtonWithInlineAppender( position = 1 ) {
const appenderButton = isAndroid()
? await this.waitForElementToBeDisplayedByXPath(
`//android.view.ViewGroup[@content-desc="block-list"]/android.view.ViewGroup[${ position }]/android.widget.Button`
)
: await this.waitForElementToBeDisplayedById( 'appender-button' );
await appenderButton.click();
}

async waitForElementToBeDisplayedById( id, timeout = 2000 ) {
Expand All @@ -874,6 +894,16 @@ class EditorPage {

return await this.driver.elementByAccessibilityId( id );
}

async waitForElementToBeDisplayedByXPath( id, timeout = 2000 ) {
await this.driver.waitForElementByXPath(
id,
wd.asserters.isDisplayed,
timeout
);

return await this.driver.elementByXPath( id );
}
}

const blockNames = {
Expand Down

0 comments on commit ac47b97

Please sign in to comment.