with one click
arkxtest-screenshots-recording
// Screen capture via UiDriver.screenCap() and hdc-based UiTest device setup for HarmonyOS arkxtest UI automation.
// Screen capture via UiDriver.screenCap() and hdc-based UiTest device setup for HarmonyOS arkxtest UI automation.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | arkxtest-screenshots-recording |
| description | Screen capture via UiDriver.screenCap() and hdc-based UiTest device setup for HarmonyOS arkxtest UI automation. |
| tech_stack | ["harmonyos"] |
| language | ["arkts"] |
| capability | ["e2e-testing"] |
| version | OpenHarmony arkxtest API 8+ |
| collected_at | "2025-01-01T00:00:00.000Z" |
Source: https://raw.githubusercontent.com/openharmony/testfwk_arkxtest/master/README_en.md
Capture device screenshots during arkxtest UI automation runs using the UiDriver.screenCap() API. Covers device-side UiTest enablement via hdc, UiTest binary deployment, and the programmatic screenshot API for embedding visual evidence into test reports and debugging workflows.
Before any screenshot or UI automation, UiTest mode must be enabled:
hdc_std shell param set persist.ace.testmode.enabled 1
For OpenHarmony 3.1 Release, UiTest must be manually built and deployed:
# Build
./build.sh --product-name rk3568 --build-target uitestkit
# Deploy to device
hdc_std target mount
hdc_std shell mount -o rw,remount /
hdc_std file send uitest /system/bin/uitest
hdc_std file send libuitest.z.so /system/lib/module/libuitest.z.so
hdc_std shell chmod +x /system/bin/uitest
import { BY, UiDriver, UiComponent } from '@ohos.uitest'
import { describe, it, expect } from '@ohos/hypium'
export default async function abilityTest() {
describe('ScreenshotTest', function () {
it('capture_after_action', 0, async function (done) {
try {
let driver = await UiDriver.create()
// Perform UI action
let button = await driver.findComponent(BY.text('Submit'))
await button.click()
// Capture screenshot
await driver.screenCap('/data/local/tmp/after_submit.png')
} finally {
done()
}
})
})
}
it('multi_step_screenshots', 0, async function (done) {
try {
let driver = await UiDriver.create()
// Initial state
await driver.screenCap('/data/local/tmp/step0_initial.png')
// Navigate
await driver.findComponent(BY.text('Settings')).click()
await driver.screenCap('/data/local/tmp/step1_settings.png')
// Toggle a switch
let toggle = await driver.findComponent(BY.text('Wi-Fi'))
await toggle.click()
await driver.screenCap('/data/local/tmp/step2_wifi_toggled.png')
} finally {
done()
}
})
After test execution, retrieve screenshots from the device:
hdc_std file recv /data/local/tmp/after_submit.png ./test-artifacts/
| API | Signature | Purpose |
|---|---|---|
screenCap | driver.screenCap(path: string): Promise<void> | Captures current screen to device-local path |
create | UiDriver.create(): Promise<UiDriver> | Creates UiDriver instance (required before screenCap) |
hdc_std shell param set persist.ace.testmode.enabled 1 — screenshots and all UiDriver APIs fail without this.screenCap() saves to the device filesystem. Use hdc_std file recv to pull files to the host. The path /data/local/tmp/ is commonly used as it's writable.await with screenCap(). Forgetting await will not capture the screenshot and won't throw an obvious error.screenCap() captures what's rendered on screen — off-screen, occluded, or not-yet-rendered components won't appear.arkxtest-assertions to capture screenshots on assertion failure for debugging.arkxtest-driver-interactions to capture before/after screenshots around clicks, swipes, and text input.driver.delayMs() before screenCap() to wait for animations or transitions to complete.