1. Docs
  2. Reference
  3. Step reference
  4. Code steps: Python and JavaScript

Code steps: Python and JavaScript

When no ready step does what you need, write it as code. A Python step runs on the machine that runs the test; a JavaScript step runs inside the web page. Both can return a value to later steps or decide whether the step passes.

4 min read Updated CustomersAdmins

In short

On this page you can

  • Run your own Python in any project type, and JavaScript in web projects.
  • Return a value to later steps with the output mode Value.
  • Pass or fail the step from code with the output mode Status.
  • Insert ready commands from the Browser Commands List.
  • Generate code from a prompt with AI in web projects.

How to use it

  1. Click Python or JS in the step toolbar.
  2. Write the code in the editor; on the web, Python has a Selenium and a Playwright tab.
  3. Read earlier values with {{tc:name}} inside the code.
  4. Set the output to Value (and a name), Status, or N/A.
  5. Save and run a Dry Run; the log shows the code, the returned value and errors.

Python or JavaScript#

PythonJavaScript
Project typesWEB, MOBILE, DESKTOPWEB only
RunsIn the runner, on the machine that runs the testInside the browser page, like code in the developer console
Can useThe test session (driver in Selenium and Appium, page in Playwright), Python libraries of the runnerThe page’s DOM, window, fetch
EditorWeb: two tabs, Selenium and Playwright; the project’s script language picks which runs. Mobile and desktop: one Script tab.One editor
ConditionsIF / ELIF / ELSE / END through Select an optionNone
ChipPythonJS

Add a code step#

  1. Add the step

    Click Python or JS. The step is added at once; there is no dialog.

  2. Write the code

    Select the step. The right panel shows the code editor. Use Format Code, Enlarge editor and Copy in its toolbar. The folder icon opens the Browser Commands List (see Ready commands).

  3. Use earlier values

    Write {{tc:name}} where you need a variable. It is replaced by its value as text before the code runs.

  4. Choose the output

    Under Output Value choose Value, Status or N/A. For Value, name the variable. See Output modes.

  5. Save and run

    An empty editor blocks saving with “Code body cannot be empty”.

The section How it works? · Example guide under the editor shows a short example for each step type.

Output modes: Value, Status, N/A#

ModeWhat happensUse it for
ValueThe value the code produces is saved as a variable and can be used in later steps as {{tc:name}}.Computing a value: a date, a cleaned number, a random email.
StatusThe produced value is read as pass or fail and sets the step’s status. A false value ends the step as ERROR and stops the case.A check you write yourself.
N/AThe code only runs. Nothing is stored and the status is not affected (unless the code raises an error).Actions: scrolling, setting local storage, closing a pop-up.

What counts as the produced value in Python: an outer-level return; otherwise the last line, if it is an expression; otherwise a variable named result. In JavaScript: the return value. If nothing is produced in Value or Status mode, the value is empty.

Python · Value mode, saved as invoiceDate
from datetime import date, timedelta
(date.today() + timedelta(days=30)).strftime("%d.%m.%Y")
JavaScript · Value mode, saved as price
return "{{tc:priceText}}".replace("$", "").trim();
JavaScript · Status mode: pass only if the cart badge shows 3
return document.querySelector('.cart-badge')?.textContent.trim() === '3';

Variables are put in as text

{{tc:count}} becomes its value before the code runs. Put text values in quotes ("{{tc:name}}") and convert numbers before comparing: int({{tc:count}}) > 10, float(…) for decimals. The log adds a tip when a number is compared with text.

Ready commands#

The folder icon in the editor opens the Browser Commands List: ready snippets (get the page, click, send keys, cookies, waits…). Search Commands, then Add to insert one at the end of the code. The tabs depend on the project type:

  • WEB: Selenium and Playwright.
  • MOBILE: Android and iOS.
  • DESKTOP: Windows and macOS.

Generate code with AI#

In web projects, the prompt field under the editor (“You can generate code by entering a prompt”) writes the code for you when you click Ask. It needs Enable AI in the project’s AI options. In mobile and desktop projects it is not available yet: “AI code generation is not available for mobile / desktop projects yet - nothing was written.” Read generated code before you run it.

At run time#

IF, ELIF, ELSE, END#

A Python step can also be a flow-control step: set Select an option to IF, ELIF, ELSE or END. The code of an IF or ELIF step is the condition. Full procedure and example: Run steps only when a condition is true.

If something goes wrong#

Didn’t find your answer?Write to support with your project name and what you see on screen.

info@smartestqa.ai
© 2026 Selenity Technology · SmartestQAsmartestqa.aiThis page as MarkdownChecked against smarttest-fe predev 2a8c79cc, smarttest-be 633c2a03, smarttest-testsuite 017fcec