A sample project is hosted in my github:
Another way to create:
https://github.com/typicode/json-server#getting-started
A sample project is hosted in my github:
Another way to create:
https://github.com/typicode/json-server#getting-started
It is important to validate the JSON response schema while doing API testing.
There are many reasons for this:
Hence it is always important to have this check in place.
We will take this example in the popular tool POSTMAN.
Most of us use POSTMAN while testing API and POSTMAN has the capability to run automated checks.
Here is how we can validate json schema:
Step1: Get the response json and convert it into schema using online json to schema converter tool
Lets take an example of below simple json response of Auth token.
{
"access_token": "f093d759-8f15-4d62-afab-f9ccf71577db",
"token_type": "bearer",
"expires_in": 1799
}
Go to https://jsonschema.net/ and paste the json in the left text box.
Make sure to select setting and check the Numeric as JSON type.
It will convert numeric as number not as integer.

Then save and click on submit button.
Step2: Copy the generated Schema
Step3: Go to Postman and go to the request – Test tab.
var Ajv = require('ajv'),
ajv = new Ajv({logger: console}),
schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The Root Schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"additionalProperties": true,
"required": [
"access_token",
"token_type",
"expires_in"
],
"properties": {
"access_token": {
"$id": "#/properties/access_token",
"type": "string",
"title": "The Access_token Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"cd42f000-9905-4971-840b-a66fa9dac4a4"
]
},
"token_type": {
"$id": "#/properties/token_type",
"type": "string",
"title": "The Token_type Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"bearer"
]
},
"expires_in": {
"$id": "#/properties/expires_in",
"type": "number",
"title": "The Expires_in Schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1799.0
]
}
}
};
pm.test('Schema is valid', function() {
var data = pm.response.json();
pm.expect(ajv.validate(schema, data)).to.be.true;
});
Once this code snippet is pasted in postman, hit send request button.
it will validate and result in Pass in Test result tab of response.
While working with API testing, we encounter SSL certificate error in testing environment.
It results into below error while executing automation script.
sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed
javax.net.ssl.SSLHandshakeException
Here is a way to bypass checking for SSL certificate while Rest assured call.
Rest assured has inbuilt option and we do not have to write any other java code to do the same.
Example 1:
RestAssured.baseURI = “http://abcd.com”;
//ByPass SSL Certificate
RestAssured.useRelaxedHTTPSValidation();
RequestSpecification httpRequest = RestAssured.given();
httpRequest.request(Method.GET, “/resource”);
Example 2:
given(). useRelaxedHTTPSValidation().when().get( “http://abcd.com/ resource ” );
Example 3:
We can also pass TLS with the same approach.
given(). useRelaxedHTTPSValidation(“TLS”).when().get( “http://abcd.com/ resource ” );
Regular expressions are patterns used to match character combinations in strings.
Sometimes while testing we come across character validation scenarios.
Few common cases of regex are:
We can make use of regex here to allow or restrict characters.
Lets take some simple scenario to understand how this works.
Usecase1:
A text field which allows the users to enter below range of characters only
a to z , A to Z , 0 to 9
Now lets construct regex to allow only these ranges of characters.
1- To start any regex expression we need to start with the char "^"
2 - Now to include the range or pattern we need to enclose it with [] brackets
3- Now for a to z , the pattern will be a-z
4- for A to Z pattern will be A-Z
5 - For 0 to 9 pattern will be 0-9 or \d
6- Finally our regex will be : ^[a-zA-Z0-9]
To test it, we can use online regex tester website:
regexr.com

You can that the given text matches as per the regex pattern we gave.
But there is a problem here.
If we try to add any character which is not within this allowed range from 2nd char position and in anywhere of the text , it will still be valid.

Notice the characters we added at the end of the text. We still get match but we did not allow it. Then how is it matching?
Because we have specified start of line as ^ but we did not specify if this regex should be applied to all the characters till the end of the text.
So it only checks the 1st char and validates as per the regex.
From the 2nd char on wards whatever you type will be accepted.
How to let it validate for entire string?
We can introduce the end of line character sequence +$
So the updated regex will now be : ^[a-zA-Z0-9]+$
This will now check for the regex for the entire input text.

Now see the result, it has no match.
Now lets see some more interesting use cases.
Usecase2: Allow below ranges
| Range | Regex |
| g to q | g-q |
| F to K | F-K |
| 5 to 9 | 5-9 |
| dot ( .) | . |
| forward slash (/) | / |
| backward slash (\) | \\\\ |
| Double quote ( ” ) | \” |
| space | (space char) |
| square brackets [] | \[\] |
Out of all the above , square brackets ,backward slash and double quote are the tricky ones as these are escape characters and we need to wrap them with backslash to escape.
Interesting thing to notice here is escaping backward slash requires a bit of technical understanding.
\\ – 1st slash is to escape the 2nd one
\\\ – 1st slash will escape the 2nd one, now it will become \\ and again it will escape the 2nd one. and it will become \
\\\\ – 1st one will escape 2nd and 3rd will escape 4th and we will get \\ finally.
So to get one backward slash after escaping we need four backward slashes.
Now lets construct our full regex:
Start and end characters with enclosing: ^[...here we wil keep all chars based on range]+$
Final regex:
^[g-qF-K5-9./\\\\\" \[\]]+$

And we see it matches with all these range of characters.
Try yourself with some characters out of the given range and see what happens.
I hope this helps you understand the basic , you can study more on complex regex further.
Check this article for more complex regex :
https://www3.ntu.edu.sg/home/ehchua/programming/howto/Regexe.html
Do let us know your feedback.
Learn, Explore , Test , Share …..
Javascript has been enabling browsers for years. NodeJS brought it to the server side. TypeScript has wrapped familiar object-oriented, statically-typed syntax around it. Anywhere you look, you’ll find Javascript: on the client, server, mobile, and embedded systems.
These are three most common testing frameworks used in JavaScript based automation frameworks.
Jasmine , Mocha , Cucumber , Serenity/JS are very popular.
Common Ground: BDD Tests
– At their core, Mocha and Jasmine both offer Behavior-Driven Design (BDD) tests
– The describe function defines a test suite. The it function implements the BDD method of describing the behavior that a function should exhibit.
Below is the comparison in all these frameworks wrt to features
Assertion:
– Jasmine has its own assertion library where as Mocha needs Chai library
Chai:
– It has the should style, the expect style, and the assert style
Sinon Fake Server:
– One feature that Sinon has that Jasmine does not is a fake server. This allows you to setup fake responses to AJAX requests made for certain URLs.
Running Tests:
– Mocha comes with a command line utility that you can use to run tests.
– Jasmine however does not have a command line utility to run tests. There are test runners out there for Jasmine, and a very popular one is Karma by the Angular team. Karma also allows support for Mocha if you’d like to run your Mocha tests that way.

This post is taken from LinkedIn
https://www.linkedin.com/posts/dheerajgambhir_what-is-packagejson-in-any-node-js-project-activity-6633741294084681728-PvKu
What is package.json in any node JS project?
package.json is the heart of any Node.js project. Every Node JS project should have this file at the root directory.
This file contains:
• All the packages/modules needed for a Node JS project and their requested versions.
• Several different directives or elements that tell NPM “How to handle the project” like scripts that can be run to automate tasks within the project.
• All the metadata for a project, such as a name, the author, the license, etc.
It makes your build reproducible, and therefore easier to share with other team members.
How we can generate it (package.json)?
Command: npm init -y
2. Create on your own: We can manually create a file “package.json” in the root folder of Node Project but make sure it has the same file name and it should have the same case “package” and the same file extension “.json”.
If you are new to Karate DSL, please follow this link to know about it.
When I started working with Karate framework, I struggled a lot to figure out various things that involves setting up the project, installing plugins, writing various json path , regex for matching etc
While starting I faced few common problems which I want to mention here so that it will save time and get it started quickly without to waste much of time. Even though every details is mentioned in official page, it still lacks few common steps that is not covered.
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>

Note: If you are working under corporate proxy, make sure to add below Proxy configuration in Feature file :
Background:
* configure proxy = ‘http://proxy.com:portnumber/’
Hope this helps.
Comment your problems .
I will try to answer your queries.
If you are new to Karate DSL, please check this official link.
Also check this link for my articles on the same.
when I was working on a script to call an API which was hosted in China region, I was facing some issues while making request in Karate.
I was getting connection time out error.
While the same request was working fine with postman.
I then posted the question in stackoverflow and Peter Thomas (Developer of Karate), responded so quickly and helped me fix my issue.
It was the issue with my Office proxy which was not allowing the request to go through.
Solution:
I just had to add one line of code in Given section as below to fix this:
* configure proxy = ‘http://myofficeproxyurl:80/’