Showing posts with label Environment Variable. Show all posts
Showing posts with label Environment Variable. Show all posts

Thursday, May 5, 2022

How to pass parameters to the dotnet test command while using NUnit

If you want to avoid a runsettings file, you can use this workaround

Tests.cs

string browser = System.Environment.GetEnvironmentVariable("Browser") ?? "chrome";

Note: Selection of browser is through an environment variable. Defaults to Chrome if unprovided.


Tests.bat

set DIR=%~dp0

chdir /d %DIR% 


SETLOCAL

SET Browser=firefox

dotnet test project.dll --filter TestCategory="Sanity"

Timeout 10

If you want to launch the test from an Azure DevOps (fka VSTS or TFS) pipeline, you can simply use the $(...) notation to inline variables

SET TestPassword=$(TestPassword)

dotnet test $(Build.SourcesDirectory)\MyCompany.MyProduct.UITests\MyTest.csproj --configuration $(BuildConfiguration) --collect "Code Coverage" --logger trx --results-directory $(Agent.TempDirectory)


Thursday, January 6, 2022

How to set the generated token as an Environment Variable in Postman Tool

Generated Token Response -

{
    "data": {
        "authToken": {
            "getToken": {
                "accessToken""b1hXMCJ9.eyJhdWETQ1NTk2NSwiYWlvIjoiCJhcHBpZCI6IjQ1ZTMA"
            }
        }
    }
}

Use the below code snippet to set the generated token as an environment variable in Postman Tool

Paste the below code in the Test tab (Please modify the code according to your response).
Environment Variable: token (Use this variable across the API's)

Example: In headers - Authorization : {{token}}


var responseObject = JSON.parse(responseBody);

if (responseObject && responseObject.data && responseObject.data.authToken && 
responseObject.data.authToken.getToken  && responseObject.data.authToken.getToken.accessToken)
{
    postman.setEnvironmentVariable("token"`Bearer ${responseObject.data.authToken.getToken.
                                                            accessToken}`);
}

Thanks for watching this space.