Universal Agent Code Snippets

When you configure Universal Agent you will see options to use Pre-Execute Scripts Snippets and Execute Command Snippets to generate boilerplate scripts for the Universal Agentto execute. This article shows how to use these options from qTest Launch or Automation Host.

Pre-Execute Scripts Examples

This section allows you to generate snippets of scripts that will execute when the Universal Agentkicks off its execution. Select the appropriate link under the Examples section to generate the scripts to the Pre-Execute Script editor.

git clone

This snippet will generate script to clone a repository into a newly created directory.

# navigate to directory where your code are located
cd /working/path/on/this/machine

# copy the repo onto this machine; probably needs to be done once unless you clean up after and remove the directory
git clone https://github.com/YourOrganization/YourRepo.git

git pull

This snippet generates scripts to incorporates changes from a remote repository into the current branch.

# navigate to directory where your code are located
cd /working/path/on/this/machine

# pull the latest code onto the machine
git pull

svn update

This snippet generates script to brings changes from the repository into your working copy.

cd /working/path/on/this/machine
svn update

tfs copy and get

This snippet generates scripts to create a workspace and get (download) either the latest version or a specified version of one or more files or folders from Team Foundation Server to the workspace.

cd /working/path/on/this/machine
tf workspace -new Beta1 -collection:http://myserver:8080/tfs/DefaultCollection
tf get

Execute Command Examples

This section lets you generate snippets of scripts that will execute when the Universal Agentkicks off its execution. Select the appropriate link under the Examples section to generate the scripts to the Execute Command editor. 

Execute Java JUnit Tests

This snippet generates scripts to execute Java JUnit tests.

java -cp "/absolute/path/to/compiled/classes" "org.junit.runner.JUnitCore" "your.package.TestClassName"
// Example:
// java -cp "/usr/local/junit-sample/target/*" "org.junit.runner.JUnitCore" "sample.SuitTest"

Execute Postman.Tests

This snippet will generate scripts to execute Postman.tests.

You must install newman command line tool globally in order for the command to be fully executed. For instructions to install newman, refer to this article.
newman run "/path/to/<your-collection>.json" --reporters cli,json --reporter-json-export "/path/to/<your-postman-results>.json" --suppress-exit-code --no-color

Execute Tosca Tests

This snippet generates scripts to execute Tosca tests.

Make sure the host machine has Tosca installed in order for the command to be fully executed.
# Windows
"C:\Program Files (x86)\TRICENTIS\Tosca Testsuite\ToscaCI\Client\ToscaCIClient.exe" -c "\path\to\test-config.xml" -t junit -r "\path\to\test-result.xml"
# Linux/Mac
java -jar /path/to/ToscaCIClient.jar -c "/path/to/test-config.xml" -t junit -r "/path/to/result.xml"

Magic Variables Snippets

In the Execute Command examples section, you will also have an ability to generate code snippets that use Magic Variables.

Universal Agentonly assigns contextual values for these variables at run time if the selected Executor is either node, python or python3.

$PROJECT_DATA snippet

This snippet generates code that uses $PROJECT_DATA variable in the Execute Command. The example below shows how the snippet looks like specific to the selected Executor.

Executor: node

Executor: python / python3

$TESTCASES_AC snippet

This snippet generates code that uses $TESTCASES_AC variable in Execute Command. The example below shows how the snippet looks like specific to the selected Executor.

Executor: node

Executor: python / python3

$TESTRUNS_LIST snippet

This snippet generates code that uses $TESTRUNS_LIST variable in Execute Command. The example below shows how the snippet looks like specific to the selected Executor.

Executor: node

Executor: python / python3