Sunday, September 12, 2010

Distribute your test suites by STAF(STAX)

STAF is a good Open source "test automation" framework which developed by IBM. I am currently using STAF(STAX) to distribute my test Suites which are organized by TestNG, it is improve your efficiency.

Here is a simple sample how I zip, transfer and execute My Test on 2 machines(please format this XML by yourself, if you need to look at it):

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
 <!DOCTYPE stax SYSTEM "stax.dtd">  
 <!-- New document created with EditiX at Fri Jul 09 15:35:49 CST 2010 -->  
 <stax>  
 <script>machinelist = ['Machinename1','Machinename2']</script>  
 <defaultcall function="ZipTest"></defaultcall>  
 <function name="ZipTest">  
 <sequence>  
 <stafcmd>  
 <location>'localhost'</location>  
 <service>'zip'</service>  
 <request>'ADD ZIPFILE D:/Raft_Project/TestPlan.zip DIRECTORY D:/Raft_Project/TestPlan RECURSE RELATIVETO D:/Raft_Project' </request>  
 </stafcmd>  
 <call function="'sleep'"></call>  
 <call function="'DistributionTest'"></call>  
 <call function="'sleep'"></call>  
 <call function="'CleanupTest'"></call>  
 </sequence>  
 </function>  
 <function name="DistributionTest">  
 <paralleliterate var="machinename" in="machinelist">  
 <sequence>  
 <stafcmd>  
 <location>machinename</location>  
 <service>'fs'</service>  
 <request>'DELETE ENTRY D:/Raft_Project/TestPlan RECURSE CONFIRM' </request>  
 </stafcmd>  
 <call function="'sleep'"></call>  
 <stafcmd>  
 <location>'local'</location>  
 <service>'fs'</service>  
 <request>'COPY FILE D:/Raft_Project/TestPlan.zip TODIRECTORY D:/Raft_Project/ TOMACHINE %s' % machinename </request>  
 </stafcmd>  
 <call function="'sleep'"></call>  
 <stafcmd>  
 <location>machinename</location>  
 <service>'zip'</service>  
 <request>'UNZIP ZIPFILE D:/Raft_Project/TestPlan.zip TODIRECTORY D:/Raft_Project/'</request>  
 </stafcmd>  
 <call function="'sleep'"></call>  
 <stafcmd>  
 <location>machinename</location>  
 <service>'fs'</service>  
 <request>'DELETE ENTRY D:/Raft_Project/TestPlan.zip RECURSE CONFIRM'</request>  
 </stafcmd>  
 <process>  
 <location>machinename</location>  
 <command mode='"shell"'>'Runner.bat'</command>  
 <workdir>R'D:\Raft_Project\TestPlan\TestRunner_Module1'</workdir>  
 <returnstdout/>  
 <returnstderr/>  
 </process>  
 </sequence>  
 </paralleliterate>  
 </function>  
 <function name="CleanupTest">  
 <stafcmd>  
 <location>'localhost'</location>  
 <service>'fs'</service>  
 <request>'DELETE ENTRY D:/Raft_Project/TestPlan.zip RECURSE CONFIRM'</request>  
 </stafcmd>  
 </function>  
 <function name="sleep">  
 <stafcmd>  
 <location>'localhost'</location>  
 <service>'delay'</service>  
 <request>'delay 6000'</request>  
 </stafcmd>  
 </function>  
 </stax>  
hope it helps! More detail instruction, please go to STAF official website:http://staf.sourceforge.net/

PS: you may need to modify your under STAF/bin/, so that it can avoid some restrictions.
 # Turn on tracing of internal errors and deprecated options  
 trace enable tracepoints "error deprecated"  
 # Enable TCP/IP connections  
 interface ssl library STAFTCP option Secure=Yes option Port=6550  
 interface tcp library STAFTCP option Secure=No option Port=6500  
 # Set default local trust  
 #trust machine local://local level 5  
 trust default level 5  
 # Add default service loader  
 serviceloader library STAFDSLS  
 SERVICE STAX LIBRARY JSTAF EXECUTE \  
 D:/STAF/services/stax/STAX.jar OPTION J2=-Xmx384m  
 SERVICE EVENT LIBRARY JSTAF EXECUTE \  
 D:/STAF/services/stax/STAFEvent.jar  
 SET MAXQUEUESIZE 10000  
 SERVICE Cron LIBRARY JSTAF EXECUTE D:\STAF\services\cron\STAFCron.jar  

2 comments:

  1. Interesting idea. What does your script Runner.bat look like? Do you report test results back to a central machine?

    ReplyDelete
  2. @morphoiz:
    Runner.bat is quite simple from my side to just start my java project, you can create yours freely:
    @echo off
    java -cp ..\Classes;..\lib\*;
    raft.engine.TestEngine > log.txt

    Right now, I did not collect multiple remote machines' test result to a central one, but it does not difficult to do so by STAF/STAX; However, it will be difficult if you are intent to merge all the results into Single report :)

    ReplyDelete