Commit graph

1 commit

Author SHA1 Message Date
Abdelrahman Hossam
7a28fd786c
ohos: Adding support for running WPT on OHOS devices using WebDriver (#38846)
Architecture:
```
Desktop (Test Controller)        OHOS Device (Test Target)
┌─────────────────────────┐     ┌─────────────────────────┐
│ WPT Server (port 8000)  │     │ Servo Browser           │
│ Test Runner Script      │---->│ WebDriver Server (7000) │
│ HDC Port Forwarding     │     │ Test Execution          │
└─────────────────────────┘     └─────────────────────────┘
```
After the test is finished, the script will parse the results and print
them in a readable format.

Tried to handle as many errors as possible and find workarounds for each
error to ensure the testing can be completed, or at least provide
comprehensive logs or information to identify exactly where the problem
is. Note that the used ports are just for testing; you can change them
to any other available ports, but make sure that the ports are
consistent in the script and given commands.

To run a WPT test on an OHOS device, you need to:
1. Connect OHOS device to the desktop via a cable (didn't try any other
way of communication)
2. Build and deploy servo with the changes in this PR using
[servoDemo](https://github.com/jschwe/ServoDemo). You can find there the
instructions to build and deploy servo to OHOS device.
3. While deploying servo to OHOS you need to ensure WebDriver is enabled
with the argument --webdriver=7000
4. Ensure OHOS SDK with HDC in PATH
5. Start WPT server on the desktop on a different terminal in servo
directory: ```bash python -m wpt serve --port 8000 ```
6. Update desktop IP in test scripts:
```python
desktop_ip = "192.168.1.100"  # Your desktop's IP
```
You can find your desktop IP with:
```bash
# Windows
ipconfig | findstr "IPv4"

# macOS/Linux
ifconfig | grep "inet "
```
script can be modified to detect the desktop's IP automatically ...
later.
7. Run tests using the new mach command:

```bash
./mach test-ohos-wpt \
    --test <test relative path> \
    --webdriver-port 7000 \
    --wpt-server-port 8000 \
    --verbose
```

The script will:
1. Set up HDC port forwarding and reverse port forwarding for WPT
automatically
2. Connect to WebDriver server on the device
3. Navigate to the test URL
4. Wait for test completion
5. Show test results

Troubleshooting common Issues and Solutions:

1. HDC command not found:
   - Install OHOS SDK and add HDC to PATH
   - Verify: `hdc --version`

2. Failed to connect to WebDriver:
   - Ensure Servo is running with `--webdriver=7000` argument
   - Check device connection: `hdc list targets`
   - Verify port forwarding: `hdc fport ls`
   - Test WebDriver directly: `curl http://localhost:7000/status`

3. Failed to navigate to test URL:
   - Update `desktop_ip` in the script
   - Ensure both devices are on same network or connected via cable
   - Test connectivity: ping from device to desktop

4. Test timeouts:
   - Increase timeout in script (default: 30 seconds)
   - Check if test requires specific dependencies
   - Verify WPT server is serving the test file

---------

Signed-off-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-09-09 08:57:36 +00:00