How to perform end-to-end testing
In RadGrad2 we are using TestCafe a node.js tool to automate end-to-end web testing. We added testcafe
as a dev dependency in the package.json file.
Identifying UI 'components'
To test the RadGrad2 app we need to be able to select the UI components. We've created ids for each of the components we want to test. We define and export the ids so there aren't typo errors. The exported ids are in a typescript file named e2e-names.ts
. The directory structure will look like:
For example:
Now we have a way of accessing the HelpPanelWidget
using TestCafe selectors. For example, we defined two HelpPanelWidget
selectors.
- One for the title, so we can check for correct titles.
- Two for the accordion, so we can open it and check for correct contents, then close it.
These selectors are exported from a file named e2e-selectors.ts
.
Currently, we don't have end-to-end tests for all the pages, widgets, and components. Hopefully, we will continue to write the missing end-to-end tests.
Writing TestCafe tests
Adding a new UI 'component' id
When we want add a new test for a component, we need to do several things.
- Create an id for the component if it doesn't already have one. Ids are the camelcase names for the component. For example, the id for the FilterCourseWidget is
filterCourseWidget
. We export the id from thee2e-names.ts
file in the directory of the component.
- Add the id to the component.
- Create one or more TestCafe selectors for the component. We export the selector from the
e2e-selectors.ts
file in the same directory as the component.
- Use the selectors in a test.