Skip to content

Commit ff71c71

Browse files
authored
Update frontend testing documentation (#132)
1 parent a8f9e07 commit ff71c71

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎docs/developer-guide/frontend-testing.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ We do this because we modify the base configuration that comes with Playwright s
2121

2222
Both the `app` and `component` tests depend on the `@openremote/test` package which includes shared fixtures, configurations and our Playwright component testing plugin.
2323

24-
The `shared` fixture in the test package is meant for general test utilities like intercepting requests.
24+
The `shared` fixtures in the test package are meant for general test utilities like intercepting requests. Besides this there are also shared component only test fixtures under `CtShared`.
2525

2626
Each project that needs testing should configure its own Playwright configuration file which must reuse the above-mentioned configurations.
2727

28-
The plugin for component testing mimics Playwright’s component testing plugin, which normally comes with Vite, but this is incompatible with the `commonjs` imports used in some components. Playwright uses Vite to bundle and mount a component to an empty HTML document for testing. Our Playwright plugin mimics the Vite based plugin using Rspack so we can mount our components to the document without import issues.
28+
The plugin for component testing mimics Playwright’s component testing plugin, which normally comes with Vite, but this is incompatible with the `commonjs` imports used in some components. Playwright uses Vite to bundle and mount components to an empty HTML document for testing. Our Playwright plugin mimics the Vite based plugin using Rspack so we can mount our components to the document without import issues.
2929

3030
### App test setup
3131

@@ -139,7 +139,7 @@ ct("My component test", async ({ mount }) => {
139139
```
140140

141141
:::note
142-
You must import a component by its alias `@openremote/*`. Relative paths will cause issues. The downsides of the alias import is that this refers to the transpiled typescript `lib` directory, which is why the component test script includes `npx tsc -b`.
142+
You must import a component by its alias `@openremote/*`. Relative paths will cause issues. The downside of alias imports is that they refer to the transpiled TypeScript (in the `lib` directory), which is why the component test script includes `npx tsc -b` and needs manual rebuilding. However you can still live reload the component changes indirectly by running `npm run serve` on the manager app.
143143
:::
144144

145145
Playwright uses [`locators`](https://playwright.dev/docs/locators) to find elements in the DOM. It's crucial to know the different types of locators to be able to write tests that are robust and to avoid flaky behavior.
@@ -165,19 +165,19 @@ export class AssetsPage implements BasePage {
165165
```
166166

167167
:::note
168-
In case you want to reuse certain non-project specific fixtures across multiple projects you can add your fixture to the `shared` fixtures in the `@openremote/test` package under `ui/test/fixtures/shared.ts`. If you want to reuse component specific fixtures in tests for a parent component or an app, simply import the fixtures and add them through the `extend` function.
168+
In case you want to reuse certain non-project specific fixtures across multiple projects you can add your fixture to the `shared` fixtures in the `@openremote/test` package under `ui/test/fixtures/shared.ts`. If you want to reuse component specific fixtures in tests for a parent component or an app, simply import the fixtures and add them through the `extend` method.
169169
:::
170170

171171
Finally extend the `test` function:
172172

173173
```ts
174-
import { test as base, type Page, type ComponentTestFixtures } from "@openremote/test";
174+
import { test as base, type Page, type SharedComponentTestFixtures } from "@openremote/test";
175175

176176
interface PageFixtures {
177177
assetsPage: AssetsPage;
178178
}
179179

180-
interface ComponentFixtures extends ComponentTestFixtures {
180+
interface ComponentFixtures extends SharedComponentTestFixtures {
181181
...
182182
}
183183

@@ -228,11 +228,11 @@ Or simply run `npm test -- --ui` in the component / app directory.
228228
Please read the [Playwright Best practices](https://playwright.dev/docs/best-practices).
229229
230230
**TL;DR**
231-
- Avoid `xpath` and `css` selectors. Relying too heavily on the [Document Object Model (DOM)](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) makes you more prone to breaking tests when a CSS class is renamed or removed, or when nested elements are removed.
231+
- Avoid `xpath` and `css` selectors. Relying too heavily on classes and filler elements makes you more prone to breaking tests when a CSS class is renamed or removed, or when nested elements are removed.
232232
- Do not use `waitForTimeout` outside of debugging. Tests don't always take the same amount of time which can cause flaky behavior, rather use something like `locator.waitFor()` or even better `page.waitForURL()`.
233233
- Isolate tests, so you can rerun them without relying on external factors such as other tests.
234234
- Use [web first assertions](https://playwright.dev/docs/test-assertions) e.g. `toBeVisible`, `toBeHidden`, `toBeChecked` etc. which use a retry mechanism to avoid flakiness.
235-
- Reuse locators and actions through test fixtures to standardize how to locate specific elements on screen and avoid code duplication in tests.
235+
- Reuse locators and compose actions through test fixtures to standardize how to locate specific elements on screen and avoid code duplication in tests.
236236
- Use the Playwright UI mode, test reports, trace viewer and debugger features.
237237
<!-- - Enable multiple browsers (see playwright UI checkboxes) -->
238238

0 commit comments

Comments
 (0)