Files
Rosea/e2e/android/garden.android.ts
T

55 lines
2.5 KiB
TypeScript

import { _android as android, expect, test, type AndroidDevice, type Page } from '@playwright/test';
import { en } from '@rosea/ui/copy';
import { pastGardener, openRing } from '../garden.js';
import { storedCare } from '../stored.js';
/**
* The Android app on Fabrica's test phone (.agents/features/fabrica-release.md F9): the debug
* APK Fabrica installed, reached through its WebView with Playwright's own Android support
* (Fabrica docs/22_devices.md). Only `fabrica tests run --target phone` runs it: the phone is
* leased from Fabrica's queue, the app's data is cleared first, and Fabrica stops the app after.
* Watering is by the keyboard's Space held down: the same pour as a held finger (rose.md), and
* the one input a WebView reached over DevTools takes as a player's.
*/
const PKG = process.env['FABRICA_TESTS_PACKAGE'];
const SERIAL = process.env['ANDROID_SERIAL'];
test.skip(!PKG || !SERIAL, "runs only through Fabrica's phone queue: fabrica tests run --target phone");
async function garden(device: AndroidDevice): Promise<Page> {
const webView = await device.webView({ pkg: PKG! }, { timeout: 30_000 });
const page = await webView.page();
await expect(page.getByRole('heading', { level: 2, name: en.gardener.question }).or(page.getByRole('button', { name: en.rose.care }))).toBeVisible({
timeout: 30_000
});
return page;
}
test('the garden opens on the phone; she is watered, and still watered after the app is closed and opened', async () => {
test.setTimeout(240_000);
const device = (await android.devices()).find((d) => d.serial() === SERIAL);
expect(device, `no phone with the serial ${SERIAL} on adb`).toBeDefined();
try {
let page = await garden(device!);
await pastGardener(page);
// No town: the private choice, and it keeps the test free of any place.
await page.getByRole('button', { name: /^Not now/ }).click();
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).focus();
await page.keyboard.down('Space');
await page.waitForTimeout(1500);
await page.keyboard.up('Space');
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
await storedCare(page, 1);
await device!.shell(`am force-stop ${PKG!}`);
await device!.shell(`monkey -p ${PKG!} -c android.intent.category.LAUNCHER 1`);
page = await garden(device!);
await page.getByRole('button', { name: en.rose.numbers }).click();
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
} finally {
await device?.close();
}
});