Skip to main content

Test Scripts

A test script is runnable Java automation code that TestFlair writes for one of your test cases, using Selenium or Playwright. The AI first walks through the test case in a real browser against your application, then writes code that repeats exactly what it verified.

  • Who can generate Project Admin, QA Manager, Tester (and workspace Owners and Coordinators)
  • Costs Flairs, per script generated. The dialog shows an estimate and your balance before you confirm
  • Where Generate from the Test Cases tab; manage the results on the Test Scripts tab
  • You need A test case with a URL, the address of the page the test starts on

How a script is made​

  1. YouPick test cases and a framework
  2. Open a cloud browser at the test case URL
  3. If anyReplay preconditions
  4. AIAI explores your app step by step
  5. RecordingRecording of verified steps
  6. AIWrite Java code that mirrors it
  7. AICompile check and automatic fixes
  8. OutcomeScript ready to run
Every script is built from a real walk through your application, not written from the test case text alone.
  1. Exploration. TestFlair opens a browser in the cloud at the test case's URL. The AI performs the test case's steps one by one against your application, with your test data, and checks each step's expected result. When it takes a wrong turn it goes back to the last step that passed and tries again, so detours don't end up in your script.
  2. Recording. As it works, TestFlair records the exact interactions that passed: which element was clicked or typed into, the values entered, the checks made and the page the test ends on. Values that come from your test data stay linked to that test data rather than being copied into the code.
  3. Code generation. The script is written to perform exactly the recorded actions and assert exactly the recorded checks, using element locators that were proven to work during the exploration.
  4. Compile check. The generated code is compiled, and compilation errors are fixed automatically before the script is marked complete.

Why the recording matters​

Because the script mirrors a walk-through that actually succeeded against your application, it is far less likely to click the wrong element, skip a step or assert something your app never shows. You don't need to do anything to turn recording on; it happens on every generation.

The recording is also what makes test case preconditions work. When a test case starts after another one (for example "Log in" before "Edit profile"), TestFlair replays the precondition's recording to reach the right starting point before exploring the dependent case. A precondition can only be used once its own script was generated with every step passing. If it can't, the test case shows why, for example:

MessageWhat to do
…has no test script yetGenerate the precondition's script first.
…last script generation did not pass every stepRegenerate the precondition's script.
…recording uses an action that cannot be replayedThe precondition used something replay can't repeat (such as a file upload). Regenerate it, or change its steps.
…recording failed its last replayThe application changed since it was recorded. Regenerate the precondition's script.
…was edited after its script was generatedRegenerate the precondition's script so the recording matches the steps.

If an exploration doesn't pass every step, TestFlair still writes a script from what the AI did. That script is worth reviewing before you rely on it, and the test case can't serve as a precondition until it is regenerated.

Generating scripts​

Choosing the language and framework for a script

Scripts are generated from the Test Cases tab. Each test case needs a URL; use Add URL on the test case (or on several selected test cases) to set one.

  1. Choose test cases Select test cases in the table and click Generate test scripts in the selection bar, or use the Generate test scripts icon on a single row. The Generate test scripts button in the page header generates for the project's test cases when nothing is selected.
  2. Pick language and framework In How would you like to generate your script?, the language is Java and you choose Selenium or Playwright. TestFlair preselects the framework you used last time (Playwright the first time).
  3. Check the cost The dialog shows the estimated cost for the number of scripts and your current Flair balance.
  4. Confirm Click Generate Test Script. The cards appear on the Test Scripts tab straight away with a Generating... tag.

You can also generate from a test case's drawer with Generate Test Script.

Framework locked by preconditions

A test case runs in the same browser as its preconditions, so they must use the same framework. If a selected test case has a precondition whose script was built with Selenium, the picker shows Locked to Selenium and the other option is disabled. If test cases that depend on the selection use the other framework, the picker warns that they will be blocked until they are regenerated too.

While a test case's script is generating, you can't edit, delete or regenerate that test case; its actions show Test script generation in progress.

Languages and frameworks​

ChoiceOptions
LanguageJava
FrameworkSelenium or Playwright

