TestNG
This page helps you run Reflex Lua scripts from TestNG tests in a Maven project.
Your test logic stays in .lua files. A TestNG listener runs them, and a Lua error fails the test.
Fastest start
Section titled “Fastest start”Copy testng-example into your project. Then:
- In
pom.xml, set your owngroupIdandartifactId, replace the<parent>block, and give the Reflex dependencies an explicit release version. - Rename the package
nl.bqa.reflex.testng.example. - Replace the scripts in
tests/lua/with your own. - Run
mvn test. TherunsLuaPassScripttest should pass.
Add it to an existing project
Section titled “Add it to an existing project”- Set up the Maven repository and token: Access, downloads and Maven.
- Add the dependency. Use the Reflex release version:
<dependency><groupId>nl.bqa.reflex</groupId><artifactId>reflex-testng-core</artifactId><version>X.Y.Z</version></dependency>
- Add the listener and annotate a test method with
@LuaScript. Leave the method body empty:import nl.bqa.reflex.testng.core.annotation.LuaScript;import nl.bqa.reflex.testng.core.listener.ReflexTestNgListener;import org.testng.annotations.Listeners;import org.testng.annotations.Test;@Listeners(ReflexTestNgListener.class)public class LoginTests {@Test@LuaScript("tests/lua/login.lua")public void loginWorks() {}}
Prefer to write Java around the script? Extend ReflexTestBase and call runLua() in your test.
Scripts use the same libraries, steps and locators as everywhere else. See Scripts.
Settings
Section titled “Settings”Set these in src/test/resources/reflex-testng.properties, or as -D system properties:
| Property | Default in the example | Purpose |
|---|---|---|
reflex.lua.root | tests/lua | Folder with your Lua scripts. |
reflex.timeout.ms | 10000 | Timeout per script. |
reflex.keepWorkspace | false | Keep the temporary workspace after the run. |
reflex.headless | true | Run the browser without a window. |
reflex.selenium.docker | false | Run browsers in Docker containers. |
mvn test # all testsmvn test -Dgroups=sanity # one groupmvn test -Dtest=LoginTests#loginWorks # one methodmvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng/smoke.xmlTestNG XML suites work as usual, including parallel="methods" for independent scripts.
Stream results to the dashboard
Section titled “Stream results to the dashboard”Add reflex-testng-dashboard, use ReflexDashboardTestNgListener instead of ReflexTestNgListener, and start the dashboard. Then pass:
mvn test \ -Dreflex.dashboard.enabled=true \ -Dreflex.dashboard.ws.url=ws://localhost:6001/runAdd -Dreflex.dashboard.auth="Bearer <token>" if the dashboard requires it. If streaming fails, the tests still run.