diff --git a/e2e/helpers/app.js b/e2e/helpers/app.js index f2d3d0400..61dc37535 100644 --- a/e2e/helpers/app.js +++ b/e2e/helpers/app.js @@ -1,8 +1,24 @@ const { expect, element, by, waitFor } = require('detox'); +const { exec } = require('child_process'); const data = require('../data'); -const platformTypes = require('./platformTypes'); + +const platformTypes = { + android: { + // Android types + alertButtonType: 'android.widget.Button', + scrollViewType: 'android.widget.ScrollView', + textInputType: 'android.widget.EditText' + }, + ios: { + // iOS types + alertButtonType: '_UIAlertControllerActionView', + scrollViewType: 'UIScrollView', + textInputType: '_UIAlertControllerTextField' + } +}; + async function navigateToWorkspace(server = data.server) { await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(10000); @@ -145,6 +161,29 @@ const checkServer = async(server) => { await element(by.id('sidebar-close-drawer')).tap(); }; +function runCommand(command) { + return new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + reject(new Error(`exec error: ${ stderr }`)); + return; + } + resolve(); + }); + }); +} + +async function prepareAndroid() { + if (device.getPlatform() !== 'android') { + return; + } + await runCommand('adb shell settings put secure spell_checker_enabled 0'); + await runCommand('adb shell settings put secure autofill_service null'); + await runCommand('adb shell settings put global window_animation_scale 0.0'); + await runCommand('adb shell settings put global transition_animation_scale 0.0'); + await runCommand('adb shell settings put global animator_duration_scale 0.0'); +} + module.exports = { navigateToWorkspace, navigateToLogin, @@ -160,5 +199,7 @@ module.exports = { searchRoom, tryTapping, checkServer, - mockMessageWithNag + mockMessageWithNag, + platformTypes, + prepareAndroid }; diff --git a/e2e/helpers/platformFunctions.js b/e2e/helpers/platformFunctions.js deleted file mode 100644 index c84c3ef4e..000000000 --- a/e2e/helpers/platformFunctions.js +++ /dev/null @@ -1,31 +0,0 @@ -const { exec } = require('child_process'); -const { device } = require('detox'); - -function runCommand(command) { - return new Promise((resolve, reject) => { - exec(command, (error, stdout, stderr) => { - if (error) { - reject(new Error(`exec error: ${ stderr }`)); - return; - } - resolve(); - }); - }); -} - -// The Spell Checker and the autofill service introduce additional flakiness, and appear over other elements. -// So, we disable them before running the tests. -exports.prepareAndroid = async() => { - if (device.getPlatform() !== 'android') { - return; - } - await runCommand('adb shell settings put secure spell_checker_enabled 0'); - await runCommand('adb shell settings put secure autofill_service null'); - await runCommand('adb shell settings put global window_animation_scale 0.0'); - await runCommand('adb shell settings put global transition_animation_scale 0.0'); - await runCommand('adb shell settings put global animator_duration_scale 0.0'); -}; - -exports.closeKeyboardAndroid = async() => { - await device.pressBack(); // Android-only -}; diff --git a/e2e/helpers/platformTypes.js b/e2e/helpers/platformTypes.js deleted file mode 100644 index 44ffb6b65..000000000 --- a/e2e/helpers/platformTypes.js +++ /dev/null @@ -1,13 +0,0 @@ -exports.android = { - // Android types - alertButtonType: 'android.widget.Button', - scrollViewType: 'android.widget.ScrollView', - textInputType: 'android.widget.EditText' -}; - -exports.ios = { - // iOS types - alertButtonType: '_UIAlertControllerActionView', - scrollViewType: 'UIScrollView', - textInputType: '_UIAlertControllerTextField' -}; diff --git a/e2e/tests/assorted/01-e2eencryption.spec.js b/e2e/tests/assorted/01-e2eencryption.spec.js index 73e0eed92..7cf7dc748 100644 --- a/e2e/tests/assorted/01-e2eencryption.spec.js +++ b/e2e/tests/assorted/01-e2eencryption.spec.js @@ -1,9 +1,7 @@ const { - navigateToLogin, login, sleep, tapBack, mockMessage, searchRoom, logout + navigateToLogin, login, sleep, tapBack, mockMessage, searchRoom, logout, platformTypes } = require('../../helpers/app'); -const platformTypes = require('../../helpers/platformTypes'); - const data = require('../../data'); const testuser = data.users.regular; diff --git a/e2e/tests/assorted/03-profile.spec.js b/e2e/tests/assorted/03-profile.spec.js index 22c47b08f..c54e5ff12 100644 --- a/e2e/tests/assorted/03-profile.spec.js +++ b/e2e/tests/assorted/03-profile.spec.js @@ -1,8 +1,11 @@ -const { navigateToLogin, login, sleep } = require('../../helpers/app'); +const { + navigateToLogin, + login, + sleep, + platformTypes +} = require('../../helpers/app'); const data = require('../../data'); -const platformTypes = require('../../helpers/platformTypes'); - const profileChangeUser = data.users.profileChanges; const scrollDown = 200; diff --git a/e2e/tests/assorted/04-setting.spec.js b/e2e/tests/assorted/04-setting.spec.js index e80a5da26..2ebd3c275 100644 --- a/e2e/tests/assorted/04-setting.spec.js +++ b/e2e/tests/assorted/04-setting.spec.js @@ -1,6 +1,5 @@ -const { navigateToLogin, login } = require('../../helpers/app'); +const { navigateToLogin, login, platformTypes } = require('../../helpers/app'); -const platformTypes = require('../../helpers/platformTypes'); const data = require('../../data'); diff --git a/e2e/tests/assorted/05-joinpublicroom.spec.js b/e2e/tests/assorted/05-joinpublicroom.spec.js index 91964afc4..a2058fc04 100644 --- a/e2e/tests/assorted/05-joinpublicroom.spec.js +++ b/e2e/tests/assorted/05-joinpublicroom.spec.js @@ -1,10 +1,8 @@ const data = require('../../data'); const { - navigateToLogin, login, mockMessage, tapBack, searchRoom + navigateToLogin, login, mockMessage, tapBack, searchRoom, platformTypes } = require('../../helpers/app'); -const platformTypes = require('../../helpers/platformTypes'); - const testuser = data.users.regular; const room = data.channels.detoxpublic.name; diff --git a/e2e/tests/assorted/10-deleteserver.spec.js b/e2e/tests/assorted/10-deleteserver.spec.js index 345640f49..89ee59545 100644 --- a/e2e/tests/assorted/10-deleteserver.spec.js +++ b/e2e/tests/assorted/10-deleteserver.spec.js @@ -1,10 +1,8 @@ const data = require('../../data'); const { - sleep, navigateToLogin, login, checkServer + sleep, navigateToLogin, login, checkServer, platformTypes } = require('../../helpers/app'); -const platformTypes = require('../../helpers/platformTypes'); - describe('Delete server', () => { let scrollViewType; let alertButtonType; diff --git a/e2e/tests/assorted/11-deeplinking.spec.js b/e2e/tests/assorted/11-deeplinking.spec.js index 296980cde..2ff059a5a 100644 --- a/e2e/tests/assorted/11-deeplinking.spec.js +++ b/e2e/tests/assorted/11-deeplinking.spec.js @@ -1,7 +1,11 @@ const data = require('../../data'); -const { tapBack, checkServer, navigateToRegister } = require('../../helpers/app'); +const { + tapBack, + checkServer, + navigateToRegister, + platformTypes +} = require('../../helpers/app'); const { get, login } = require('../../helpers/data_setup'); -const platformTypes = require('../../helpers/platformTypes'); const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' }; diff --git a/e2e/tests/init.js b/e2e/tests/init.js index 89789d235..0ec2f4985 100644 --- a/e2e/tests/init.js +++ b/e2e/tests/init.js @@ -2,7 +2,7 @@ const detox = require('detox'); const adapter = require('detox/runners/mocha/adapter'); const config = require('../../package.json').detox; const { setup } = require('../helpers/data_setup'); -const { prepareAndroid } = require('../helpers/platformFunctions'); +const { prepareAndroid } = require('../helpers/app'); before(async() => { await Promise.all([setup(), detox.init(config, { launchApp: false })]); diff --git a/e2e/tests/room/03-roomactions.spec.js b/e2e/tests/room/03-roomactions.spec.js index 9e21b5063..708bd56be 100644 --- a/e2e/tests/room/03-roomactions.spec.js +++ b/e2e/tests/room/03-roomactions.spec.js @@ -1,11 +1,9 @@ const data = require('../../data'); const { - navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage + navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage, platformTypes } = require('../../helpers/app'); const { sendMessage } = require('../../helpers/data_setup'); -const platformTypes = require('../../helpers/platformTypes'); - async function navigateToRoomActions(type) { let room; if (type === 'd') { @@ -376,11 +374,19 @@ describe('Room actions screen', () => { const openActionSheet = async(username) => { await waitFor(element(by.id(`room-members-view-item-${ username }`))).toExist().withTimeout(5000); - await element(by.id(`room-members-view-item-${ username }`)).tap(); - await sleep(300); - await expect(element(by.id('action-sheet'))).toExist(); - await expect(element(by.id('action-sheet-handle'))).toBeVisible(); - await element(by.id('action-sheet-handle')).swipe('up'); + let n = 0; + while (n < 3) { + // Max tries three times, in case it does not register the click + try { + await element(by.id(`room-members-view-item-${ username }`)).tap(); + await waitFor(element(by.id('action-sheet'))).toExist().withTimeout(5000); + await expect(element(by.id('action-sheet-handle'))).toBeVisible(); + await element(by.id('action-sheet-handle')).swipe('up'); + return; + } catch (e) { + n += 1; + } + } }; const closeActionSheet = async() => { diff --git a/e2e/tests/room/09-jumptomessage.spec.js b/e2e/tests/room/09-jumptomessage.spec.js index a762fbd3f..77adb6381 100644 --- a/e2e/tests/room/09-jumptomessage.spec.js +++ b/e2e/tests/room/09-jumptomessage.spec.js @@ -1,8 +1,7 @@ const data = require('../../data'); const { - navigateToLogin, tapBack, login, searchRoom, sleep + navigateToLogin, tapBack, login, searchRoom, sleep, platformTypes } = require('../../helpers/app'); -const platformTypes = require('../../helpers/platformTypes'); async function navigateToRoom(roomName) { await searchRoom(`${ roomName }`);