woensdag 30 maart 2016

Tosca > {DATE} or {DATE[][][]} function

For some reason I ALWAYS forget what the correct syntax is with this function. So hereby a post to forever remember:

First: a good search term in the Tosca documentation:
DATE AND TIME EXPRESSIONS

Syntax:
{<EXPRESSION>[<Basedate>][<Offset>][<Format>]}

In normal human readable:
{DATE[basedate][offset][format]}

Key-letters for specifying the format:
d
days
M
months
y
years
h
hours
m
minutes
s
seconds

dinsdag 15 maart 2016

Visual Studio & Git & BitBucket: how to get started

I am not very knowledgeable when it comes to version control systems (something I really have to develop myself further in), but luckily many tools work pretty well out of the box. A very simple way to get started with VCS is to use Visual Studio's built-in-Git with BitBucket.

HOW TO:

  • Create a new empty repository in BitBucket
  • Create your to-be-version-controlled project in Visual Studio
  • Add the project to version control and choose 'Git'
  • Go to Team Explorer
    • Go to 'Changes'
    • Type 'initial commit' in the textbox
    • Click to the 'Commit' button
      • Choose 'Commit and push'
    • VS will give an error message that no remote repository is linked to the project
      • In that same error-message-screen will be a textbox where you can add the url of the remote repo.
      • Copy-paste there the URL to your BitBucket repo and...
    • Done!

donderdag 3 maart 2016

Dabbling in TTT > Powershell script to assist with development/deployment

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"