Friday, February 23, 2024

How can one address the collation discrepancy that arises when the database and the table have different collations?

If you want to change the collation of the entire database, you can use the following command:

ALTER DATABASE YourDatabaseName

COLLATE NewCollationName

Replace "YourDatabaseName" with the name of your database and "NewCollationName" with the name of the collation you want to use.

Remember, changing the collation of a database will only affect the default collation of new tables and columns and won’t change the collation of existing tables and columns. You would need to change those individually if needed.

You can alter the collation of a specific column in a table using the ALTER TABLE statement. Here is a general example:

ALTER TABLE YourTableName

ALTER COLUMN YourColumnName

COLLATE NewCollationName

In this query, replace "YourTableName" with the name of your table, "YourColumnName" with the name of the column that has the collation issue, and "NewCollationName" with the name of the collation you want to use.

Please note that you should be careful when changing collation as it can affect your data and the performance of your queries. It’s recommended to back up your data before making such changes. Also, ensure that the new collation is compatible with your data.

Thursday, September 7, 2023

Step-by-Step Guide to Updating Env Config Variables in Octopus Project

Step-by-Step Guide to Updating Env Config Variables in Octopus Project -

  1. Open the Octopus project for which you want to update the Env Config variables.

  2. In the left-hand navigation pane, click Variables > Project Templates.

  3. Add the required project templates along with their values.

  4. Click Save.

  5. Click Tenants from the menu.

  6. Select the required tenant.

  7. Click Variables.

  8. Expand the required project to update the variable names.

  9. Update the variables and click Save.

  10. Return to the Octopus project.

  11. Click Process.

  12. Add the Octopus Admin and Service Fabric modules from the Script Modules section.

  13. Click the Add step (Run a script).

Test Env Config file:

hostname = hostname_value

Use the following PowerShell script to update the Env Config variables:

#Test [String]$hostname = "" Write-Message -Message ("Validating Test Variables ....") ##Validate Test Variables For Successful Deployment

$hostname = Validate-SFParameters -Value $OctopusParameters['hostname'] -ParameterName "hostname" -ReturnValue Write-Header -Header "END VALIDATING VARIABLES"; ## -------------------------------------------------------------------------------------- ## Update the variables in the Config file ## -------------------------------------------------------------------------------------- $config_file_path = "C:\config\default.config" # Open the config file $config_file = Get-Content -Path $config_file_path $config_file = $config_file -replace "(?<=^|\W)hostname_value(?=\W|$)", $hostname # Write the config file Set-Content $config_file_path $config_file

14. Create the release

15. Open the test environment configuration file in the project directory and verify that the configurations have been updated.

Friday, July 28, 2023

Number System Conversions

This blog post covers various number system conversions, explaining how to convert numbers between decimal, octal, hexadecimal, and binary representations. The content presents step-by-step procedures for each conversion, making it easy for readers to follow along.

1) Decimal to Octal:

231

231 ÷ 8 = 28

231 % 8 = 7

28 ÷ 8 = 3

28 % 8 = 4

3 ÷ 8 = 0

3 % 8 = 3

So, the octal equivalent of the decimal number 231 is 347.

Octal to Decimal
347

3 * 8^2 + 4 * 8^1 + 7 * 8^0
3 * 64 + 4 * 8 + 7 * 1
192 + 32 + 7 = 231

So, the decimal equivalent of the octal number 347 is 231.

2) Decimal to Hexadecimal
200

200 ÷ 16 = 12
200 % 16 = 8

12 ÷ 16 = 0
12 % 16 = 12 (C)
So, the hexadecimal equivalent of the decimal number 200 is C8.

Hexadecimal to Decimal
C8

C * 16^1 + 8 * 16^0

12 * 16 + 8 * 1
192 + 8 = 200
So, the decimal equivalent of hexadecimal number C8 is 200.

3) Decimal to Binary
125

125 ÷ 2 = 62
125 % 2 = 1

62 ÷ 2 = 31
62 % 2 = 0

31 ÷ 2 = 15
31 % 2 = 1

15 ÷ 2 = 7
15 % 2 = 1

7 ÷ 2 = 3
7 % 2 = 1

3 ÷ 2 = 1
3 % 2 = 1

1 ÷ 2 = 0
1 % 2 = 1
So, the binary equivalent of the decimal number 125 is 1111101.

Binary to Decimal
1111101

= (1 * 2^6) + (1 * 2^5) + (1 * 2^4) + (1 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0)
= 64 + 32 + 16 + 8 + 4 + 0 + 1
= 125

So, the decimal equivalent of the binary number 1111101 is 125.


Thursday, March 9, 2023

To find out the space used by tables in MS SQL Server

Use the below code to find out the space used by tables in MS SQL Server -


SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS FreeSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS FreeSpaceMB
FROM 
    sys.tables t
INNER JOIN     
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    TotalSpaceMB DESC


Wednesday, March 8, 2023

How to publish artifacts in Azure DevOps pipeline

Everyone is interested in viewing the artifacts, such as logs and execution reports after the pipeline execution is complete.

Use the following lines of code in the YAML file to upload the artifacts after the execution.

$(System.DefaultWorkingDirectory) -- is the current project directory

-   taskPublishBuildArtifacts@1
        conditionalways()
        inputs:
            pathToPublish$(System.DefaultWorkingDirectory)\logs
            artifactNameYour artifact name
        displayNameprovide your display name

Monday, February 20, 2023

How to Zoom In, Zoom Out the Chrome, Edge, Safari and Firefox Browsers

 How to Zoom In, Zoom Out the Chrome, Edge, Safari and Firefox Browsers -


We can zoom in, and zoom out the browsers by using the following commands -

"document.body.style.zoom = 'number of % to zoom'";

document.body.style.MozTransform = 'scale(number of % to zoom)';";


public class Tests{

public static void main(String[] args){

WebDriver driver=new ChromeDriver();

driver.get("https://software-testing-made-lifeeasy.blogspot.com/");

JavascriptExecutor js = (JavascriptExecutor)driver;

//The below line will work for these browsers - Chrome, Edge and Safari

String zoomProperty = "document.body.style.zoom = '200.0%'";

//The below line will work only for the Firefox browser

String zoomProperty = "document.body.style.MozTransform = 'scale(0.5)';"; //50% zoom, If you provide scale as 1, it's 100% zoom.

js.executeScript(zoomProperty);

}

}

Thursday, August 4, 2022

How to rename a database in the MS SQL server:


Use the below code to rename a database in the MS SQL server - 

USE master; GO ALTER DATABASE Database01 SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE Database01 MODIFY NAME = Database02 ; GO ALTER DATABASE Database02 SET MULTI_USER GO



 How to read a JSON file and validate the response against the schema.

Install the following requirements:

  • pip install jsonschema

Use the below code to read a JSON:

def readJSONFile(fileName):
        data = open(fileName)
        jsonData = json.load(data)
        return jsonData

Use the below code to validate a JSON schema:

def validate_schema(json_data, json_schema):
        try:
            validate(instance=json_data, schema= json_schema)
        except jsonschema.exceptions.ValidationError as err:
            assert False, "JSON schema is not matching, Please check"

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


Thursday, November 18, 2021

 

How to Click a button or links from browser console window by Using JQuery


var y = 0;
while( y < 2 ) 
    $x("//a[@class='wsmc-topmenu__breadcrumb-link--home']")[y].click();
    y = y + 1;
}

Result: 
Two times, the link or button will be clicked.

Try this solution and result is awesome.

Monday, July 19, 2021

Get most recent folder and move the files from one computer to another computer using batch commands

@echo off
FOR /F "delims=" %%i IN ('dir /b /ad-h /t:c /o-d') DO (
    SET a=%%i
    GOTO :found
)
echo No subfolder found
:found
echo Most recent subfolder: %a%

mkdir "\\DEE\AT\Files\%a%"
XCOPY %a% \\DEE\AT\Files\%a% /s /h /Y
pause 

Wednesday, April 14, 2021

How to get text from parent element and exclude text from children (C# Selenium)

Example: Suppose you have the following DOM

<h2 class="title">Charger

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>


<h2 class="title">Mobile

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>


<h2 class="title">Cable

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>

Solution: You can use the below code to fetch the parent element texts (i.e. Charger, Mobile and Cable) IList list = Application.driver.FindElements(By.XPath("//h2")); string[] texts = new string[list.Count]; foreach (IWebElement element in list) { texts[i] = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].firstChild.textContent;", element); i++; } return texts;

Friday, December 25, 2020

How to get the number of objects created in JAVA

Program to get the number of objects created in JAVA

public class Main

{

    static int i=0;

    public Main()

    {

        i++;

    }

    public Main(String name)

    {

        i++;

    }

public static void main(String[] args)

{

    Main m=new Main();

    Main m1=new Main("Balaji");

    System.out.println(i);

}

}

Output:

2

Wednesday, February 14, 2018

How to click the 'Second' element out of '8' matching element using Selenium Webdriver (Two elements in a page with same ID's)

Option 1:

You can use XPath indexing.

Example:
driver.findElement(By.xpath("(//*[@id="notificationStatusSwitch"])[2]"));

Option 2:

You can use findElements(): Using the given “locating mechanism” find all the elements on the current page.It returns a list of web elements, Then access the second one found

Example:

List<WebElement> elementList = driver.findElements(By.xpath("//*[@id="notificationStatusSwitch"]"));

elementList.get(1).click;