In Appwright, writing a test is simple and similar to how tests are written in Playwright, but with enhanced mobile capabilities.
A suite does not need its own @playwright/test dependency. Besides test and expect, the package re-exports Playwright's request and the types around it (APIRequest, APIRequestContext, APIResponse, TestInfo), for calling an app's HTTP API from a test or a hook:
import { test, type APIRequestContext } from '@tulip/appwright';
let api: APIRequestContext;
test.beforeAll(async ({ playwright }) => {
api = await playwright.request.newContext({ baseURL: process.env.SITE_URL });
});In Appwright, you can define multiple test configurations for different platforms (Android, iOS, etc.) within your appwright.config.ts. This configuration tells Appwright how to run your tests on different devices and environments.
// In appwright.config.ts
import { defineConfig, Platform } from "appwright";
export default defineConfig({
projects: [
{
name: "android",
use: {
platform: Platform.ANDROID,
device: {
provider: "emulator", // or 'local-device' or 'browserstack'
},
buildPath: "app-release.apk",
},
},
{
name: "ios",
use: {
platform: Platform.IOS,
device: {
provider: "emulator", // or 'local-device' or 'browserstack'
},
buildPath: "app-release.app", // Path to your .app file
},
},
],
});Appwright provides built-in fixtures to handle mobile interactions:
The device fixture offers methods to interact with native mobile app elements.
import { test, expect } from 'appwright';
test('should display the login screen and tap on Login button', async ({ device }) => {
// Assert that the login button is visible
await expect(device.getByText('Login')).toBeVisible();
// Tap on the login button
await device.getByText('Login').tap();
});For hybrid mobile apps with WebView content, Appwright provides a webView fixture that automatically handles context switching between native and web contexts:
import { test, expect } from 'appwright';
test('WebView login test', async ({ device, webView }) => {
// Use webView for web content
await webView.getByTestId('username').fill('admin');
await webView.getByTestId('password').fill('password123');
await webView.getByText('Login').tap();
// Use familiar assertions
await expect(webView.getByText('Welcome')).toBeVisible();
// Mix device and webView as needed
await device.backgroundApp(-1);
});Note: Currently supports apps with a single WebView only. The framework automatically connects to the first available WebView context within your app.
Declare at the top of a describe block that its tests need a fresh app. One beforeAll (one Appium session) reinstalls the app from the project's buildPath, or wipes its data with appReset: 'clearData':
import { test, useCleanDevice } from '@tulip/appwright';
test.describe.serial('onboarding', () => {
useCleanDevice({ appReset: 'reinstall' });
test('shows the welcome screen', async ({ device }) => {
await expect(device.getByText('Welcome')).toBeVisible();
});
});See Device for the app lifecycle, file access and URL helpers behind it.
To run the test, you can use the npx appwright test command.
npx appwright test --project androidnpx appwright test --project iosAbove commands will trigger runs on android and iOS emulators based on the above configuration.
Each run writes its results into test-results/<run> and its HTML report into
playwright-report/<run>. Pass --run-name <name> to choose the folder name; see
Test results per run.
Once the test is completed, the report is launched automatically in the browser.