Skip to main content

How to send test results to Vansah from C# (.NET)

Use the Vansah C# binding to automatically send test runs, step logs, results and screenshots from your .NET automation directly to Vansah Test Management for Jira.

Overview

The Vansah C# binding is a single class, VansahNode.cs, that you add to your test project and call from your existing tests. It works with Selenium, Playwright (.NET), NUnit, xUnit, MSTest and other .NET frameworks, and connects to the Vansah REST API.

Before you begin

Step-by-step

Step 1: Add the NuGet dependency

The binding depends on Newtonsoft.Json. Add it with the .NET CLI:

…or as a PackageReference in your .csproj:

Step 2: Add the VansahNode class to your project

  1. Copy the file VansahNode.cs.

  2. Paste it into your test project. The class lives in the "Vansah" namespace, so add "using Vansah;" where you use it.

Step 3: Configure the token, URL and Space Key

Create a VansahNode instance and set your token, API URL, and Space Key. The Space Key is your Jira project key and is required for API v2.

Prefer to keep the token out of source control? Read it from an environment variable:

Where to find these: generate your token in Create a Vansah API Token, and copy your API URL from Vansah API Connect URL.

Step 4: Create a test run

Choose the run type that matches how your test case is organised. Set the matching context (issue key, folder path, or test plan key) first, then create the run.

Against a Jira Work item

Against a Test Folder

The folder path goes into the TestFolderID property. Not sure of the path? See Getting the folder path of a test folder. The path must contain a "/" and must not start with "/".

Against an Advanced Test Plan (ATP)

Against a Standard Test Plan (STP)

Note: Test plan runs target iteration 1 by default. To record results against a different iteration, call app.setTestPlanIteration(n) - where n is 1 to 5 - before AddTestRunFromAdvancedTestPlan or AddTestRunFromStandardTestPlan. This applies to Test Plan runs only, not Jira-issue or folder runs.

Step 5: Log your test results

For step-by-step tests, log a result for each step. The result can be a string (NA, FAILED, PASSED, UNTESTED - case-insensitive; note NA, not N/A) or an int (0 = N/A, 1 = FAIL, 2 = PASS, 3 = Not tested).

Tip: For a single overall result with no steps, use a Quick Test instead: app.AddQuickTestFromJiraIssue("TEST-C1", 2); // 2 = PASS

Step 6: Attach a screenshot (optional)

Pass a screenshot file path (string) to AddTestLog or UpdateTestLog and the binding uploads it and links it to the log.

Step 7: Enable debug logging (optional)

If a run or log is not appearing as expected, turn on payload logging to see the exact JSON the binding sends to Vansah.

Step 8: Run your tests and view results in Vansah

  1. Run your automated tests as usual.

  2. Open the linked Jira issue, test folder, or test plan in Vansah.

  3. Confirm the new test run and its step logs (and any screenshots) appear.

Full example (Folder, ATP and STP)

Method reference

  • AddTestRunFromJiraIssue(string testCase)

    Creates a run linked to a Jira issue (set via the JiraIssueKey property).

  • AddTestRunFromTestFolder(string testCase)

    Creates a run under a Vansah test folder (set via the TestFolderID property).

  • AddTestRunFromAdvancedTestPlan(string assetType, string testCase)

    Creates a run under an ATP. assetType is "folder" or "issue".

  • AddTestRunFromStandardTestPlan(string testCase)

    Creates a run under a Standard Test Plan.

  • AddTestLog(result, comment, step [, screenshotPath])

    Logs one step result (+ optional screenshot path). result: string NA/FAILED/PASSED/UNTESTED or int 0-3.

  • UpdateTestLog(result, comment [, screenshotPath])

    Updates the most recent log with a new result/comment/screenshot.

  • AddQuickTestFromJiraIssue(string testCase, result)

    Single overall result against a Jira issue (string or int).

  • AddQuickTestFromTestFolders(string testCase, result)

    Single overall result under a test folder (string or int).

  • RemoveTestRun()

    Deletes the most recently created test run.

  • RemoveTestLog()

    Deletes the most recently created test log (a fresh Untested placeholder is put back for that step).

Configuration (properties and setter methods)

  • SetVansahToken(property) - Vansah Connect token used to authenticate requests.

  • SetVansahURL(property) - Vansah API base URL

  • SpaceKey(property) - Space Key (Jira project key). Required for API v2.

  • TestFolderID(property) - Test folder path. Must contain "/" and must not start with "/".

  • JiraIssueKey(property) - Jira issue key to attach runs/logs to.

  • TestPlanAssetType(property) - For ATP runs: "folder" or "issue". Defaults to "folder".

  • SprintName(property) - Optional. Associates runs with a sprint.

  • release_Name(property) - Optional. Associates runs with a release/version.

  • environment_Name(property) - Optional. Tags runs with an environment (e.g. SYS, UAT).

  • setAdvancedTestPlanKey(string key) - Advanced Test Plan key (e.g. KAN-P17).

  • setStandardTestPlanKey(string key) - Standard Test Plan key (e.g. KAN-P18).

  • setTestPlanIteration(int iteration) - Optional. Targets a specific STP/ATP iteration (1-5). Defaults to 1 if not set.

  • setDebug(bool debug) - Enables request-payload logging (the token is never printed).

Related articles

Did this answer your question?