2424import org .openqa .grid .common .GridRole ;
2525import org .openqa .grid .common .RegistrationRequest ;
2626import org .openqa .grid .internal .utils .SelfRegisteringRemote ;
27+ import org .openqa .grid .internal .utils .configuration .CoreRunnerConfiguration ;
2728import org .openqa .grid .internal .utils .configuration .GridHubConfiguration ;
2829import org .openqa .grid .internal .utils .configuration .GridNodeConfiguration ;
2930import org .openqa .grid .internal .utils .configuration .StandaloneConfiguration ;
3536
3637import java .io .File ;
3738import java .io .IOException ;
38- import java .util . Arrays ;
39+ import java .lang . reflect . Method ;
3940import java .util .function .Supplier ;
4041import java .util .logging .ConsoleHandler ;
4142import java .util .logging .FileHandler ;
4647public class GridLauncherV3 {
4748
4849 private static final Logger log = Logger .getLogger (GridLauncherV3 .class .getName ());
50+ private static final String CORE_RUNNER_CLASS =
51+ "org.openqa.selenium.server.htmlrunner.HTMLLauncher" ;
4952
5053 private static abstract class GridItemLauncher {
5154 protected StandaloneConfiguration configuration ;
@@ -57,53 +60,7 @@ void printUsage() {
5760 }
5861 }
5962
60- private static ImmutableMap <GridRole , Supplier <GridItemLauncher >> LAUNCHERS =
61- ImmutableMap .<GridRole , Supplier <GridItemLauncher >>builder ()
62- .put (GridRole .NOT_GRID , () -> new GridItemLauncher () {
63- public void setConfiguration (String [] args ) {
64- configuration = new StandaloneConfiguration ();
65- new JCommander (configuration , args );
66- helpRequested = configuration .help ;
67- }
68-
69- public void launch () throws Exception {
70- log .info ("Launching a standalone Selenium Server" );
71- SeleniumServer server = new SeleniumServer (configuration );
72- server .boot ();
73- log .info ("Selenium Server is up and running" );
74- }
75- })
76- .put (GridRole .HUB , () -> new GridItemLauncher () {
77- public void setConfiguration (String [] args ) {
78- configuration = new GridHubConfiguration ();
79- new JCommander (configuration , args );
80- helpRequested = configuration .help ;
81- }
82- public void launch () throws Exception {
83- log .info ("Launching Selenium Grid hub" );
84- Hub h = new Hub ((GridHubConfiguration ) configuration );
85- h .start ();
86- log .info ("Nodes should register to " + h .getRegistrationURL ());
87- log .info ("Selenium Grid hub is up and running" );
88- }
89- })
90- .put (GridRole .NODE , () -> new GridItemLauncher () {
91- public void setConfiguration (String [] args ) {
92- configuration = new GridNodeConfiguration ();
93- new JCommander (configuration , args );
94- helpRequested = configuration .help ;
95- }
96- public void launch () throws Exception {
97- log .info ("Launching a Selenium Grid node" );
98- RegistrationRequest c = RegistrationRequest .build ((GridNodeConfiguration ) configuration );
99- SelfRegisteringRemote remote = new SelfRegisteringRemote (c );
100- remote .setRemoteServer (new SeleniumServer (configuration ));
101- remote .startRemoteServer ();
102- log .info ("Selenium Grid node is up and ready to register to the hub" );
103- remote .startRegistrationProcess ();
104- }
105- })
106- .build ();
63+ private static ImmutableMap <String , Supplier <GridItemLauncher >> LAUNCHERS = buildLaunchers ();
10764
10865 public static void main (String [] args ) throws Exception {
10966 GridItemLauncher launcher = buildLauncher (args );
@@ -135,6 +92,11 @@ private static GridItemLauncher buildLauncher(String[] args) {
13592 String role = "standalone" ;
13693
13794 for (int i = 0 ; i < args .length ; i ++) {
95+ if (args [i ].equals ("-htmlSuite" )) {
96+ GridItemLauncher launcher = LAUNCHERS .get ("corerunner" ).get ();
97+ launcher .setConfiguration (args );
98+ return launcher ;
99+ }
138100 if (args [i ].startsWith ("-role=" )) {
139101 role = args [i ].substring ("-role=" .length ());
140102 } else if (args [i ].equals ("-role" )) {
@@ -224,4 +186,92 @@ private static void configureLogging(StandaloneConfiguration configuration) {
224186 }
225187 }
226188 }
189+
190+ private static ImmutableMap <String , Supplier <GridItemLauncher >> buildLaunchers () {
191+ ImmutableMap .Builder <String , Supplier <GridItemLauncher >> launchers =
192+ ImmutableMap .<String , Supplier <GridItemLauncher >>builder ()
193+ .put (GridRole .NOT_GRID .toString (), () -> new GridItemLauncher () {
194+ public void setConfiguration (String [] args ) {
195+ configuration = new StandaloneConfiguration ();
196+ new JCommander (configuration , args );
197+ helpRequested = configuration .help ;
198+ }
199+
200+ public void launch () throws Exception {
201+ log .info ("Launching a standalone Selenium Server" );
202+ SeleniumServer server = new SeleniumServer (configuration );
203+ server .boot ();
204+ log .info ("Selenium Server is up and running" );
205+ }
206+ })
207+ .put (GridRole .HUB .toString (), () -> new GridItemLauncher () {
208+ public void setConfiguration (String [] args ) {
209+ configuration = new GridHubConfiguration ();
210+ new JCommander (configuration , args );
211+ helpRequested = configuration .help ;
212+ }
213+
214+ public void launch () throws Exception {
215+ log .info ("Launching Selenium Grid hub" );
216+ Hub h = new Hub ((GridHubConfiguration ) configuration );
217+ h .start ();
218+ log .info ("Nodes should register to " + h .getRegistrationURL ());
219+ log .info ("Selenium Grid hub is up and running" );
220+ }
221+ })
222+ .put (GridRole .NODE .toString (), () -> new GridItemLauncher () {
223+ public void setConfiguration (String [] args ) {
224+ configuration = new GridNodeConfiguration ();
225+ new JCommander (configuration , args );
226+ helpRequested = configuration .help ;
227+ }
228+
229+ public void launch () throws Exception {
230+ log .info ("Launching a Selenium Grid node" );
231+ RegistrationRequest
232+ c =
233+ RegistrationRequest .build ((GridNodeConfiguration ) configuration );
234+ SelfRegisteringRemote remote = new SelfRegisteringRemote (c );
235+ remote .setRemoteServer (new SeleniumServer (configuration ));
236+ remote .startRemoteServer ();
237+ log .info ("Selenium Grid node is up and ready to register to the hub" );
238+ remote .startRegistrationProcess ();
239+ }
240+ });
241+
242+ try {
243+ Class .forName (CORE_RUNNER_CLASS , false , GridLauncherV3 .class .getClassLoader ());
244+
245+ launchers .put ("corerunner" , () -> new GridItemLauncher () {
246+ @ Override
247+ void setConfiguration (String [] args ) {
248+ configuration = new CoreRunnerConfiguration ();
249+ new JCommander (configuration , args );
250+ helpRequested = configuration .help ;
251+ }
252+
253+ @ Override
254+ void launch () throws Exception {
255+ Class <?> coreRunnerClass = Class .forName (CORE_RUNNER_CLASS );
256+ Object coreRunner = coreRunnerClass .newInstance ();
257+ Method mainInt = coreRunnerClass .getMethod ("mainInt" , String [].class );
258+
259+ CoreRunnerConfiguration runnerConfig = (CoreRunnerConfiguration ) this .configuration ;
260+ String [] args = new String [] {
261+ /* Results file */ runnerConfig .htmlSuite .get (3 ),
262+ /* suite */ runnerConfig .htmlSuite .get (2 ),
263+ /* start url */ runnerConfig .htmlSuite .get (1 ),
264+ /* multi window */ "true" ,
265+ /* browser string */ runnerConfig .htmlSuite .get (0 ),
266+ };
267+ Integer result = (Integer ) mainInt .invoke (coreRunner , (Object ) args );
268+ System .exit (result );
269+ }
270+ });
271+ } catch (ReflectiveOperationException e ) {
272+ // Do nothing. It's fine.
273+ }
274+
275+ return launchers .build ();
276+ }
227277}
0 commit comments