The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/tests/e2e
Douglas Fabris 108f7f5185
test: Reorg modal page objects (#37871)
3 days ago
..
apps test: Reorg modal page objects (#37871) 3 days ago
config
containers/saml test: add saml login tests for user without name and user with channels (#36383) 4 months ago
e2e-encryption test: Reorg modal page objects (#37871) 3 days ago
federation test: Reorg modal page objects (#37871) 3 days ago
fixtures feat: e2ee security hardening (#36942) 2 months ago
omnichannel test: Reorg modal page objects (#37871) 3 days ago
page-objects test: Reorg modal page objects (#37871) 3 days ago
utils test: Replace magic tag names in e2e tests (#37932) 5 days ago
.eslintrc.json
README.md test: add best practices to README (#36600) 4 months ago
account-forgetSessionOnWindowClose.spec.ts
account-login.spec.ts chore: Move E2E Encryption startup (#36722) 4 months ago
account-profile.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
account-security.spec.ts fix: Unable to change password when 2FA is enabled (#37745) 2 weeks ago
admin-room.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
admin-users-custom-fields.spec.ts test: Flaky admin search users (#37501) 1 month ago
admin-users-role-management.spec.ts test: Flaky admin search users (#37501) 1 month ago
admin-users-status-management.spec.ts test: Flaky admin search users (#37501) 1 month ago
admin-users.spec.ts feat: User `inactiveReason` (#37224) 4 weeks ago
administration-settings.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
administration.spec.ts fix: `UserAutoCompleteMultiple` not removing selected items (#37823) 1 week ago
anonymous-user.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
avatar-settings.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
calendar.spec.ts chore: links module (#37347) 2 months ago
channel-management.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
create-channel.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
create-direct.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
create-discussion.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
delete-account.spec.ts test: Purge duplicated `toastbar` page objects (#37410) 2 months ago
email-inboxes.spec.ts test: Refactor admin locators (#37341) 2 months ago
embedded-layout.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
emojis.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
enforce-2FA.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
export-messages.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
feature-preview.spec.ts test: Reorg modal page objects (#37871) 3 days ago
file-upload.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
forgot-password.spec.ts
global-search.spec.ts feat!: Remove omnichannel current chats panel (#37673) 1 week ago
homepage.spec.ts
iframe-authentication.spec.ts test: Remove `Utils` page object (#37371) 2 months ago
image-gallery.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
image-upload.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
imports.spec.ts test: Refactor admin locators (#37341) 2 months ago
jump-to-thread-message.spec.ts chore: Remove `.main-content` CSS (#36167) 7 months ago
login.spec.ts test: Remove `Utils` page object (#37371) 2 months ago
mark-unread.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
message-actions.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
message-composer.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
message-mentions.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
messaging.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
notification-sounds.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
oauth.spec.ts
permissions.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
presence.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
preview-public-channel.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
prune-messages.spec.ts test: Purge duplicated `toastbar` page objects (#37410) 2 months ago
quote-attachment.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
quote-messages.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
read-receipts.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
register.spec.ts test: Remove `Utils` page object (#37371) 2 months ago
report-message.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
reset-password.spec.ts
retention-policy.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
saml.spec.ts test: add saml login tests for user without name and user with channels (#36383) 4 months ago
search-discussion.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
settings-assets.spec.ts test: Refactor admin locators (#37341) 2 months ago
settings-int.spec.ts test: Purge duplicated `toastbar` page objects (#37410) 2 months ago
settings-persistence-on-ui-navigation.spec.ts chore: Upgrade Fuselage focus handling (#37334) 1 month ago
sidebar-administration-menu.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
sidebar-menu.spec.ts test: menu disappears once page finishes loading (#36079) 7 months ago
sidebar.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
system-messages.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
team-management.spec.ts test: Reorg modal page objects (#37871) 3 days ago
threads.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
translations.spec.ts
user-card-info-actions-by-member.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
user-card-info-actions-by-room-owner.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
user-required-password-change.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
video-conference-ring.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
video-conference.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago
voice-calls-ce.spec.ts test: Reorg modal page objects (#37871) 3 days ago
voice-calls-ee.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 1 week ago

README.md

E2E Testing with playwright

Running tests

The application must be started with TEST_MODE=true

$ TEST_MODE=true yarn dev

Then we can run a single suite with

$ yarn test:e2e ./tests/e2e/administration.spec.ts

Or all the tests with

$ yarn test:e2e

We can also provide some env vars to test:e2e script:

  • BASE_URL=<any_url> Run the tests to the given url
  • PWDEBUG=1 Control the test execution

Page Objects

  • Any locator name must start with of one the following prefixes: btn, link, input, select, checkbox, text

Assertions

Checking if a element is visible

 await expect(anyElement).toBeVisible();

Playwright Locator Best Practices

Preferred locator types:

1. By role .getByRole():

This is the most recommended locator type.

  • It ensures our element is accessible to screen readers and other assistive technologies.
  • It ensures that the element is uniquely identifiable.
  • It's recommended to use the exact option to ensure that the locator doesn't match any other element with the same role
await page.getByRole('button', { name: 'Save', exact: true });

// Without the `exact` option, Playwright would match buttons with 'Save' and 'Save changes' labels.

2. By text .getByText() or .getByLabel():

  • Use this when locating by role is not possible or not sufficient.
  • Be sure to restrict the scope of the locator to the element you are looking for.

3. Locator with has:

Our input elements hide the native input and render a custom component.

To target the input and trigger changes, you should locate the label that wraps the input and use the has locator.

page.locator('label', { has: this.page.getByRole('checkbox', { name: 'Private' }) });

Locator types to avoid (at all costs):

If you are not able to find the element by role, label or text, it's a sign that the element is not accessible to the user. The component should be refactored to allow a more accessible locator.

1. By data-qa-id or testId .getByTestId():

// DON'T ❌ 
page.locator('[data-qa-id="menu-more-actions"]'); 

// DO ✅
page.getByRole('menu', {name: 'More actions', exact: true }); 

2. By elements and class names .locator('div.class-name'):

The HTML structure and/or class names can easily change over time, so it's better to use the locator by role and name.

// DON'T ❌
page.locator('#modal-root .rcx-button-group--align-end .rcx-button--primary');

// #modal-root was used to locate the injected portal element for the modal.
// This can be better located by role 'dialog' and making sure the modal has the proper name attribute.

// DO ✅
page.getByRole('dialog', name: 'Modal name example').getByRole('button', { name: 'Confirm', exact: true });

3. By position:

Using nth-child or similar selectors is not recommended as it can easily change. It's a fragile locator and it's hard to maintain.

4. Parent/Child relationships:

A change in the DOM structure can break the test.

Use our page-objects:

apps/meteor/tests/e2e/page-objects

  • page-objects are a great way to reuse locators across tests using getters and methods.
  • They make it easier to write tests that are more readable and maintainable.
  • Always make sure to use the most restricted scope possible - not the whole page to avoid multiple matches.

If you are writing a new test, make sure to look at the existing page-objects to see if there is a suitable one for your use case.

If not, evaluate if creating a reusable getter/method is worth it and create the ones you need in the respective context.

E.g.: Writing a new test for a sidebar behavior.

  • check apps/meteor/tests/e2e/page-objects/fragments/sidebar.ts if the fragments you need are already there.
  • If not, create new getters and/or methods in this file.

Usage example:

// apps/meteor/tests/e2e/page-objects/fragments/sidebar.ts
// ...

	get sidebar(): Locator {
		return this.page.getByRole('navigation', { name: 'sidebar' });
	}

	get channelsList(): Locator {
		return this.sidebar.getByRole('list', { name: 'Channels' });
	}

  // Restricted scope: inside navigation > sidebar > list named Channels > link with name
	getSearchRoomByName(name: string) {
		return this.channelsList.getByRole('link', { name });
	}
// test.spec.ts

  test('should display sidebar items', async ({ page }) => {
      poHomeChannel = new HomeChannel(page);
      await page.goto('/home');
      const targetChannel = 'channel-test';

      await expect(poHomeChannel.sidebar.getSearchRoomByName(targetChannel)).toBeVisible();
  });

Cleanup after tests

  • Remember to delete all users, channels, rooms, etc, created during the tests.
  • Reset settings to their default values after the tests, if changed.
  • Close all new pages opened during the tests.
  • You can use the test.afterAll() or test.afterEach() methods to clean up after the tests.
// test.spec.ts

test.describe.serial('feature example', ({ api}) => {
	  let targetChannel;
	  let targetDiscussion;

    test.beforeAll(async ({ api }) => {
      // change setting value
		  await setSettingValueById(api, 'Accounts_AllowFeaturePreview', true);

      // create channel
      targetChannel = await createTargetChannel(api, { members: ['user1'] });

      // create discussion
      targetDiscussion = await createTargetDiscussion(api);
    });
    test.afterAll(async ({ api }) => {
      // reset setting value
		  await setSettingValueById(api, 'Accounts_AllowFeaturePreview', false);

      // delete  channel
      await deleteChannel(api, targetChannel);

      // delete discussion
      await deleteRoom(api, targetDiscussion._id);
    });
})

General recommendations

Use test.describe for grouping tests

It can be used to group related tests into a test suite. It provides a way to organize tests logically and improve the readability and maintainability of your test code.

test.describe('Feature Test', () => {
  test('should show feature test', async ({ api}) => {
    // do some tests
  });
});

Use test.step for grouping steps

Enhances test readability and provides more detailed information in test reports

test.describe('Feature Test', () => {
  test.step('should show feature test', async ({ api}) => {
    // do some tests
  });
});

Big test files should not be .serial:

  • Ok for tests with very few steps, when steps have dependencies on each other, you can simulate the user flow sequentially.
  • Avoid chaining big tests with test.serial - dependant steps make it harder to debug and/or make small changes

If you are changing something on the 34th step, you would have to run the whole test suite multiple times during development, instead of olny running the test step in question.