Thursday, June 9, 2022

How to call C# code from Python -

Install - pip install clr

pip install --pre pythonnet

Please find the below example -


C# Code :

namespace PrintYourName

{

    [ComVisible(true)]

    public class Test

    {

        public int DoSum(int a, int b)

        {

            return a + b;

        }


        public int DoSub(int a, int b)

        {

            return a - b;

        }


        public int DoMul(int a, int b)

        {

            return a * b;

        }


        public string printName()

        {

            return "Balaji";

        }

        public static string GetZonedDateTime()

        {

            DateTime dateTime = DateTime.Now;

            string zonedDateTime = string.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", dateTime.ToLocalTime());

            return zonedDateTime;

        }

    }

}

Python Code:

import clr

import sys

print(sys.version)

lb = clr.AddReference(r"C:\Project\Automation\PrintYourName\obj\Debug\net6.0\PrintYourName.dll")

from C#NameSpace import ClassName

from PrintYourName import Test

# from System.IO import *

# from System.Convert import *

c= Test()

print("Addition Result is", c.DoSum(10,10))

print("Subtraction Result is", c.DoSub(12,10))

print("Multiply Result is", c.DoMul(20,10))

print("Name is ", c.printName())


Output:



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)


Tuesday, February 15, 2022

Suppose you are given with a day name, and a number (int value), you need to write a code to determine the number of days after the given day is which day ?

Asked this question in one of the leading MNC.

// Eg.  

// Input: Day = Sunday  & number = 4

// Output: Wednesday

 // Eg.

// Input: Day = Thursday & number = 9

// Output: Friday


import java.util.*;

 class Solution

{   

    public String solution(String day, int number)

    {

        String days[]={"Sunday", "Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday"};

        String output=null;

        for(int i=0;i<days.length;i++)

        {

            if(days[i]==day)

            {

                output = days[(i+number-1)%7];

                break;

            }

        }

         return output;

    }

}

class Main 

{

    public static void main(String[] args)

   

        String ans = new Solution().solution("Sunday",21);

        System.out.println(ans);

    }

}

==============

Find occurrences of a character without using loops and conditions -

String str = "Balaji"; //Find how many times 'a' is repeating

System.out.println(str.split("a").length-1);

Thursday, February 10, 2022

Generate LivingDoc Report

Use the below commands to generate LivingDoc report

set DIR=%~dp0

chdir /d %DIR% 

livingdoc test-assembly Sales_API.dll -t TestExecution.json

LivingDoc.html

Timeout 10

Monday, January 31, 2022

Setup Allure in Windows 10 and Generate Allure Report

  1. Download the latest allure framework from the below link - https://github.com/allure-framework/allure2
  2. Set the allure bin path
  3. Open the CMD and check the allure version by entering 'allure --version'
  4. Run the test cases
  5. Open the CMD and run the following command to generate the allure report - 'allure serve D:\Learnings\Project\build\allure-results'
  6. Automatically the report will be opened


To run a cucumber test using Gradle -
.\gradlew.bat test --tests RunTests




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.

Tuesday, December 7, 2021

How to install Cypress on windows machine -

1. Download and install node.js

2. Open the cmd and type npm --version to check the npm version and type npm init.

3. After the initialization, Go to your project folder and Type 'npm install cypress --save-dev'

4. Wait for the installation to complete.

5. Cypress will be installed in your project folder (Cypress has now been installed in your ./node_modules directory, with its binary executable accessible from ./node_modules/.bin.)

6. Delete the cypress file from ./node_modules/.bin

7. Verify the cypress by using npx cypress verify.

8. To open the cypress, type cypress open and wait for a few seconds, the cypress application will be opened.


Kindly adhere to the following instructions to utilize the most recent edition:

  1. Acquire and install node.js.
  2. Launch VS code.
  3. Establish a new project.
  4. Activate the terminal and execute the subsequent commands to install the required components:

  • npm init -y
  • npm install cypress
  • npm install -D typescript
  • npm run cypress:open