When working on SETs/Adapter customizations/Addins one of the very annoying activities is 'deploying' your .dll to Tosca after building it:
- Find the directory where the newly built .dll was placed
- Copy the newly built .dll to %TRICENTIS_HOME%\Automation\Framework
- "Oh shit, forgot to 'End Process' the 'Tricentis.Automation.Agent.exe'"
- End Process@Tricentis.Automation.Agent.exe
- Re-find the directory where the newly built .dll was placed
- Finally copy the newly built .dll to %TRICENTIS_HOME\Automation\Framework
- In the case of an Addin-deploy we even need to add killing the actual Tosca Commander client to this checklist.
Let's write a powershell script which takes care of all that. We'll have to write two scripts. One for SET/CustomAdapter deploys and one for Addin deploys. Because of the aforementioned reasons
The SET/CA deploy script is easily done... [added:] actually it was not so easily done. The script posted earlier would often generate error message because the copy-item would be called before the old .dll would truly be released. With the help of stackoverflow we modified the script to be more robust:
#IsFileLocked was literally copied from Stackoverflow
function IsFileLocked([string]$filePath){
Rename-Item $filePath $filePath -ErrorVariable errs -ErrorAction SilentlyContinue
return ($errs.Count -ne 0)
}
$newFile = "[fullpath of new .dll]"
$targetDirectory = "C:\Program Files (x86)\TRICENTIS\TOSCA Testsuite\Automation\Framework"
$TAA_Id = Get-Process -Name "Tricentis.Automation.Agent" -ErrorAction SilentlyContinue
if($TAA_Id)
{
Stop-Process -inputobject $TAA_Id
Wait-Process -inputobject $TAA_Id
}
Do
{
Start-sleep -m 500
} While(IsFileLocked $newFile)
Copy-Item $newFile $targetDirectory -Force
It bugs me that the above script has a hard 500ms wait in it, but I couldn't get the script to consistently work without it and won't waste time on half a second. The only caveat here is that you have to run Powershell in administrator mode. A quick Google showed it would be possible to make the script self-elevating but that's an exercise for another time. The above very simple script seemed to work fine and is a real time saver.
After updating the SETDeploy the AddinDeploy becomes trivial:
function IsFileLocked([string]$filePath){
Rename-Item $filePath $filePath -ErrorVariable errs -ErrorAction SilentlyContinue
return ($errs.Count -ne 0)
}
$newFile = "[fullpath new .dll]"
$targetDirectory = "C:\Program Files (x86)\TRICENTIS\TOSCA Testsuite\ToscaCommander\Addins"
$TAA_Id = Get-Process -Name "TOSCACommander" -ErrorAction SilentlyContinue
if($TAA_Id)
{
Stop-Process -inputobject $TAA_Id
Wait-Process -inputobject $TAA_Id
}
Do
{
Start-sleep -m 500
} While(IsFileLocked $newFile)
Copy-Item $newFile $targetDirectory -Force
Start-Process "C:\Program Files (x86)\TRICENTIS\TOSCA Testsuite\ToscaCommander\TOSCACommander.exe"