Differences

This shows you the differences between two versions of the page.

Link to this comparison view

remoteagentautoit [2016/09/22 02:36] (current)
Line 1: Line 1:
  
 +===== Remote Agent - AutoIT =====
 +
 +This is an example remote agent to integrate //​TestOptimal//​ with [[http://​www.autoitscript.com/​|AutoIt]],​ an open source automation tool for testing windows applications.
 +
 +The main idea is to have the agent running within AutoIt and connect to //​TestOptimal//​ server to receive the test sequence generated from the model. Because the agent is part of your AutoIt script, it has access to your existing AutoIt scripts to drive/test your windows applications. The execution result is then passed back to //​TestOptimal//​ server to be recorded with the model.
 +
 +Each remote command received from //​TestOptimal//​ server is automatically executed dynamically as a function call. For example the command received "​MBT_start"​ as the first command when the model starts will result in a function call to "​MBT_start"​ (notice the exact same name).
 +
 +The script below can be found in "​script"​ folder in the download package. The file is: DemoAgent.au3. DemoAgent.au3 includes TOAgent.au3 which takes care of the communication with //​TestOptimal//​ server. You should not modify TOAgent.au3.
 +
 +To run this demo, first make sure //​TestOptimal//​ server is started. Next start up AutoIt as you usually do and browse to "​script"​ folder to open DemoAgent.au3.
 +
 +When DemoAgent.au3 is started, you should see a series of dialog windows showing the remote commands it received from the server. Below is DemoAgent.au3 with comments inline to help explain how it works:
 +
 +   ;init sets up communication to your model in this demo "​Demo_RemoteAgent"​
 +   init ("​localhost",​ 8888, "​Demo_RemoteAgent"​)
 +   ​MsgBox(0,​ "​TOAgent",​ "​Starting model execution on TestOptimal server"​)
 +
 +   ; execModel opens the model remotely on TestOptimal server and executes it.
 +   ; two parameters are user id and password. In this demo security has not been enabled.
 +   ​execModel("",​ ""​)
 +
 +   ; wait for a few second for the model execution to be started.
 +   ​MsgBox(0,​ "​TOAgent",​ "​Sleeping for 2 seconds for the model to start."​)
 +   ​sleep(2000)
 +
 +   Local $cmd
 +   ​MsgBox(0,​ "​TOAgent",​ "​AgentID is: " & getAgentID())
 +
 +   ​$showCmd = 1
 +
 +   ; infinite loop until no more remote commands are received
 +   Local $result
 +   Do
 +       ; obtains the remote command from the model running on TestOptimal server
 +       $cmd = getNextCmd()
 +       if ($cmd = ""​) then
 +       ​ Exitloop
 +       endif
 +
 +       If (getStatus() = "​E"​) Then
 +         ​setStatus ("​A",​ getStatsResult())
 +         ​Exitloop
 +       EndIf
 +
 +       if ($showCmd = 1) then
 +  $showCmd = MsgBox(1, "​remoteCmd",​ "​remote cmd is: " & $cmd & @LF & "Press cancel to skip showing this dialog."​)
 +  endif
 +
 +       ; add your logic to execute mbtCmd received from TestOptimal server
 +       ; ​   "​C"​ for completion, "​X"​ for failure, "​E"​ for fatal error (cause MBT to exit)
 +       ​$result = execute($cmd)
 +       if @error then
 +        if @error=1 then
 +          setStatus ("",​ "​noop"​)
 +        else
 +          setStatus ("​X",​ "​@error:​ " & @error & ", result: " & $result)
 +      endif
 +  else
 +    setStatus ("​C",​ $result)
 +  endif
 +   Until $cmd = ""​
 +
 +   ​MsgBox(0,​ "​TOAgent",​ "​TOAgent on AutoIT Finished!"​)
 +
 +   ; stop the model execution (necessary for multiple virtual users)
 +   ​stopExec()
 +
 +   ; wait for couple of seconds for the model to come to stop.
 +   ​Sleep(2000)
 +
 +   ; save execution stats with the model to be reviewed later
 +   ​MsgBox(0,​ "​TOAgent",​ "​Saving the execution results to be viewed with TestOptimal browser..."​)
 +   ​saveStat ("exec from AutoIT agent"​)
 +
 +   ; close the model
 +   ​MsgBox(0,​ "​TOAgent",​ "​Execution summary: " & @LF & getExecSummary())
 +   ​closeModel()
 +
 +   ; Following functions are examples of user defined function to execute the remote command received.
 +   Func MBT_start()
 +  return "​mbtStart executed"​
 +   ​EndFunc
 +
 +   Func MBT_end()
 +  return "​mbtEnd executed"​
 +   ​EndFunc
 +
 +   Func OneQuarter_onentry()
 +  return "​Entering ProductList"​
 +   ​EndFunc
 +
 +   Func OneQuarter_onexit()
 +  return "​Exiting ProductList"​
 +   ​EndFunc
 +
 +   ; we purposely force a failure on addOneQuarter transition
 +   Func OneQuarter_addOneQuarter_action()
 +  setError(3)
 +  return "​addQuarter failed"​
 +   ​EndFunc
 +
 +   Func OneQuarter_addOneQuarter_prep()
 +  return ""​
 +   ​EndFunc
 +
 +   Func OneQuarter_addOneQuarter_verify()
 +  return ""​
 +   ​EndFunc
Print/export
QR Code
QR Code remoteagentautoit (generated for current page)