Skip to content
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
Prev Previous commit
Next Next commit
lint fixes
  • Loading branch information
jostnes committed May 11, 2022
commit 4c7f918067fae2ce113d893ff77589875321fdf5
39 changes: 25 additions & 14 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,21 @@ const waitForMediaLibrary = async ( driver ) => {
* @param {number} iteration - Default value is 0
* @return {string} - Returns the first element found, empty string if not found
*/
const waitForVisible = async (
driver,
elementLocator,
maxIteration = 25,
iteration = 0
const waitForVisible = async (
driver,
elementLocator,
maxIteration = 25,
iteration = 0
) => {
const timeout = 1000;

if ( iteration >= maxIteration ) {
// if element not found, print error and return empty string
// eslint-disable-next-line no-console
console.error(`"${ elementLocator }" is still not visible after ${ iteration } retries!`)
return ''
console.error(
`"${ elementLocator }" is still not visible after ${ iteration } retries!`
);
return '';
} else if ( iteration !== 0 ) {
// wait before trying to locate element again
await driver.sleep( timeout );
Expand All @@ -492,7 +494,12 @@ const waitForVisible = async (
const element = await driver.elementsByXPath( elementLocator );
if ( element.length !== 1 ) {
// if locator is not visible, try again
return waitForVisible( driver, elementLocator, maxIteration, iteration + 1 );
return waitForVisible(
driver,
elementLocator,
maxIteration,
iteration + 1
);
}

return element[ 0 ];
Expand All @@ -504,15 +511,19 @@ const waitForVisible = async (
* @param {number} maxIteration - Default value is 25, can be adjusted to be less to wait for element to not be visible
* @return {boolean} - Returns true if element is found, false otherwise
*/
const isElementVisible = async (
driver,
elementLocator,
maxIteration = 25
const isElementVisible = async (
driver,
elementLocator,
maxIteration = 25
) => {
const element = await waitForVisible(driver, elementLocator, maxIteration)
const element = await waitForVisible(
driver,
elementLocator,
maxIteration
);

// if there is no element, return false
if ( ! element ) {
if ( ! element ) {
return false;
}

Expand Down