I am trying to run multiple testsuites for Selenium-rc programmatically with Selenese. I analyzed the java code for the selenium-server-standalone-2.37.0.jar
and determined that I had to use the main method of the GridLauncher
class. And because I want to run multiple test suites, i put in a loop.
for (String[] arguments : argumentsList) {
GridLauncher.main(arguments);
}
The first problem I encountered was that GridLauncher
uses System.exit()
to close itself. But that causes my process to stop also. The way that I solved this was to make the System.exit()
throw an exception. This idea I got from this question in Stackoverflow.
private static class ExitTrappedException extends SecurityException {
static void forbidSystemExitCall() {
final SecurityManager securityManager = new SecurityManager() {
@Override
public void checkPermission( Permission permission ) {
if( "exitVM".equals( permission.getName() ) ) {
throw new ExitTrappedException() ;
}
}
@Override
public void checkExit(int status) {
throw new SecurityException();
}
} ;
System.setSecurityManager( securityManager ) ;
}
static void enableSystemExitCall() {
System.setSecurityManager( null ) ;
}
}
for (String[] arguments : argumentsList) {
ExitTrappedException.forbidSystemExitCall();
try {
GridLauncher.main(arguments);
} catch (SecurityException se) {
//catching System.exit()
} finally {
ExitTrappedException.enableSystemExitCall() ;
}
}
The problem that I encounter now is that the stream doesn't close and i get an exception when the loop tries to perform the Selenium test: WARN - Failed to start: SocketListener1@0.0.0.0:4444
I tried to look for ways to close the stream but can't find anything. Is it possible to close it? If so, how?