Play test cases use normal Playwright code with Leapwork helpers on top. Keep each user action or validation as one leapwork.step(...) so the test stays readable, traceable, and easy to replay.
Core building blocks
|
Helper |
Use for |
Example |
|---|---|---|
|
|
Create one atomic test step |
|
|
|
Set shared runtime behavior |
|
|
|
Read an input variable |
|
|
|
Save a result for later steps |
|
|
|
Verify the current page visually |
|
Minimal example
import { expect } from "@playwright/test";
leapwork.configuration({
timeoutMs: 5000,
enableSelfHeal: true,
});
const email = leapwork.variables.get("email", leapwork.storage.PERMANENT);
const page = await leapwork.step("Open the login page", async () => {
return await leapwork.launch(leapwork.run.url);
});
await leapwork.step("Fill the email field", async () => {
const emailInput = page.getByLabel("Email", { exact: true });
await expect(emailInput).toHaveCount(1);
await emailInput.fill(String(email ?? ""));
}, {
action: "input",
});
await leapwork.step("Click Sign in", async () => {
const signInButton = page.getByRole("button", { name: "Sign in", exact: true });
await expect(signInButton).toHaveCount(1);
await signInButton.click();
}, {
action: "click",
});
await leapwork.step("Verify the dashboard heading", async () => {
await expect(page.getByRole("heading", { name: "Dashboard", exact: true })).toBeVisible();
}, {
action: "validate",
});
Visual validation
Use a screenshot assertion when the expected state is visual and hard to express with a single locator.
await leapwork.step("Validate the signed-in page visually", async () => {
await assertScreenshot("The page shows the dashboard with the main navigation visible");
}, {
action: "validate",
});
Saving values for later steps
const orderId = await leapwork.step("Read the order id", async () => {
return await page.getByTestId("order-id").innerText();
});
leapwork.variables.set("orderId", orderId, leapwork.storage.LOCAL);
How to add testdata variables as a separate TS asset and use in multiple TCs
-
Create a new typescript asset.
-
Add your functions variables there and export them.
Plain Text
export const testVar = "testVal";
export function doSomething() {
console.log("Do something");
}
-
Now create a new test case.
-
Drag and drop this in references section if you just want to import variables and functions else if you want to execute it something then drop it in steps sections.
-
Go to playwright section and import and use your functions and variables like you do in playwright.
-
An import statement will be created automatically as soon as typescript asset is dropped.
Plain Text
import { StepTest, testVar, doSomething } from "@assets/Add to basket and basket build-up/Step test";
console.log(testVar);
doSomething();
Good habits
-
Use one
leapwork.step(...)per business action. -
Add
action: "click","input", or"validate"so Play classifies the step correctly. -
Use Playwright
expect(...)for DOM-based checks andassertScreenshot(...)for visual checks.