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
Júlia Jaeger Foresti 1045010054
test: add best practices to README (#36600)
5 months ago
..
apps
config
containers/saml fix: allow users to set password first time (#36627) 5 months ago
federation feat: Separate video call and voice call room actions (#35700) 9 months ago
fixtures fix: allow users to set password first time (#36627) 5 months ago
omnichannel chore: Rooms store (#36439) 6 months ago
page-objects fix: User custom status text being overwritten (#36601) 5 months ago
utils fix: redirect on required password change (#36381) 6 months ago
.eslintrc.json
README.md test: add best practices to README (#36600) 5 months ago
access-security-page.spec.ts chore: Remove `.main-content` CSS (#36167) 7 months ago
account-forgetSessionOnWindowClose.spec.ts
account-login.spec.ts fix: stale data after login expired (#36338) 6 months ago
account-profile.spec.ts feat: Require token name when creating personal access token (#35315) 7 months ago
admin-room.spec.ts
admin-users-custom-fields.spec.ts fix: users.update API call erases other customFields (#36578) 5 months ago
admin-users.spec.ts fix: new user not moving from Pending to Deactivated tab in admin UI (#35828) 8 months ago
administration-settings.spec.ts fix: CodeSettingInput renders duplicate code text box (#35273) 10 months ago
administration.spec.ts fix: Owner change modal not showing content as expected (#35815) 8 months ago
anonymous-user.spec.ts
avatar-settings.ts
calendar.spec.ts fix: status sync for overlapping events (#36206) 7 months ago
channel-management.spec.ts test: flaky should be able to navigate on call popup with keyboard (#36082) 8 months ago
create-channel.spec.ts
create-direct.spec.ts
create-discussion.spec.ts
delete-account.spec.ts test: add end-to-end tests for delete own account functionality (#36129) 7 months ago
e2e-encryption.spec.ts test: Ensure login button is visible after logout in e2e encryption t… (#36650) 5 months ago
email-inboxes.spec.ts
embedded-layout.spec.ts test: improve the current tests for embedded layout (#36311) 6 months ago
emojis.spec.ts regression: `EmojiPicker` not displaying scrollbar properly (#35536) 10 months ago
enforce-2FA.spec.ts feat: improve UX for logged users with mandatory 2FA roles (#35709) 9 months ago
export-messages.spec.ts test: export messages with hide contextual bar preference (#36564) 5 months ago
feature-preview.spec.ts fix: [Enhanced navigation] Missing burger menu in embedded layout (#36398) 6 months ago
file-upload.spec.ts fix: `FileUpload` initial focus order (#35889) 9 months ago
forgot-password.spec.ts
homepage.spec.ts
image-gallery.spec.ts test: Replace invalid `imageLink` in image-gallery (#35645) 10 months ago
image-upload.spec.ts fix: upload of malformed jpegs with Message_Attachments_Strip_Exif disabled fails silently (#35839) 8 months ago
imports.spec.ts
jump-to-thread-message.spec.ts chore: Remove `.main-content` CSS (#36167) 7 months ago
login.spec.ts fix: Remove `Change to Default` button suggestion in login page (#36062) 8 months ago
mark-unread.spec.ts test: flaky - stop closing page before sending the message (#35646) 10 months ago
message-actions.spec.ts chore: Rooms store (#36439) 6 months ago
message-composer.spec.ts chore: `AudioMessageRecorder` mount effect (#35146) 11 months ago
message-mentions.spec.ts test: flaky feature preview tests (#35891) 9 months ago
messaging.spec.ts fix: Parsing emojis inside code blocks in attachment content using `chat.postMessage` API call (#35963) 8 months ago
oauth.spec.ts
otr.spec.ts fix: Don't allow OTR message editing (#35600) 8 months ago
permissions.spec.ts
presence.spec.ts fix: User custom status text being overwritten (#36601) 5 months ago
preview-public-channel.spec.ts chore: Only public channels cannot be previewed by permissions (#35611) 9 months ago
prune-messages.spec.ts fix: ui does not update after pruning only files (#36099) 6 months ago
quote-attachment.spec.ts test: Automate the functionality for quoting an attachment with description. (#36190) 7 months ago
quote-messages.spec.ts test: automate various quote operations (#36351) 6 months ago
read-receipts.spec.ts
register.spec.ts fix: UI validation for existing email during user registration (#35277) 7 months ago
report-message.spec.ts test: create tests for reporting messages (#35783) 9 months ago
reset-password.spec.ts
retention-policy.spec.ts
saml.spec.ts fix: allow users to set password first time (#36627) 5 months ago
search-discussion.spec.ts feat: Use `IconButton` to navigate to parent room (#35613) 9 months ago
settings-assets.spec.ts
settings-int.spec.ts
settings-persistence-on-ui-navigation.spec.ts
sidebar-administration-menu.spec.ts
sidebar-menu.spec.ts test: menu disappears once page finishes loading (#36079) 7 months ago
sidebar.spec.ts fix: User custom status text being overwritten (#36601) 5 months ago
system-messages.spec.ts
team-management.spec.ts fix: create-c and create-p not being applied to Team Creation (#36592) 5 months ago
threads.spec.ts chore: Rooms store (#36439) 6 months ago
translations.spec.ts
user-card-info-actions-by-member.spec.ts
user-card-info-actions-by-room-owner.spec.ts
user-required-password-change.spec.ts fix: User custom status text being overwritten (#36601) 5 months ago
video-conference-ring.spec.ts test: flaky should be able to navigate on call popup with keyboard (#36082) 8 months ago
video-conference.spec.ts test: flaky should be able to navigate on call popup with keyboard (#36082) 8 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.