End-to-end tests run on a host machine, unlike other Fuchsia packages that are served to a Fuchsia device and run on the device. To trigger actions on a Fuchsia device (for example, “swipe right on the screen”) from a remote test host, end-to-end tests send JSON-RPC requests to SL4F running on the device. SL4F then translates these requests into Fuchsia-equivalent FIDL commands for various driver services on the device.
However, not all requests from a test host to a Fuchsia device need to go through SL4F. For instance, a test can directly access a Fuchsia device’s Flutter driver or Chrome driver over separate, dedicated HTTP connections (see Figure 1), given the condition that the test host can access these drivers’ ports on the device. If not, the test setup may require port forwarding.
Interaction between an end-to-end test and SL4F
The following sequence walks through how an end-to-end test triggers the “swipe right on the screen” action on a Fuchsia device:
- An end-to-end test runs on a host machine.
- The test starts SL4F on the Fuchsia device over SSH.
- SL4F listens for HTTP requests on port 80 on the device.
- The test sends a JSON-RPC request to SL4F, asking the “swipe right on the screen” action on the device.
- SL4F’s Input facade parses the request into a FIDL command.
- The device performs the “swipe right on the screen” action.
Once started, SL4F continues to run on the device and accept requests until the test terminates SL4F.
Facades in SL4F
Fuchsia extends the functionality of SL4F to introduce additional orchestration and inspection mechanisms that are necessary for testing Fuchsia products. SL4F structures this new functionality into groupings called facades. Each facade exposes one or more JSON-RPC methods.
For end-to-end tests to trigger actions and verify states on a Fuchsia device, a facade offers the following mechanisms:
- Orchestration: A facade is a wrapper for FIDL APIs that runs as a HTTP service handler on a Fuchsia device.
- Inspection: A facade keeps track of asynchronous events on a Fuchsia device.
SL4F currently supports several facades, for example:
- Audio facade - Insert and capture audio.
- Screen facade - Capture the screen.
- Input facade - Inject input gestures on the touch screen.
- Diagnostics facade - Read data published by Inspect from components.
- Wlan facade - Manipulate the status of a wireless LAN device.
- Netstack facade - Manipulate network interfaces.
- File facade - Write and read files on a device’s storage.
- WebDriver facade - Enable and disable devtools in a Chrome webrunner.