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:
Use the below code to validate a JSON schema:
This blog is a valuable resource for those seeking to expand their knowledge of software testing. It provides a wealth of information on various software testing concepts, as well as a comprehensive collection of interview questions and answers. If you are looking to enhance your skills and expertise in software testing, this blog is an excellent starting point for your learning journey.
How to read a JSON file and validate the response against the schema.
Install the following requirements:
Use the below code to read a JSON:
Use the below code to validate a JSON schema:
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:
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)
Asked this question in one of the leading MNC.
// Eg.
// Input: Day = Sunday
& number = 4
// Output: Wednesday
// Input: Day = Thursday & number = 9
// Output: Friday
import java.util.*;
{
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);
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
.\gradlew.bat test --tests RunTests