Skip to main content

Codegen

Codegen records the taps and typing you perform on a real device and turns them into a runnable taqwright spec. As you drive the app in a browser-based inspector, it picks a stable locator for each element you touch and appends a line of source to the test. It is the fastest way to a first test, and a quick way to discover the right locator for a tricky element.

Start codegen

npx taqwright codegen --project android

This opens the inspector in your browser at http://localhost:4280. codegen is shorthand for inspect --record, so recording arms automatically the moment you connect to a device.

OptionDescription
-c, --config <file>Configuration file. Default: taqwright.config.{ts,mts,js,mjs}.
--project <name>Project to record against. Default: the first project in config.
--port <n>Preferred local port for the inspector UI. Default: 4280.
--host <host>Host to bind the inspector UI. Default: localhost.
--no-openDo not automatically open the browser.

See Command line for the full CLI.

Connect to a device

The inspector opens on a setup page. Connect through a local emulator or device (taqwright starts Appium for you if it is not already running) or a cloud provider (BrowserStack or LambdaTest, with credentials read from the environment). Once connected, a live view of the device appears and recording begins.

Record actions

Interact with the device view and each action is appended to the generated spec. Codegen records the same actions you would write by hand: tap, double tap, long press, fill, clear, swipe, scroll, pinch, drag, check and uncheck, focus and blur, key presses, and selectOption for native pickers. See Actions for what each does.

Pick a locator

Tap an element and codegen proposes a locator for it. It verifies candidate selectors against the live screen and ranks them by uniqueness first, then stability, preferring attribute-based locators over positional ones:

  • Android: getById (resource-id) is preferred, then getByUiSelector, then getByXpath.
  • iOS: getById (accessibility id) is preferred, then getByPredicate, then getByClassChain, then getByXpath.

When more than one element matches, codegen disambiguates with .nth(i). See the locator strategies in Writing tests.

Record assertions

Beyond actions, you can record assertions from the inspector, visibility, text, value, checked state, count, attribute, and the rest. They emit as expect(...) matchers or locator.assert*() calls. See Assertions.

The generated spec

The recording is a complete, runnable spec:

tests/recorded.spec.ts
import { test, expect } from '@taqwright/taqwright';

test('recorded test', async ({ mobile }) => {
await mobile.getById('username_field').fill('emma@demoapp.com');
await mobile.getById('password_field').fill('10203040');
await mobile.getById('login_btn').click();
await expect(mobile.getByText('View All')).toBeVisible();
});

Save and run

Export the spec from the inspector to your project's test directory (it is written as recorded.spec.ts by default, with a native save dialog on macOS). It lands under tests/ ready to run:

npx taqwright test

Explore without recording

To browse the live UI tree and build locators without recording anything, open the same inspector in explore mode:

npx taqwright inspect --project android

For the natural-language and recording overview, see Generating tests; for the commands, see Command line.