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
Tasso Evangelista 819399c7b8
chore(eslint): Consistent type imports/exports (#39341)
4 days ago
..
apps test: Reorg modal page objects (#37871) 3 months ago
config
containers/saml
e2e-encryption chore(eslint): Consistent type imports/exports (#39341) 4 days ago
federation chore(eslint): Allow `await` in loops (#39178) 6 days ago
fixtures chore(eslint): Consistent type imports/exports (#39341) 4 days ago
omnichannel chore: replace messages `data-qa` (#38493) 1 week ago
page-objects chore: Upgrade fuselage packages (#39169) 6 days ago
utils test: Add automated tests for custom fields functionality. (#38743) 2 weeks ago
README.md
account-forgetSessionOnWindowClose.spec.ts
account-login.spec.ts
account-manage-devices.spec.ts fix: Device logout not redirecting to login page (#38616) 3 weeks ago
account-profile.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
account-security.spec.ts feat: enable password policy by default and increase `MinLength` (#38032) 2 months ago
admin-device-management.spec.ts fix: Device logout not redirecting to login page (#38616) 3 weeks ago
admin-room.spec.ts test: Replace `data-qa` by accessible locators (#36757) 2 months ago
admin-users-custom-fields.spec.ts
admin-users-role-management.spec.ts
admin-users-status-management.spec.ts
admin-users.spec.ts
administration-settings.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
administration.spec.ts test: Reorg omnichannel admin page objects (#37972) 1 month ago
anonymous-user.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
avatar-settings.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
calendar.spec.ts
channel-management.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
create-channel.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
create-direct.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
create-discussion.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
delete-account.spec.ts
email-inboxes.spec.ts
embedded-layout.spec.ts test: Reorg composer page objects (#38104) 2 months ago
emojis.spec.ts test: Reorg composer page objects (#38104) 2 months ago
enforce-2FA.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
export-messages.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
feature-preview.spec.ts test: Reorg composer page objects (#38104) 2 months ago
file-upload.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
files-management.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
forgot-password.spec.ts
global-search.spec.ts feat!: Remove omnichannel current chats panel (#37673) 3 months ago
homepage.spec.ts test: remove homepage `data-qa` attributes (#38004) 2 months ago
iframe-authentication.spec.ts
image-gallery.spec.ts chore(eslint): Allow `await` in loops (#39178) 6 days ago
image-upload.spec.ts test: Automated tests verifying presence of typing indicator. (#38488) 4 weeks ago
imports.spec.ts
jump-to-thread-message.spec.ts
login.spec.ts
mark-unread.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
message-actions.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
message-composer.spec.ts fix: Mentions popup remains open after canceling message edit (#38635) 2 weeks ago
message-mentions.spec.ts feat: standardize username display (#38532) 4 weeks ago
messaging.spec.ts chore(eslint): Allow `await` in loops (#39178) 6 days ago
notification-sounds.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
oauth.spec.ts
permissions.spec.ts test: Reorg composer page objects (#38104) 2 months ago
presence.spec.ts fix: saving custom status without changes breaks the UI (#38186) 2 months ago
preview-public-channel.spec.ts test: Reorg composer page objects (#38104) 2 months ago
prune-messages.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
quote-attachment.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
quote-messages.spec.ts test: Reorg composer page objects (#38104) 2 months ago
read-receipts.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
register.spec.ts i18n: Update inline error messages in registration form (#36442) 2 weeks ago
report-message.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
reset-password.spec.ts feat: enable password policy by default and increase `MinLength` (#38032) 2 months ago
retention-policy.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
saml.spec.ts
search-discussion.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
settings-assets.spec.ts test: Replace `data-qa` by accessible locators (#36757) 2 months ago
settings-int.spec.ts test: remove homepage `data-qa` attributes (#38004) 2 months ago
settings-persistence-on-ui-navigation.spec.ts test: remove `data-qa-setting-id` locators (#38002) 2 months ago
sidebar-administration-menu.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
sidebar-menu.spec.ts
sidebar.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
system-messages.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
team-management.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
threads.spec.ts chore: replace messages `data-qa` (#38493) 1 week ago
translations.spec.ts
user-card-info-actions-by-member.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
user-card-info-actions-by-room-owner.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
user-required-password-change.spec.ts feat: enable password policy by default and increase `MinLength` (#38032) 2 months ago
video-conference-ring.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
video-conference.spec.ts feat: Move enhanced navigation out of feature preview (#37285) 3 months ago
voice-calls-ee.spec.ts test: Reorg composer page objects (#38104) 2 months 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.