Testing Framework
Testing Framework
Importing Modules
import test from '@system.test'
Introduction
The system.test module is an end-to-end testing framework that can programmatically simulate user operations and check whether the interface behavior meets expectations.
A simple code example for simulating user operations is as follows:
await test.getByClass('play-button').click()
await test.getByClass('more-button').click()
await test.getByClass('download-button').click()
await test.getByClass('close-button').click()
await test.getByClass('menu-button').click()
await test.getHasText('Download List').click()
await test.getByTag('Scroll').scroll(0, -200, 0.3)
await test.getHasText(/[a-z]/).click()
This code will automatically wait for elements in the interface to be rendered, use scroll gestures to bring occluded elements into the visible area, and then perform gestures such as clicking or scrolling on them.
API
Helper Functions
These functions provide auxiliary capabilities in tests, such as delays.
wait
Asynchronously delays for a specified time, used to wait for certain operations in tests or to simulate user pauses.
Locators
Locators find elements (native components) from the top-level page of the application, for example, by searching based on the element's tag or id. For further introduction to locators, please refer to the Locator object.
getByTag
Locates elements by tag. Currently, only UpperCamelCase naming is supported, such as 'P', 'Swiper', etc.
getByClass
Locates elements by the class attribute.
getById
Locates elements by the id attribute.
getHasText
Locates elements based on whether the element's text attribute matches the text parameter. The text parameter is a regular expression, for example:
/hello/tests whether the element'stextattribute value contains the string'hello';/^hello/tests whether the element'stextattribute value starts with'hello';/^hello$/tests whether the element'stextattribute value is exactly'hello'.
The matching rules for the text parameter are the same as RegExp.test().
Locator Object
The Locator object is returned by locator APIs and can be used for further operations. All locator operations will attempt to automatically wait for the element to appear and move it into the visible area.
click
Once the element exists and has been scrolled into the visible area, a click gesture is simulated at the element's position.
scroll
Once the element exists and has been scrolled into the visible area, a scroll gesture is simulated at the element's position. dx and dy are the scroll offsets in pixels; the optional duration is the time for the gesture in seconds, with a default value of .
This method waits for the element's scrolled attribute to become false before resolving the returned Promise object. Therefore, for components such as scroll and swiper, the scroll() method will only trigger the next operation after the inertial animation of these components has stopped.
wait
Waits for the element to exist and scrolls it into view, but does not simulate any gestures or other operations.
