Skip to content

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.

Copy testng-example into your project. Then:

  1. In pom.xml, set your own groupId and artifactId, replace the <parent> block, and give the Reflex dependencies an explicit release version.
  2. Rename the package nl.bqa.reflex.testng.example.
  3. Replace the scripts in tests/lua/ with your own.
  4. Run mvn test. The runsLuaPassScript test should pass.
  1. Set up the Maven repository and token: Access, downloads and Maven.
  2. 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>
  3. 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.

Set these in src/test/resources/reflex-testng.properties, or as -D system properties:

PropertyDefault in the examplePurpose
reflex.lua.roottests/luaFolder with your Lua scripts.
reflex.timeout.ms10000Timeout per script.
reflex.keepWorkspacefalseKeep the temporary workspace after the run.
reflex.headlesstrueRun the browser without a window.
reflex.selenium.dockerfalseRun browsers in Docker containers.
Terminal window
mvn test # all tests
mvn test -Dgroups=sanity # one group
mvn test -Dtest=LoginTests#loginWorks # one method
mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng/smoke.xml

TestNG XML suites work as usual, including parallel="methods" for independent scripts.

Add reflex-testng-dashboard, use ReflexDashboardTestNgListener instead of ReflexTestNgListener, and start the dashboard. Then pass:

Terminal window
mvn test \
-Dreflex.dashboard.enabled=true \
-Dreflex.dashboard.ws.url=ws://localhost:6001/run

Add -Dreflex.dashboard.auth="Bearer <token>" if the dashboard requires it. If streaming fails, the tests still run.