Both frameworks run in a Chromium-based browser. Scripts generated from an AI editor through the MCP server are also Java.

Following generation​

A script generating inside a batch, with the live view icon

Generation takes a couple of minutes per script and runs in the background, so you can keep working.

  • Progress indicator. A panel in the corner of the app lists your running jobs (script generation, executions and bug generation) with a ring showing how many have finished, for example 2 of 5 items completed. Click an entry to jump to it. Finished entries stay until you dismiss them, and the panel only shows jobs from the workspace you are in.
  • Batches. Scripts generated together are grouped under a Batch header with a done count (for example 3/4) until all of them finish.
  • Generation details. Click a generating card (or choose Generation details from its menu) to open the live view:
TabShows
StreamThe live cloud browser next to the Action Log (every action the AI took, with a tick or a cross) and the Generation Logs. See Watching the AI Explore.
LogsThe generation log.
CodeThe code once it has been written.

While the AI works, an Agent Thinking box explains what it is doing next.

Stopping a generation​

Use Stop on a card's menu, in the drawer, in the selection bar for selected cards, or in the page header to stop everything that is generating. The confirmation reminds you that the Flairs already used are not refunded. A stopped script shows Generation cancelled and can be regenerated.

The Test Scripts tab​

The Test Scripts tab with a generated script

Every test case that has a script appears as a card showing its code, name, status, URL, language, framework and the number of linked bugs.

ControlWhat it does
All / Completed / FailedQuick status toggle
Search and filtersSearch by name; filter by Status (Generating/Running, Completed, Failed) and Automation framework
Show codeExpands the card to show the code, or switch to Logs
Run iconRuns the script, or reruns it. See Test Execution
RegenerateShown instead of Run when generation failed or was cancelled
⋯ menuStop, Generation details, Execution history, Export, Copy script ID, Delete

Select cards to act on several at once: Run, Rerun, Regenerate, Stop, Export and Delete appear in the selection bar when they apply. The page's ⋯ menu exports or deletes all scripts. Deleting a script keeps the test case and sets it back to Pending.

Copy script ID copies the ID you need to run the script from a CI pipeline. See Git Integrations.

Status tags​

TagMeaning
Generating...The AI is exploring or writing code
Generation completedThe script is ready to run
Generation failedGeneration didn't finish. Regenerate it
Generation cancelledSomeone stopped it

Once a script has been run, the card shows the latest execution result instead (for example Execution Success or Execution Failed). See Test Execution.

Reading and editing the code​

Click a finished card to open its drawer, or maximize the drawer to a full page.

TabShows
CodeThe script, editable in a code editor
LogsThe generation log
Execution historyEvery run of this script
PropertiesThe script's details, such as its test case and when it was created (drawer only)

Scripts follow the Page Object Model. The Classes list on the left of the code shows:

  • a base class with the browser setup shared by the test,
  • the test class with the test itself,
  • one page class per page of your application, holding that page's elements and actions.

Pick a class to view or edit it, then click Save. If you close with unsaved changes, TestFlair asks before discarding them. The drawer footer also has Run (or Rerun), and Regenerate for a failed script.

tip

Regenerating replaces your edits with a fresh script. If you have changed the code by hand, export it first.

Exporting​

Export downloads a .zip containing a ready-to-run Maven project: the Java sources, a pom.xml, a testng.xml and a README. A script with preconditions is exported together with them so it runs on its own. Export works for completed scripts, one at a time or several at once.

Troubleshooting​

"To generate test scripts you need to add URL to at least 1 test case"

  • Add a URL to the test cases you want scripts for, on the Test Cases tab.

Generation failed

  • Open Generation details and read the Action Log and Generation Logs to see where it stopped. Common causes: the URL isn't reachable from the internet (see Testing local applications), the login data in your test data is wrong, or a step describes something the page doesn't have. Fix the test case or its test data, then Regenerate.

The framework option is disabled

  • A precondition of the test case uses the other framework. Generate with that framework, or regenerate the precondition first.

The Generate button is greyed out

  • Your Flair balance is below the estimated cost. See Billing.

Next Steps​