Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(tests) adds e2e tests for virtual background dialog

Jaya Allamsetty41ba851275ad
diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.ts
index 61eb888b7a..f34909e018 100644
--- a/tests/helpers/Participant.ts
+++ b/tests/helpers/Participant.ts
@@ -26,6 +26,7 @@ import SecurityDialog from '../pageobjects/SecurityDialog';
import SettingsDialog from '../pageobjects/SettingsDialog';
import Toolbar from '../pageobjects/Toolbar';
import VideoQualityDialog from '../pageobjects/VideoQualityDialog';
+import VirtualBackgroundDialog from '../pageobjects/VirtualBackgroundDialog';
import Visitors from '../pageobjects/Visitors';
import { LOG_PREFIX, logInfo } from './browserLogger';
@@ -637,6 +638,13 @@ export class Participant {
return new PasswordDialog(this);
}
+ /**
+ * Returns the virtual background dialog.
+ */
+ getVirtualBackgroundDialog(): VirtualBackgroundDialog {
+ return new VirtualBackgroundDialog(this);
+ }
+
/**
* Returns the prejoin screen.
*/
diff --git a/tests/pageobjects/Toolbar.ts b/tests/pageobjects/Toolbar.ts
index 39cdad2549..2162c3d9ee 100644
--- a/tests/pageobjects/Toolbar.ts
+++ b/tests/pageobjects/Toolbar.ts
@@ -18,6 +18,7 @@ const STOP_DESKTOP = 'Stop sharing your screen';
const ENTER_TILE_VIEW_BUTTON = 'Enter tile view';
const EXIT_TILE_VIEW_BUTTON = 'Exit tile view';
const VIDEO_QUALITY = 'Manage video quality';
+const VIRTUAL_BACKGROUND = 'Select Background';
const VIDEO_MUTE = 'Stop camera';
const VIDEO_UNMUTE = 'Start camera';
@@ -245,6 +246,13 @@ export default class Toolbar extends BasePageObject {
return this.clickButtonInOverflowMenu(SETTINGS);
}
+ /**
+ * Clicks on the virtual background toolbar button which opens the virtual background settings.
+ */
+ clickVirtualBackgroundButton() {
+ return this.clickButtonInOverflowMenu(VIRTUAL_BACKGROUND);
+ }
+
/**
* Ensure the overflow menu is open and clicks on a specified button.
* @param accessibilityLabel The accessibility label of the button to be clicked.
diff --git a/tests/pageobjects/VirtualBackgroundDialog.ts b/tests/pageobjects/VirtualBackgroundDialog.ts
new file mode 100644
index 0000000000..fe677ae64d
--- /dev/null
+++ b/tests/pageobjects/VirtualBackgroundDialog.ts
@@ -0,0 +1,109 @@
+import BaseDialog from './BaseDialog';
+
+const VB_DIALOG_CONTAINER = '#virtual-background-dialog';
+const NONE_THUMBNAIL = '[aria-label="Remove background"]';
+const SLIGHT_BLUR_THUMBNAIL = '[aria-label="Half Blur"]';
+const BLUR_THUMBNAIL = '[aria-label="Blur"]';
+
+/**
+ * Page object for the Virtual Background tab inside the settings dialog.
+ */
+export default class VirtualBackgroundDialog extends BaseDialog {
+ /**
+ * Waits for the virtual background dialog container to be displayed.
+ */
+ async waitForDisplay(): Promise<void> {
+ await this.participant.driver.$(VB_DIALOG_CONTAINER).waitForDisplayed({
+ timeout: 5000,
+ timeoutMsg: 'Virtual background dialog not displayed'
+ });
+ }
+
+ /**
+ * Returns true if the dialog container is currently displayed.
+ */
+ isDisplayed(): Promise<boolean> {
+ return this.participant.driver.$(VB_DIALOG_CONTAINER).isDisplayed();
+ }
+
+ /**
+ * Clicks the "Remove background" (None) thumbnail.
+ */
+ async clickNone(): Promise<void> {
+ await this.participant.log('VirtualBackgroundDialog: clicking None thumbnail');
+ const el = this.participant.driver.$(NONE_THUMBNAIL);
+
+ await el.waitForClickable({ timeout: 3000, timeoutMsg: 'None thumbnail not clickable' });
+ await el.click();
+ }
+
+ /**
+ * Clicks the "Half Blur" (slight blur) thumbnail.
+ */
+ async clickSlightBlur(): Promise<void> {
+ await this.participant.log('VirtualBackgroundDialog: clicking Slight Blur thumbnail');
+ const el = this.participant.driver.$(SLIGHT_BLUR_THUMBNAIL);
+
+ await el.waitForClickable({ timeout: 3000, timeoutMsg: 'Slight Blur thumbnail not clickable' });
+ await el.click();
+ }
+
+ /**
+ * Clicks the "Blur" (full blur) thumbnail.
+ */
+ async clickBlur(): Promise<void> {
+ await this.participant.log('VirtualBackgroundDialog: clicking Blur thumbnail');
+ const el = this.participant.driver.$(BLUR_THUMBNAIL);
+
+ await el.waitForClickable({ timeout: 3000, timeoutMsg: 'Blur thumbnail not clickable' });
+ await el.click();
+ }
+
+ /**
+ * Returns true if the given thumbnail element has aria-checked="true" (selected in the dialog).
+ *
+ * @param {string} selector - CSS selector for the thumbnail element.
+ */
+ async isThumbnailChecked(selector: string): Promise<boolean> {
+ const el = this.participant.driver.$(selector);
+
+ await el.waitForExist({ timeout: 2000 });
+
+ return (await el.getAttribute('aria-checked')) === 'true';
+ }
+
+ /**
+ * Returns true if the None thumbnail is currently selected in the dialog.
+ */
+ isNoneChecked(): Promise<boolean> {
+ return this.isThumbnailChecked(NONE_THUMBNAIL);
+ }
+
+ /**
+ * Returns true if the Slight Blur thumbnail is currently selected in the dialog.
+ */
+ isSlightBlurChecked(): Promise<boolean> {
+ return this.isThumbnailChecked(SLIGHT_BLUR_THUMBNAIL);
+ }
+
+ /**
+ * Returns true if the Blur thumbnail is currently selected in the dialog.
+ */
+ isBlurChecked(): Promise<boolean> {
+ return this.isThumbnailChecked(BLUR_THUMBNAIL);
+ }
+
+ /**
+ * Clicks OK to apply the selected background and close the dialog.
+ */
+ confirm(): Promise<void> {
+ return this.clickOkButton();
+ }
+
+ /**
+ * Clicks the X button to cancel without applying any changes.
+ */
+ cancel(): Promise<void> {
+ return this.clickCloseButton();
+ }
+}
diff --git a/tests/specs/misc/virtualBackground.spec.ts b/tests/specs/misc/virtualBackground.spec.ts
new file mode 100644
index 0000000000..3e16d00667
--- /dev/null
+++ b/tests/specs/misc/virtualBackground.spec.ts
@@ -0,0 +1,220 @@
+import { setTestProperties } from '../../helpers/TestProperties';
+import { ensureOneParticipant } from '../../helpers/participants';
+
+setTestProperties(__filename, {
+ usesBrowsers: [ 'p1' ]
+});
+
+/**
+ * Reads the current virtual-background slice of the Redux store.
+ */
+async function getVBState() {
+ return ctx.p1.execute(() => APP.store.getState()['features/virtual-background']);
+}
+
+/**
+ * Opens the virtual background dialog via the toolbar button and waits for it to be displayed.
+ */
+async function openVBDialog() {
+ await ctx.p1.getToolbar().clickVirtualBackgroundButton();
+ await ctx.p1.getVirtualBackgroundDialog().waitForDisplay();
+}
+
+/**
+ * Waits until backgroundEffectEnabled settles to the expected value.
+ * Needed because jitsiTrack.setEffect() is async — an effect load failure can briefly flip the
+ * flag to true before rolling it back to false.
+ * When expecting true, the value must remain stable for stabilityWindow ms to avoid passing on
+ * the optimistic pre-apply dispatch.
+ *
+ * @param {boolean} expected - The expected settled value.
+ * @param {number} timeout - How long to wait in ms.
+ * @param {number} stabilityWindow - How long the expected value must remain unchanged (ms).
+ */
+async function waitForEffectEnabled(expected: boolean, timeout = 8000, stabilityWindow = 500): Promise<void> {
+ let matchedAt: number | undefined;
+ const requiredStableMs = expected ? stabilityWindow : 0;
+
+ await ctx.p1.driver.waitUntil(
+ async () => {
+ const state = await getVBState();
+
+ if (state.backgroundEffectEnabled !== expected) {
+ matchedAt = undefined;
+
+ return false;
+ }
+
+ if (requiredStableMs === 0) {
+ return true;
+ }
+
+ const now = Date.now();
+
+ if (matchedAt === undefined) {
+ matchedAt = now;
+
+ return false;
+ }
+
+ return now - matchedAt >= requiredStableMs;
+ },
+ { timeout, timeoutMsg: `backgroundEffectEnabled did not settle to ${expected} within ${timeout}ms` }
+ );
+}
+
+describe('Virtual backgrounds', () => {
+ it('joining the meeting', async () => {
+ await ensureOneParticipant({
+ configOverwrite: {
+ disableVirtualBackground: false
+ }
+ });
+ });
+
+ it('open virtual background dialog', async () => {
+ await openVBDialog();
+ expect(await ctx.p1.getVirtualBackgroundDialog().isDisplayed()).toBe(true);
+ });
+
+ it('select none — aria-checked and redux state', async () => {
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ await vbDialog.clickNone();
+ expect(await vbDialog.isNoneChecked()).toBe(true);
+ expect(await vbDialog.isBlurChecked()).toBe(false);
+ expect(await vbDialog.isSlightBlurChecked()).toBe(false);
+
+ await vbDialog.confirm();
+ await waitForEffectEnabled(false);
+
+ const state = await getVBState();
+
+ expect(state.backgroundEffectEnabled).toBe(false);
+ expect(state.selectedThumbnail).toBe('none');
+ });
+
+ it('select slight blur — aria-checked and redux state', async () => {
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ await vbDialog.clickSlightBlur();
+ expect(await vbDialog.isSlightBlurChecked()).toBe(true);
+ expect(await vbDialog.isNoneChecked()).toBe(false);
+ expect(await vbDialog.isBlurChecked()).toBe(false);
+
+ await vbDialog.confirm();
+ await waitForEffectEnabled(true);
+
+ const state = await getVBState();
+
+ expect(state.backgroundEffectEnabled).toBe(true);
+ expect(state.backgroundType).toBe('blur');
+ expect(state.blurValue).toBe(8);
+ expect(state.selectedThumbnail).toBe('slight-blur');
+ });
+
+ it('select full blur — aria-checked and redux state', async () => {
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ await vbDialog.clickBlur();
+ expect(await vbDialog.isBlurChecked()).toBe(true);
+ expect(await vbDialog.isNoneChecked()).toBe(false);
+ expect(await vbDialog.isSlightBlurChecked()).toBe(false);
+
+ await vbDialog.confirm();
+
+ // Wait long enough for the async setEffect() to complete without rolling back.
+ // A false value here would mean the effect threw and backgroundEffectEnabled was reset.
+ await waitForEffectEnabled(true, 15000);
+
+ const state = await getVBState();
+
+ expect(state.backgroundEffectEnabled).toBe(true);
+ expect(state.backgroundType).toBe('blur');
+ expect(state.blurValue).toBe(25);
+ expect(state.selectedThumbnail).toBe('blur');
+ });
+
+ it('disable background — redux state correct', async () => {
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ await vbDialog.clickNone();
+ await vbDialog.confirm();
+
+ await waitForEffectEnabled(false);
+
+ const state = await getVBState();
+
+ expect(state.backgroundEffectEnabled).toBe(false);
+ expect(state.selectedThumbnail).toBe('none');
+ });
+
+ it('rapid switching before confirm — only last selection applied', async () => {
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ // Click through several blur options quickly without confirming between them
+ await vbDialog.clickBlur();
+ await vbDialog.clickNone();
+ await vbDialog.clickSlightBlur();
+ await vbDialog.clickBlur();
+ await vbDialog.clickSlightBlur();
+
+ // Slight blur should be the active selection in the dialog
+ expect(await vbDialog.isSlightBlurChecked()).toBe(true);
+ expect(await vbDialog.isBlurChecked()).toBe(false);
+ expect(await vbDialog.isNoneChecked()).toBe(false);
+
+ await vbDialog.confirm();
+ await waitForEffectEnabled(true);
+
+ const state = await getVBState();
+
+ expect(state.selectedThumbnail).toBe('slight-blur');
+ expect(state.backgroundType).toBe('blur');
+ expect(state.blurValue).toBe(8);
+ });
+
+ it('cancel discards selection — redux state unchanged', async () => {
+ // Precondition: slight-blur is applied from the previous test
+ const stateBefore = await getVBState();
+
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ await vbDialog.clickBlur();
+ expect(await vbDialog.isBlurChecked()).toBe(true);
+
+ await vbDialog.cancel();
+
+ const stateAfter = await getVBState();
+
+ expect(stateAfter.selectedThumbnail).toBe(stateBefore.selectedThumbnail);
+ expect(stateAfter.backgroundEffectEnabled).toBe(stateBefore.backgroundEffectEnabled);
+ expect(stateAfter.backgroundType).toBe(stateBefore.backgroundType);
+ });
+
+ it('persistence across reopen — previously applied thumbnail shown as selected', async () => {
+ // Apply full blur
+ await openVBDialog();
+ await ctx.p1.getVirtualBackgroundDialog().clickBlur();
+ await ctx.p1.getVirtualBackgroundDialog().confirm();
+ await waitForEffectEnabled(true, 15000);
+
+ // Reopen and verify blur is still aria-checked
+ await openVBDialog();
+ const vbDialog = ctx.p1.getVirtualBackgroundDialog();
+
+ expect(await vbDialog.isBlurChecked()).toBe(true);
+ expect(await vbDialog.isSlightBlurChecked()).toBe(false);
+ expect(await vbDialog.isNoneChecked()).toBe(false);
+
+ // Clean up
+ await vbDialog.clickNone();
+ await vbDialog.confirm();
+ await waitForEffectEnabled(false);
+ });
+});