Yes, you can add the <testcase> element and use the <tcstatus> element to 
record testcase passes and fails and the testcase passes/fails, etc will 
be shown in the STAX Monitor's "Testcase Info" panel.  You can use a 
<loop> (or <iterate> element) to run multiple testcases where each 
testcase may contain one or more <process> elements (and/or <stafcmd> 
elements, etc).  Each <testcase> as well as each <process> that is run 
will be displayed by the STAX Monitor in the "Active Job Element" panel 
while they are actively running. Also, any messages you send will show up 
in the STAX Monitor's "Messages" panel.

Here's an example of a STAX job that runs 10 tests, where each "test" runs 
a "ls /" command and records a testcase pass or fail depending on if the 
"ls /" command ran successfully or not:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">

<stax>

  <defaultcall function="test"/>

  <function name="test">
    <sequence>

      <script>
        numTests = 10
        command = 'ls /'
        numPasses = 0
        numFails = 0
      </script>

      <loop var="i" from="1" to="numTests">
        <testcase name="'Test%s' % (i)">
          <sequence>

            <!-- Run a command (e.g. "ls /")and return its stdout/stderr 
-->
            <process>
              <location>'local'</location>
              <command mode="'shell'">command</command>
              <stderr mode="'stdout'"/>
              <returnstdout/>
            </process>

            <if expr="RC == 0">
              <sequence>
                <script>
                  msg = '%s: Output from "%s" command:\n%s' % \
                        (STAXCurrentTestcase, command, STAXResult[0][1])
                  numPasses = numPasses + 1
                </script>
                <tcstatus result="'pass'"/>
              </sequence>
              <else>
                <sequence>
                  <script>
                    msg = '%s: "%s" failed with RC=%s, STAFResult=%s, 
STAXResult=%s' % \
                          (STAXCurrentTestcase, command, RC, STAFResult, 
STAXResult)
                    numFails = numFails + 1
                  </script>
                  <tcstatus result="'fail'">msg</tcstatus>
                </sequence>
              </else>
            </if>

            <message log="1">msg</message>

          </sequence>
        </testcase>
      </loop>

      <!-- Return the result -->
      <return>
        '%s Tests:  %s passes, %s fails' % (numTests, numPasses, numFails)
      </return>

    </sequence>
  </function>

</stax>

You can run this STAX job via the STAX Monitor to monitor its results as 
it runs. 

Or you can submit a STAX EXECUTE request to run this STAX job and wait for 
it to complete and return its job result as follows:

# STAF local STAX EXECUTE FILE /stax/runTests.xml WAIT RETURNRESULT
Response
--------
{
  Job ID         : 20
  Start Date-Time: 20130725-10:26:31
  End Date-Time  : 20130725-10:26:33
  Status         : Normal
  Result         : 10 Tests:  10 passes, 0 fails
  Job Log Errors : []
  Testcase Totals: {
    Tests : 10
    Passes: 10
    Fails : 0
  }
}

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:   babuni mishra <bab...@outlook.com>
To:     Sharon Lucas/Austin/IBM@IBMUS, 
Date:   07/25/2013 09:42 AM
Subject:        RE: [staf-users] simple stax script



Hi Sharon,
Thanks a lot for the quick response, i want one more help :

I want to monitor a job with stax , say  i am executing a bunh of tests 
and want to monitor. So here if i'll take previous example:

i'll run ls for 100 time and want to monitor, so for iteration i will use 
loop but for monitoring will it monitor the test lively? Can you please 
share a monitor example for a live scenario.

Thanks

To: bab...@outlook.com
CC: staf-users@lists.sourceforge.net
Subject: Re: [staf-users] simple stax script
From: luc...@us.ibm.com
Date: Thu, 25 Jul 2013 08:07:19 -0500

If you want a STAX job's result to be set to a message then you need to 
return that message from the STAX job's main function using the <return> 
element. 
For example: 

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<!DOCTYPE stax SYSTEM "stax.dtd"> 

<stax> 

  <defaultcall function="test"/> 

  <function name="test"> 
    <sequence> 

      <script>command = 'ls /'</script> 

      <!-- Run a command (e.g. "ls /")and return its stdout/stderr --> 
      <process> 
        <location>'local'</location> 
        <command mode="'shell'">command</command> 
        <stderr mode="'stdout'"/> 
        <returnstdout/> 
      </process> 

      <if expr="RC == 0"> 
        <script>lsOutput = 'Output from "%s" command:\n%s' % (command, 
STAXResult[0][1])</script> 
        <else> 
          <script> 
            lsOutput = '"%s" failed with RC=%s, STAFResult=%s, 
STAXResult=%s' % \ 
                       (command, RC, STAFResult, STAXResult) 
          </script> 
        </else> 
      </if> 

      <message log="1">lsOutput</message> 

      <!-- Get the current date-time --> 
      <script> 
        from time import localtime, strftime 
        currentTime = strftime("%a, %d %b %Y %H:%M:%S", localtime()) 
      </script> 

      <message log="1">'Current date-time: %s' % currentTime</message> 

      <!-- Create a result containing "Hello world", the current 
date-time, and output from "ls /" command --> 
      <script>result = 'Hello world @ %s.\n%s' % (currentTime, 
lsOutput)</script> 

      <!-- Log the result in the STAX Job User Log and send to the STAX 
Monitor messages --> 
      <message log="1">result</message> 

      <!-- Return the result --> 
      <return>result</return> 

    </sequence> 
  </function> 

</stax> 

You can submit a STAX EXECUTE request to run this STAX job and wait for it 
to complete and return its job result as follows: 

# STAF local STAX EXECUTE FILE C:/stax/returnJobResult.xml WAIT 
RETURNRESULT DETAILS 
Response 
-------- 
{ 
  Job ID         : 12 
  Start Date-Time: 20130725-08:02:14 
  End Date-Time  : 20130725-08:02:15 
  Status         : Normal 
  Result         : Hello world @ Thu, 25 Jul 2013 08:02:15. 
Output from "ls /" command: 
Cygwin.bat 
Cygwin.ico 
Thumbs.db 
bin 
cygdrive 
dev 
etc 
home 
lib 
proc 
tmp 
usr 
var 

  Job Log Errors : [] 
  Testcase Totals: { 
    Tests : 0 
    Passes: 0 
    Fails : 0 
  } 
  Testcases      : [] 
} 

For more information on the <return> element, see section "return: Return 
from a Function" in the STAX User's Guide at 
http://staf.sourceforge.net/current/STAX/staxug.html#Header_Return 

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        babuni mishra <bab...@outlook.com> 
To:        "staf-users@lists.sourceforge.net" 
<staf-users@lists.sourceforge.net>, 
Date:        07/25/2013 06:46 AM 
Subject:        [staf-users] simple stax script 



Hi , 
I am a newbie to STAX, wants to use in my automated solution in Linux Env. 

Can any one share me a sample stax script which will return me 
1) hello world message & current date & output of 'ls' (unix command) 

both in STDOUT & in a file. 

I have followed couple of blogs, executed sample stax script aswell, but 
not able to get the result ,  it always comes as 
 Result         : None 


Thanks, 
Bab
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to