From ec22d9446ad49747e01fcf97533dff3ee5b419df Mon Sep 17 00:00:00 2001 From: Anant Bhasin Date: Fri, 4 Jun 2021 16:38:12 +0530 Subject: [PATCH] platform dependent component types --- e2e/helpers/app.js | 9 +++++++-- e2e/helpers/platformTypes.js | 8 ++++---- e2e/tests/assorted/01-e2eencryption.spec.js | 16 +++++++++++----- e2e/tests/assorted/03-profile.spec.js | 11 ++++++++--- e2e/tests/assorted/04-setting.spec.js | 5 ++++- e2e/tests/assorted/05-joinpublicroom.spec.js | 7 +++++-- e2e/tests/assorted/10-deleteserver.spec.js | 8 ++++++-- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/e2e/helpers/app.js b/e2e/helpers/app.js index bfeae8d4d..7f7999c0a 100644 --- a/e2e/helpers/app.js +++ b/e2e/helpers/app.js @@ -2,6 +2,7 @@ const { device, expect, element, by, waitFor } = require('detox'); const data = require('../data'); +const platformTypes = require('./platformTypes'); async function navigateToWorkspace(server = data.server) { await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(10000); @@ -36,12 +37,14 @@ async function login(username, password) { } async function logout() { + const deviceType = device.getPlatform(); + const scrollViewType = platformTypes[deviceType].scrollViewType; await element(by.id('rooms-list-view-sidebar')).tap(); await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000); await waitFor(element(by.id('sidebar-settings'))).toBeVisible().withTimeout(2000); await element(by.id('sidebar-settings')).tap(); await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000); - await element(by.type('android.widget.ScrollView')).atIndex(1).scrollTo('bottom'); + await element(by.type(scrollViewType)).atIndex(1).scrollTo('bottom'); await element(by.id('settings-logout')).tap(); const logoutAlertMessage = 'You will be logged out of this application.'; await waitFor(element(by.text(logoutAlertMessage)).atIndex(0)).toExist().withTimeout(10000); @@ -83,8 +86,10 @@ async function pinMessage(message){ } async function dismissReviewNag(){ + const deviceType = device.getPlatform(); + const alertButtonType = platformTypes[deviceType].alertButtonType; await waitFor(element(by.text('Are you enjoying this app?'))).toExist().withTimeout(60000); - await element(by.text('No').and(by.type('android.widget.Button'))).tap(); // Tap `no` on ask for review alert + await element(by.text('No').and(by.type(alertButtonType))).tap(); // Tap `no` on ask for review alert } async function tapBack() { diff --git a/e2e/helpers/platformTypes.js b/e2e/helpers/platformTypes.js index af95e29d4..5a241843d 100644 --- a/e2e/helpers/platformTypes.js +++ b/e2e/helpers/platformTypes.js @@ -1,11 +1,11 @@ -const { device } = require('detox'); - -export default device.getPlatform() === 'android' ? { +exports.android = { //Android types alertButtonType: 'android.widget.Button', scrollViewType: 'android.widget.ScrollView', textInputType: 'android.widget.EditText', -} : { +}; + +exports.ios = { //iOS types alertButtonType: '_UIAlertControllerActionView', scrollViewType: 'UIScrollView', diff --git a/e2e/tests/assorted/01-e2eencryption.spec.js b/e2e/tests/assorted/01-e2eencryption.spec.js index c827661b4..ff7d060cb 100644 --- a/e2e/tests/assorted/01-e2eencryption.spec.js +++ b/e2e/tests/assorted/01-e2eencryption.spec.js @@ -3,6 +3,8 @@ const { } = require('detox'); const { navigateToLogin, login, sleep, tapBack, mockMessage, searchRoom, logout } = require('../../helpers/app'); +const platformTypes = require('../../helpers/platformTypes'); + const data = require('../../data'); const testuser = data.users.regular @@ -44,9 +46,13 @@ async function navigateSecurityPrivacy() { describe('E2E Encryption', () => { const room = `encrypted${ data.random }`; const newPassword = 'abc'; + let alertButtonType, scrollViewType; before(async () => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); + const deviceType = device.getPlatform(); + alertButtonType = platformTypes[deviceType].alertButtonType; + scrollViewType = platformTypes[deviceType].scrollViewType; await navigateToLogin(); await login(testuser.username, testuser.password); }); @@ -141,7 +147,7 @@ describe('E2E Encryption', () => { await element(by.id('e2e-encryption-security-view-change-password')).tap(); await waitFor(element(by.text('Are you sure?'))).toExist().withTimeout(2000); await expect(element(by.text('Make sure you\'ve saved it carefully somewhere else.'))).toExist(); - await element(by.text('Yes, change it').and(by.type('android.widget.Button'))).tap(); + await element(by.text('Yes, change it').and(by.type(alertButtonType))).tap(); await waitForToast(); }); @@ -194,10 +200,10 @@ describe('E2E Encryption', () => { await element(by.id('e2e-encryption-security-view-reset-key').and(by.label('Reset E2E Key'))).tap(); await waitFor(element(by.text('Are you sure?'))).toExist().withTimeout(2000); await expect(element(by.text('You\'re going to be logged out.'))).toExist(); - await element(by.text('Yes, reset it').and(by.type('android.widget.Button'))).tap(); + await element(by.text('Yes, reset it').and(by.type(alertButtonType))).tap(); await sleep(2000) - await waitFor(element(by.text('OK').and(by.type('android.widget.Button')))).toExist().withTimeout(2000); - await element(by.text('OK').and(by.type('android.widget.Button'))).tap(); + await waitFor(element(by.text('OK').and(by.type(alertButtonType)))).toExist().withTimeout(2000); + await element(by.text('OK').and(by.type(alertButtonType))).tap(); await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(10000); await element(by.id('workspace-view-login')).tap(); await waitFor(element(by.id('login-view'))).toBeVisible().withTimeout(2000); @@ -231,7 +237,7 @@ describe('E2E Encryption', () => { await element(by.id('register-view-username')).replaceText(data.registeringUser.username); await element(by.id('register-view-email')).replaceText(data.registeringUser.email); await element(by.id('register-view-password')).typeText(data.registeringUser.password); - element(by.type('android.widget.ScrollView')).atIndex(1).scrollTo('bottom'); + element(by.type(scrollViewType)).atIndex(1).scrollTo('bottom'); await element(by.id('register-view-submit')).tap(); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); diff --git a/e2e/tests/assorted/03-profile.spec.js b/e2e/tests/assorted/03-profile.spec.js index 2d8e40c17..0e947b346 100644 --- a/e2e/tests/assorted/03-profile.spec.js +++ b/e2e/tests/assorted/03-profile.spec.js @@ -17,8 +17,13 @@ async function waitForToast() { } describe('Profile screen', () => { + let textInputType, scrollViewType; + before(async() => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); + const deviceType = device.getPlatform(); + textInputType = platformTypes[deviceType].textInputType; + scrollViewType = platformTypes[deviceType].scrollViewType; await navigateToLogin(); await login(profileChangeUser.username, profileChangeUser.password); await element(by.id('rooms-list-view-sidebar')).tap(); @@ -79,7 +84,7 @@ describe('Profile screen', () => { await element(by.id('profile-view-name')).replaceText(`${ profileChangeUser.username }new`); await element(by.id('profile-view-username')).typeText(`${ profileChangeUser.username }new`); await device.pressBack(); - await element(by.type('android.widget.ScrollView')).atIndex(1).swipe('up'); + await element(by.type(scrollViewType)).atIndex(1).swipe('up'); await element(by.id('profile-view-submit')).tap(); await waitForToast(); }); @@ -88,13 +93,13 @@ describe('Profile screen', () => { await element(by.id('profile-view-email')).replaceText(`mobile+profileChangesNew${ data.random }@rocket.chat`); await element(by.id('profile-view-new-password')).replaceText(`${ profileChangeUser.password }new`); await element(by.id('profile-view-submit')).tap(); - await element(by.type('android.widget.EditText')).typeText(`${ profileChangeUser.password }\n`); + await element(by.type(textInputType)).typeText(`${ profileChangeUser.password }\n`); await element(by.text('SAVE')).tap(); await waitForToast(); }); it('should reset avatar', async() => { - await element(by.type('android.widget.ScrollView')).atIndex(1).swipe('up'); + await element(by.type(scrollViewType)).atIndex(1).swipe('up'); await element(by.id('profile-view-reset-avatar')).tap(); await waitForToast(); }); diff --git a/e2e/tests/assorted/04-setting.spec.js b/e2e/tests/assorted/04-setting.spec.js index 966c86314..dc848d3c3 100644 --- a/e2e/tests/assorted/04-setting.spec.js +++ b/e2e/tests/assorted/04-setting.spec.js @@ -8,8 +8,11 @@ const data = require('../../data'); const testuser = data.users.regular describe('Settings screen', () => { + let alertButtonType; before(async() => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); + const deviceType = device.getPlatform(); + alertButtonType = platformTypes[deviceType].alertButtonType; await navigateToLogin(); await login(testuser.username, testuser.password); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000); @@ -67,7 +70,7 @@ describe('Settings screen', () => { await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000); await element(by.id('settings-view-clear-cache')).tap(); await waitFor(element(by.text('This will clear all your offline data.'))).toExist().withTimeout(2000); - await element(by.text('Clear').and(by.type('android.widget.Button'))).tap(); + await element(by.text('Clear').and(by.type(alertButtonType))).tap(); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(5000); await waitFor(element(by.id(`rooms-list-view-item-${ data.groups.private.name }`))).toExist().withTimeout(10000); }) diff --git a/e2e/tests/assorted/05-joinpublicroom.spec.js b/e2e/tests/assorted/05-joinpublicroom.spec.js index 9e4319c0d..a804a18ec 100644 --- a/e2e/tests/assorted/05-joinpublicroom.spec.js +++ b/e2e/tests/assorted/05-joinpublicroom.spec.js @@ -19,8 +19,11 @@ async function navigateToRoomActions() { } describe('Join public room', () => { + let scrollViewType; before(async() => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); + const deviceType = device.getPlatform(); + scrollViewType = platformTypes[deviceType].scrollViewType; await navigateToLogin(); await login(testuser.username, testuser.password); await navigateToRoom(); @@ -151,11 +154,11 @@ describe('Join public room', () => { await expect(element(by.id('room-actions-mentioned'))).toBeVisible(); await expect(element(by.id('room-actions-starred'))).toBeVisible(); // await expect(element(by.id('room-actions-search'))).toBeVisible(); - await element(by.type('android.widget.ScrollView')).atIndex(1).swipe('down'); + await element(by.type(scrollViewType)).atIndex(1).swipe('down'); await expect(element(by.id('room-actions-share'))).toBeVisible(); await expect(element(by.id('room-actions-pinned'))).toBeVisible(); await expect(element(by.id('room-actions-notifications'))).toBeVisible(); - await element(by.type('android.widget.ScrollView')).atIndex(0).swipe('up'); + await element(by.type(scrollViewType)).atIndex(0).swipe('up'); await expect(element(by.id('room-actions-leave-channel'))).toBeVisible(); }); diff --git a/e2e/tests/assorted/10-deleteserver.spec.js b/e2e/tests/assorted/10-deleteserver.spec.js index 75023fc90..16db10c7a 100644 --- a/e2e/tests/assorted/10-deleteserver.spec.js +++ b/e2e/tests/assorted/10-deleteserver.spec.js @@ -5,8 +5,12 @@ const data = require('../../data'); const { sleep, navigateToLogin, login, checkServer } = require('../../helpers/app'); describe('Delete server', () => { + let scrollViewType, alertButtonType; before(async() => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); + const deviceType = device.getPlatform(); + alertButtonType = platformTypes[deviceType].alertButtonType; + scrollViewType = platformTypes[deviceType].scrollViewType; await navigateToLogin(); await login(data.users.regular.username, data.users.regular.password); }); @@ -32,7 +36,7 @@ describe('Delete server', () => { await element(by.id('register-view-username')).replaceText(data.registeringUser3.username); await element(by.id('register-view-email')).replaceText(data.registeringUser3.email); await element(by.id('register-view-password')).typeText(data.registeringUser3.password); - await element(by.type('android.widget.ScrollView')).atIndex(0).swipe('up'); + await element(by.type(scrollViewType)).atIndex(0).swipe('up'); await element(by.id('register-view-submit')).tap(); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); @@ -43,7 +47,7 @@ describe('Delete server', () => { await element(by.id('rooms-list-header-server-dropdown-button')).tap(); await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000); await element(by.id(`rooms-list-header-server-${ data.server }`)).longPress(1500); - await element(by.text('Delete').and(by.type('android.widget.Button'))).tap(); + await element(by.text('Delete').and(by.type(alertButtonType))).tap(); await element(by.id('rooms-list-header-server-dropdown-button')).tap(); await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000); await waitFor(element(by.id(`rooms-list-header-server-${ data.server }`))).toBeNotVisible().withTimeout(10000);