From 5e76ce1babdeacaccca7ec7e165e0790c6d35e01 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Tue, 8 Oct 2024 19:00:02 +0530 Subject: [PATCH 1/6] init --- e2e/modules/environment.js | 6 +- .../notification_badge_in_dock.test.js | 80 ++++++++++++ .../notification_trigger.test.js | 122 ++++++++++++++++++ e2e/webpack.config.js | 2 +- 4 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 e2e/specs/notification_trigger/notification_badge_in_dock.test.js create mode 100644 e2e/specs/notification_trigger/notification_trigger.test.js diff --git a/e2e/modules/environment.js b/e2e/modules/environment.js index ab8fe22dc89..6f742911f68 100644 --- a/e2e/modules/environment.js +++ b/e2e/modules/environment.js @@ -31,7 +31,7 @@ const downloadsLocation = path.join(userDataDir, 'Downloads'); const boundsInfoPath = path.join(userDataDir, 'bounds-info.json'); const appUpdatePath = path.join(userDataDir, 'app-update.yml'); const exampleURL = 'http://example.com/'; -const mattermostURL = process.env.MM_TEST_SERVER_URL || 'http://localhost:8065/'; +const mattermostURL = 'https://mattermost-pr-28334.test.mattermost.cloud/'; // process.env.MM_TEST_SERVER_URL || 'http://localhost:8065/'; if (process.platform === 'win32') { const robot = require('robotjs'); @@ -266,8 +266,8 @@ module.exports = { await window.waitForSelector('#input_password-input'); await window.waitForSelector('#saveSetting'); - await window.type('#input_loginId', process.env.MM_TEST_USER_NAME); - await window.type('#input_password-input', process.env.MM_TEST_PASSWORD); + await window.type('#input_loginId', 'sysadmin'); + await window.type('#input_password-input', 'Sys@dmin123'); await window.click('#saveSetting'); }, diff --git a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js new file mode 100644 index 00000000000..d946a9d39fa --- /dev/null +++ b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js @@ -0,0 +1,80 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +const fs = require('fs'); + +const {expect} = require('chai'); + +const env = require('../../modules/environment'); +const {asyncSleep} = require('../../modules/utils'); + +describe('Trigger Notification From desktop', function desc() { + this.timeout(400000); + + const config = env.demoMattermostConfig; + + beforeEach(async () => { + env.cleanDataDir(); + env.createTestUserDataDir(); + env.cleanTestConfig(); + fs.writeFileSync(env.configFilePath, JSON.stringify(config)); + await asyncSleep(1000); + this.app = await env.getApp(); + this.serverMap = await env.getServerMap(this.app); + + loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); + await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); + firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win; + await env.loginToMattermost(firstServer); + const textbox = await firstServer.waitForSelector('#post_textbox'); + textbox.focus(); + }); + + env.shouldTest(it, process.platform === 'darwin')('should receive a notification on macOS', async () => { + await triggerTestNotification(); + const badgeValue = await this.app.evaluate(async ({app}) => { + return app.dock.getBadge(); + }); + badgeValue.should.equal('1'); + await verifyNotificationRecievedinDM(); + }); + env.shouldTest(it, process.platform === 'win32')('should receive a notification on Windows', async () => { + await triggerTestNotification(); + const badgeValue = await this.app.evaluate(async ({app}) => { + return app.dock.getBadge(); + }); + badgeValue.should.equal('1'); + await verifyNotificationRecievedinDM(); + + }); + env.shouldTest(it, process.platform === 'linux')('should receive a notification on Ubuntu', async () => { + await triggerTestNotification(); + const badgeValue = await this.app.evaluate(async ({app}) => { + return app.dock.getBadge(); + }); + badgeValue.should.equal('1'); + await verifyNotificationRecievedinDM(); + }); +}); + +async function triggerTestNotification() { + await firstServer.click('div#CustomizeYourExperienceTour > button'); + const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); + await sendNotificationButton.scrollIntoViewIfNeeded(); + await sendNotificationButton.click(); + await asyncSleep(1000); +} + +async function verifyNotificationRecievedinDM() { + await firstServer.click('#accountSettingsHeader > button.close'); + const sidebarLink = await firstServer.locator('a.SidebarLink:has-text("system-bot")'); + const badgeElement = await sidebarLink.locator('span.badge'); + const badgeCount = await badgeElement.textContent(); + badgeCount.should.equal('1'); + + sidebarLink.click() + await asyncSleep(1000); + + const lastPostBody = await firstServer.locator('div.post__body').last(); + const textContent = await lastPostBody.textContent(); + textContent.should.equal("app.notifications.test_message"); +} \ No newline at end of file diff --git a/e2e/specs/notification_trigger/notification_trigger.test.js b/e2e/specs/notification_trigger/notification_trigger.test.js new file mode 100644 index 00000000000..e8e56f8b887 --- /dev/null +++ b/e2e/specs/notification_trigger/notification_trigger.test.js @@ -0,0 +1,122 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +const fs = require('fs'); + +const {expect} = require('chai'); + +const env = require('../../modules/environment'); +const {asyncSleep} = require('../../modules/utils'); + +describe('Trigger Notification From desktop', function desc() { + this.timeout(400000); + + const config = env.demoMattermostConfig; + + beforeEach(async () => { + env.cleanDataDir(); + env.createTestUserDataDir(); + env.cleanTestConfig(); + fs.writeFileSync(env.configFilePath, JSON.stringify(config)); + await asyncSleep(1000); + this.app = await env.getApp(); + this.serverMap = await env.getServerMap(this.app); + + loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); + await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); + firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win; + await env.loginToMattermost(firstServer); + const textbox = await firstServer.waitForSelector('#post_textbox'); + textbox.focus(); + }); + + env.shouldTest(it, process.platform === 'darwin')('should receive a notification on macOS', async () => { + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + const browserWindow = await this.app.browserWindow(mainWindow); + + const permissionStatus = await browserWindow.evaluate(() => Notification.permission); + expect(permissionStatus).toBe('granted'); + + await firstServer.click('div#CustomizeYourExperienceTour > button'); + + const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); + await sendNotificationButton.scrollIntoViewIfNeeded(); + await sendNotificationButton.click(); + + await asyncSleep(100000); + + const notification = await getNotification(); + + // Verify the notification content + expect(notification).toBeTruthy(); + expect(notification.title).toBe('Expected Notification Title'); + expect(notification.body).toContain('Expected notification content'); + }); + + env.shouldTest(it, process.platform === 'win32')('should receive a notification on Windows', async () => { + await firstServer.click('div#CustomizeYourExperienceTour > button'); + const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); + await sendNotificationButton.scrollIntoViewIfNeeded(); + await sendNotificationButton.click(); + await asyncSleep(100000); + + const notificationReceived = await this.app.evaluate(async () => { + + }); + + if (!notificationReceived) { + throw new Error('Notification was not received on Windows.'); + } + }); + env.shouldTest(it, process.platform === 'linux')('should receive a notification on Ubuntu', async () => { + await firstServer.click('div#CustomizeYourExperienceTour > button'); + const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); + await sendNotificationButton.scrollIntoViewIfNeeded(); + await sendNotificationButton.click(); + await asyncSleep(1000); + + const notificationReceived = await this.app.evaluate(async () => { + + }); + + if (!notificationReceived) { + throw new Error('Notification was not received on Ubuntu.'); + } + }); +}); + +async function getNotification() { + if (process.platform === 'darwin') { + return getMacOSNotification(); + } else if (process.platform === 'win32') { + return getWindowsNotification(); + } else if (process.platform === 'linux') { + return getLinuxNotification(); + } + throw new Error('Unsupported operating system'); +} + +async function getMacOSNotification() { + const script = ` + tell application "System Events" + set notificationCenter to application process "NotificationCenter" + set notifications to every UI element of notificationCenter + if (count of notifications) > 0 then + set latestNotification to item 1 of notifications + set notificationTitle to name of latestNotification + set notificationBody to value of static text 2 of latestNotification + return notificationTitle & "|" & notificationBody + else + return "No notifications" + end if + end tell + `; + + try { + const result = execSync(`osascript -e '${script}'`, {encoding: 'utf8'}); + const [title, body] = result.trim().split('|'); + return {title, body}; + } catch (error) { + console.error('Error retrieving macOS notification:', error); + return null; + } +} diff --git a/e2e/webpack.config.js b/e2e/webpack.config.js index 75cb32bc415..d6f7b9aa755 100644 --- a/e2e/webpack.config.js +++ b/e2e/webpack.config.js @@ -9,7 +9,7 @@ const webpack = require('webpack'); module.exports = { mode: 'development', entry: { - e2e: glob.sync('./specs/**/*.js'), + e2e: glob.sync('./specs/**/notification_trigger.test.js'), }, output: { path: path.resolve(__dirname, 'dist/'), From 2759c142e4364bc97b0cd18ce9aba3a28c7bc4c9 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Tue, 8 Oct 2024 19:40:18 +0530 Subject: [PATCH 2/6] only run badge check notif test --- e2e/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/webpack.config.js b/e2e/webpack.config.js index d6f7b9aa755..fb9fe3fc66e 100644 --- a/e2e/webpack.config.js +++ b/e2e/webpack.config.js @@ -9,7 +9,7 @@ const webpack = require('webpack'); module.exports = { mode: 'development', entry: { - e2e: glob.sync('./specs/**/notification_trigger.test.js'), + e2e: glob.sync('./specs/**/notification_badge_in_dock.test.js'), }, output: { path: path.resolve(__dirname, 'dist/'), From 37ccff3549c038577ded76f42761014cbb4ca009 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Tue, 8 Oct 2024 20:03:55 +0530 Subject: [PATCH 3/6] update test steps --- .../notification_badge_in_dock.test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js index d946a9d39fa..2e7efafca1b 100644 --- a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js +++ b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js @@ -58,10 +58,14 @@ describe('Trigger Notification From desktop', function desc() { async function triggerTestNotification() { await firstServer.click('div#CustomizeYourExperienceTour > button'); - const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); + const sendNotificationButton = await firstServer.waitForSelector('.sectionNoticeButton.btn-primary'); await sendNotificationButton.scrollIntoViewIfNeeded(); + const textBeforeClick = await sendNotificationButton.textContent(); + textBeforeClick.should.equal('Send a test notification'); await sendNotificationButton.click(); - await asyncSleep(1000); + await asyncSleep(2000); + const textAfterClick = await sendNotificationButton.textContent(); + textAfterClick.should.equal('Error sending test notification'); } async function verifyNotificationRecievedinDM() { @@ -76,5 +80,5 @@ async function verifyNotificationRecievedinDM() { const lastPostBody = await firstServer.locator('div.post__body').last(); const textContent = await lastPostBody.textContent(); - textContent.should.equal("app.notifications.test_message"); + textContent.should.equal("If you received this test notification, it worked!"); } \ No newline at end of file From 831ad45a12d11f975c65cb6ef746af3416598733 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 13 Oct 2024 11:35:24 +0530 Subject: [PATCH 4/6] test linux --- .github/workflows/e2e-functional-template.yml | 2 +- .../notification_badge_in_dock.test.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-functional-template.yml b/.github/workflows/e2e-functional-template.yml index c1aa25b7aff..e4d1154b082 100644 --- a/.github/workflows/e2e-functional-template.yml +++ b/.github/workflows/e2e-functional-template.yml @@ -167,7 +167,7 @@ jobs: ## Windows Dependencies - name: e2e/install-dependencies-windows - if: steps.cache-node-modules.outputs.cache-hit != 'true' && runner.os == 'Windows' + if: steps.cache-node-modules.outputs.cache-hit != 'true' && runner.os == 'windows' env: PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 run: | diff --git a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js index 2e7efafca1b..7bf5aef507e 100644 --- a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js +++ b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js @@ -40,16 +40,15 @@ describe('Trigger Notification From desktop', function desc() { env.shouldTest(it, process.platform === 'win32')('should receive a notification on Windows', async () => { await triggerTestNotification(); const badgeValue = await this.app.evaluate(async ({app}) => { - return app.dock.getBadge(); + return app.getBadge(); }); badgeValue.should.equal('1'); await verifyNotificationRecievedinDM(); - }); env.shouldTest(it, process.platform === 'linux')('should receive a notification on Ubuntu', async () => { await triggerTestNotification(); const badgeValue = await this.app.evaluate(async ({app}) => { - return app.dock.getBadge(); + return app.getBadgeCount(); }); badgeValue.should.equal('1'); await verifyNotificationRecievedinDM(); @@ -63,9 +62,9 @@ async function triggerTestNotification() { const textBeforeClick = await sendNotificationButton.textContent(); textBeforeClick.should.equal('Send a test notification'); await sendNotificationButton.click(); - await asyncSleep(2000); + await asyncSleep(3000); const textAfterClick = await sendNotificationButton.textContent(); - textAfterClick.should.equal('Error sending test notification'); + textAfterClick.should.equal('Test notification sent'); } async function verifyNotificationRecievedinDM() { From ee013e1f856d1c26ce38073255a7e2395d071314 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 13 Oct 2024 11:46:47 +0530 Subject: [PATCH 5/6] fix windows e2e desktop --- .github/workflows/e2e-functional-template.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-functional-template.yml b/.github/workflows/e2e-functional-template.yml index e4d1154b082..de8ae30c583 100644 --- a/.github/workflows/e2e-functional-template.yml +++ b/.github/workflows/e2e-functional-template.yml @@ -167,7 +167,7 @@ jobs: ## Windows Dependencies - name: e2e/install-dependencies-windows - if: steps.cache-node-modules.outputs.cache-hit != 'true' && runner.os == 'windows' + if: runner.os == 'windows' env: PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 run: | @@ -180,6 +180,7 @@ jobs: cd e2e npm ci npx electron-rebuild --platform=win32 -f -t prod,optional,dev -w robotjs --module-dir ../ + npm install mochawesome-report-generator - name: e2e/run-playright-tests-${{ runner.os }} run: | From c9891279b55c0f241d16fbe0a6d8f13186938cc5 Mon Sep 17 00:00:00 2001 From: yasserfaraazkhan Date: Sun, 13 Oct 2024 19:36:09 +0530 Subject: [PATCH 6/6] add test for mac --- e2e/specs/notification_trigger/helpers.js | 28 ++++ .../notification_badge_in_dock.test.js | 57 ++------ .../notification_trigger.test.js | 122 ------------------ e2e/webpack.config.js | 2 +- 4 files changed, 37 insertions(+), 172 deletions(-) create mode 100644 e2e/specs/notification_trigger/helpers.js delete mode 100644 e2e/specs/notification_trigger/notification_trigger.test.js diff --git a/e2e/specs/notification_trigger/helpers.js b/e2e/specs/notification_trigger/helpers.js new file mode 100644 index 00000000000..865222d788e --- /dev/null +++ b/e2e/specs/notification_trigger/helpers.js @@ -0,0 +1,28 @@ +const {asyncSleep} = require('../../modules/utils'); + +export async function triggerTestNotification(firstServer) { + await firstServer.click('div#CustomizeYourExperienceTour > button'); + const sendNotificationButton = await firstServer.waitForSelector('.sectionNoticeButton.btn-primary'); + await sendNotificationButton.scrollIntoViewIfNeeded(); + const textBeforeClick = await sendNotificationButton.textContent(); + textBeforeClick.should.equal('Send a test notification'); + await sendNotificationButton.click(); + await asyncSleep(3000); + const textAfterClick = await sendNotificationButton.textContent(); + textAfterClick.should.equal('Test notification sent'); +} + +export async function verifyNotificationRecievedinDM(firstServer) { + await firstServer.click('#accountSettingsHeader > button.close'); + const sidebarLink = await firstServer.locator('a.SidebarLink:has-text("system-bot")'); + const badgeElement = await sidebarLink.locator('span.badge'); + const badgeCount = await badgeElement.textContent(); + badgeCount.should.equal('1'); + + sidebarLink.click() + await asyncSleep(1000); + + const lastPostBody = await firstServer.locator('div.post__body').last(); + const textContent = await lastPostBody.textContent(); + textContent.should.equal("If you received this test notification, it worked!"); +} diff --git a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js index 7bf5aef507e..b96e2106cfa 100644 --- a/e2e/specs/notification_trigger/notification_badge_in_dock.test.js +++ b/e2e/specs/notification_trigger/notification_badge_in_dock.test.js @@ -1,16 +1,17 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -const fs = require('fs'); - -const {expect} = require('chai'); +import {triggerTestNotification, verifyNotificationRecievedinDM} from './helpers'; +const fs = require('fs'); const env = require('../../modules/environment'); const {asyncSleep} = require('../../modules/utils'); + describe('Trigger Notification From desktop', function desc() { this.timeout(400000); const config = env.demoMattermostConfig; + let firstServer; beforeEach(async () => { env.cleanDataDir(); @@ -21,7 +22,7 @@ describe('Trigger Notification From desktop', function desc() { this.app = await env.getApp(); this.serverMap = await env.getServerMap(this.app); - loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); + const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win; await env.loginToMattermost(firstServer); @@ -29,55 +30,13 @@ describe('Trigger Notification From desktop', function desc() { textbox.focus(); }); + // This support to getBadge is only available for MacOS env.shouldTest(it, process.platform === 'darwin')('should receive a notification on macOS', async () => { - await triggerTestNotification(); + await triggerTestNotification(firstServer); const badgeValue = await this.app.evaluate(async ({app}) => { return app.dock.getBadge(); }); badgeValue.should.equal('1'); - await verifyNotificationRecievedinDM(); - }); - env.shouldTest(it, process.platform === 'win32')('should receive a notification on Windows', async () => { - await triggerTestNotification(); - const badgeValue = await this.app.evaluate(async ({app}) => { - return app.getBadge(); - }); - badgeValue.should.equal('1'); - await verifyNotificationRecievedinDM(); - }); - env.shouldTest(it, process.platform === 'linux')('should receive a notification on Ubuntu', async () => { - await triggerTestNotification(); - const badgeValue = await this.app.evaluate(async ({app}) => { - return app.getBadgeCount(); - }); - badgeValue.should.equal('1'); - await verifyNotificationRecievedinDM(); + await verifyNotificationRecievedinDM(firstServer); }); }); - -async function triggerTestNotification() { - await firstServer.click('div#CustomizeYourExperienceTour > button'); - const sendNotificationButton = await firstServer.waitForSelector('.sectionNoticeButton.btn-primary'); - await sendNotificationButton.scrollIntoViewIfNeeded(); - const textBeforeClick = await sendNotificationButton.textContent(); - textBeforeClick.should.equal('Send a test notification'); - await sendNotificationButton.click(); - await asyncSleep(3000); - const textAfterClick = await sendNotificationButton.textContent(); - textAfterClick.should.equal('Test notification sent'); -} - -async function verifyNotificationRecievedinDM() { - await firstServer.click('#accountSettingsHeader > button.close'); - const sidebarLink = await firstServer.locator('a.SidebarLink:has-text("system-bot")'); - const badgeElement = await sidebarLink.locator('span.badge'); - const badgeCount = await badgeElement.textContent(); - badgeCount.should.equal('1'); - - sidebarLink.click() - await asyncSleep(1000); - - const lastPostBody = await firstServer.locator('div.post__body').last(); - const textContent = await lastPostBody.textContent(); - textContent.should.equal("If you received this test notification, it worked!"); -} \ No newline at end of file diff --git a/e2e/specs/notification_trigger/notification_trigger.test.js b/e2e/specs/notification_trigger/notification_trigger.test.js deleted file mode 100644 index e8e56f8b887..00000000000 --- a/e2e/specs/notification_trigger/notification_trigger.test.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. -const fs = require('fs'); - -const {expect} = require('chai'); - -const env = require('../../modules/environment'); -const {asyncSleep} = require('../../modules/utils'); - -describe('Trigger Notification From desktop', function desc() { - this.timeout(400000); - - const config = env.demoMattermostConfig; - - beforeEach(async () => { - env.cleanDataDir(); - env.createTestUserDataDir(); - env.cleanTestConfig(); - fs.writeFileSync(env.configFilePath, JSON.stringify(config)); - await asyncSleep(1000); - this.app = await env.getApp(); - this.serverMap = await env.getServerMap(this.app); - - loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); - await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); - firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win; - await env.loginToMattermost(firstServer); - const textbox = await firstServer.waitForSelector('#post_textbox'); - textbox.focus(); - }); - - env.shouldTest(it, process.platform === 'darwin')('should receive a notification on macOS', async () => { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - const browserWindow = await this.app.browserWindow(mainWindow); - - const permissionStatus = await browserWindow.evaluate(() => Notification.permission); - expect(permissionStatus).toBe('granted'); - - await firstServer.click('div#CustomizeYourExperienceTour > button'); - - const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); - await sendNotificationButton.scrollIntoViewIfNeeded(); - await sendNotificationButton.click(); - - await asyncSleep(100000); - - const notification = await getNotification(); - - // Verify the notification content - expect(notification).toBeTruthy(); - expect(notification.title).toBe('Expected Notification Title'); - expect(notification.body).toContain('Expected notification content'); - }); - - env.shouldTest(it, process.platform === 'win32')('should receive a notification on Windows', async () => { - await firstServer.click('div#CustomizeYourExperienceTour > button'); - const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); - await sendNotificationButton.scrollIntoViewIfNeeded(); - await sendNotificationButton.click(); - await asyncSleep(100000); - - const notificationReceived = await this.app.evaluate(async () => { - - }); - - if (!notificationReceived) { - throw new Error('Notification was not received on Windows.'); - } - }); - env.shouldTest(it, process.platform === 'linux')('should receive a notification on Ubuntu', async () => { - await firstServer.click('div#CustomizeYourExperienceTour > button'); - const sendNotificationButton = await firstServer.waitForSelector('.btn-primary'); - await sendNotificationButton.scrollIntoViewIfNeeded(); - await sendNotificationButton.click(); - await asyncSleep(1000); - - const notificationReceived = await this.app.evaluate(async () => { - - }); - - if (!notificationReceived) { - throw new Error('Notification was not received on Ubuntu.'); - } - }); -}); - -async function getNotification() { - if (process.platform === 'darwin') { - return getMacOSNotification(); - } else if (process.platform === 'win32') { - return getWindowsNotification(); - } else if (process.platform === 'linux') { - return getLinuxNotification(); - } - throw new Error('Unsupported operating system'); -} - -async function getMacOSNotification() { - const script = ` - tell application "System Events" - set notificationCenter to application process "NotificationCenter" - set notifications to every UI element of notificationCenter - if (count of notifications) > 0 then - set latestNotification to item 1 of notifications - set notificationTitle to name of latestNotification - set notificationBody to value of static text 2 of latestNotification - return notificationTitle & "|" & notificationBody - else - return "No notifications" - end if - end tell - `; - - try { - const result = execSync(`osascript -e '${script}'`, {encoding: 'utf8'}); - const [title, body] = result.trim().split('|'); - return {title, body}; - } catch (error) { - console.error('Error retrieving macOS notification:', error); - return null; - } -} diff --git a/e2e/webpack.config.js b/e2e/webpack.config.js index fb9fe3fc66e..fb2b8b7f8a4 100644 --- a/e2e/webpack.config.js +++ b/e2e/webpack.config.js @@ -9,7 +9,7 @@ const webpack = require('webpack'); module.exports = { mode: 'development', entry: { - e2e: glob.sync('./specs/**/notification_badge_in_dock.test.js'), + e2e: glob.sync('./specs/**/notification_tri*.test.js'), }, output: { path: path.resolve(__dirname, 'dist/'),