views:

668

answers:

2

Greetings,

I have completed developing a suite of tests using Selenium RC and Java and I'm trying to integrate them with the build system so I can run the tests overnight. The process runs like this:

  1. Cruisecontrol does a full build
  2. A cron job on the Cruisecontrol server installs the build on a specific test cluster.
  3. When the build installation is complete a web page is updated with the results of the install (pass/fail).
  4. An application (trigger.jar) running on a client machine (Windows XP) will be monitoring the web page. When it detects a successful install it will start the Selenium tests: java -jar overnightTests.jar.
  5. It is not necessary for the trigger application to do any logging or to capture the exit code for the test suite. All that stuff is handled by the test suite.

I've already written all the pieces but the trigger is giving me trouble.

Here's my code:

try {
    String cmd = "java";
    String jArg = "-jar";
    String program = "overnightTests.jar";
    String aptUrl = "https://apt.qa6.spockmate.com/apt/" ;
    String campaignManagerURL = "http://app01.dev02.sn.spockmate.com:8080/cm/" ;
    String contractDatafile = "C:\\testdata\\MasterDataForSelenium.xls" ;
    String adMapDataDir = "C:\\testdata\\AdMaps\\" ;
    String creativeAssetsFile =  "C:\\testdata\\CreativeAssets\\CreativeAssetsForSeleniumTests.csv";
    String adminURL = "https://admin.qa6.spockmate.com/admin/"; 

    String [] commands = new String[]{cmd, jArg, program, aptUrl, campaignManagerURL, contractDatafile, adMapDataDir, creativeAssetsFile, adminURL};

    Process child = Runtime.getRuntime().exec(commands);

} catch (IOException e) {
    System.out.println("Exception thrown while calling Runtime:");
    System.out.println(e.getCause());
    e.printStackTrace();
}

When the line "Runtime.getRuntime().exec(commands)" executes, the trigger.jar hangs. It doesn't matter if I'm running the app from the DOS command line or from Eclipse. Here's the weird part: once I kill the trigger.jar application (via ctrl-c or Eclipse's stop button) the overnightTests.jar application that I'm trying to trigger will start. This happens every time I run the application. It's as if instead of starting the overnight_tests.jar the tool is being placed in a queue to be started "next". I've tried assigning 'Runtime.getRuntime().exec(commands);' to a Process variable and doing a wait() on the Process and I've tried ignoring the return altogether. The result is always the same.

My questions are:

  1. What is my code missing that would allow it to launch overnightTests.jar in a separate process and forget about it, allowing Selenium to go off on its merry way and do its thing?
  2. For anyone who has faced this problem before, is there an easier, cleaner, less-elaborate solution? I have a great deal of control over the format of the trigger signal and how it is sent and received and my main requirement is that the solution be robust. Anything that works and isn't over-elaborate or complex is worth a try.

Any help or suggestions would make me very happy and make it far more likely that I'll be able finish this project and go on vacation at the end of the month.

+1  A: 

A couple of suggestions:

  • use Ant if you can, I've found it very reliable for invoking Java processes and you have control over things like "spawn" and "fork" (search for "ant java task" for more details). You can find an example here, look at the "jmeter-cycle-heapdump" target (line 159), also look at the usage of the Ant "parallel" / "sequential" elements, I think this will give you some ideas on the test automation that you are attempting :) -- http://code.google.com/p/perfbench/source/browse/trunk/perfbench/build.xml
  • I would try to put all those commands into a normal batch file and try and call that somehow, might be simpler and you don't need to worry about a java process calling another java process, which seems to be the problem
Peter Thomas
+1  A: 

I am not convinced by your setup of triggering a Selenium test suite once an installation has been done?

What are the reasons behind not creating just another project in the CruiseControl that would be triggered nightly? Let say if your core project is XXX, then I would add XXX_nightly tests.

Moreover with some smart <veto> you could trigger the nightly tests only if the core project is in correct status. This setup will allow you to manually force the 'nightly' tests even in the business hours.

Grzegorz Oledzki