Write a Java test
Write a simple test scenario, compile it, and execute it.
Before you begin:
- The tested application is the price application used in the Quick Start: Generate and execute a test scenario.
- All source files are available in GGCDIR/src/samples directory.
-
Begin by running the Genero Ghost Client ggcgen tool to create
a skeleton application.
ggcgen java --skeleton myapp_tests
The myapp_tests_provider.java file is created in the "scenario" package:
/* * Generated using Genero Ghost Client 2.00.06-201905141203 */ package scenario; import com.fourjs.ggc.ScenarioProvider; import com.fourjs.ggc.Scenario; import com.fourjs.ggc.Client; import com.fourjs.ggc.generator.ScenarioChecks; import java.util.concurrent.ConcurrentLinkedDeque; public class myapp_test2_provider implements ScenarioProvider { private final ConcurrentLinkedDeque<Scenario> scenarios; /* Instance initializer */ public myapp_test2_provider() { scenarios = new ConcurrentLinkedDeque<>(); /* Register scenario functions */ scenarios.add(new scenario_0()); } /* Scenario myapp_test2 id: 0 */ private class scenario_0 implements Scenario { @Override public void play(Client client) { } } @Override public Scenario nextScenario() { return scenarios.removeFirst(); } }
In this scenario:- The code begins by importing the Genero Ghost Client Java classes.
- The
myapp_test2_provider()
method implements thecom.fourjs.ggc.ScenarioProvider
interface. - A function (
scenario_0
) with the id of 0 is registered in thescenarios
variable. A test may register multiple test scenarios in this variable. They run in the sequence registered. - A
scenario_0
class is declared. This implements thecom.fourjs.ggc.Scenario
interface, which requires the methodplay
to run the test.
-
To the play method of the
scenario_0
class add code to test an application.For the test, the window name is retrieved from the client and the actioncancel
is triggered./* * Generated using Genero Ghost Client 2.00.06-201905141203 */ package scenario; import com.fourjs.ggc.ScenarioProvider; import com.fourjs.ggc.Scenario; import com.fourjs.ggc.Client; import com.fourjs.ggc.generator.ScenarioChecks; import java.util.concurrent.ConcurrentLinkedDeque; public class myapp_test2_provider implements ScenarioProvider { private final ConcurrentLinkedDeque<Scenario> scenarios; /* Instance initializer */ public myapp_test2_provider() { scenarios = new ConcurrentLinkedDeque<>(); /* Register scenario functions */ scenarios.add(new scenario_0()); } /* Scenario myapp_test2 id: 0 */ private class scenario_0 implements Scenario { @Override public void play(Client client) { String windowTitle = client.getUserInterface().getCurrentWindow().getTitle(); System.out.println("Window title is: " + windowTitle); System.out.println("Exiting with action 'cancel'"); client.wait(100); client.action("cancel"); } } @Override public Scenario nextScenario() { return scenarios.removeFirst(); } }