<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bharath Kumar S</title>
    <description>The latest articles on Forem by Bharath Kumar S (@bharathkumar28).</description>
    <link>https://forem.com/bharathkumar28</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F574249%2Fe45d542c-cf5c-4d90-99cc-18597d34295c.jpg</url>
      <title>Forem: Bharath Kumar S</title>
      <link>https://forem.com/bharathkumar28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bharathkumar28"/>
    <language>en</language>
    <item>
      <title>Next.js 16 Type Safety: Async PageProps &amp; Typed Routes</title>
      <dc:creator>Bharath Kumar S</dc:creator>
      <pubDate>Mon, 22 Dec 2025 20:57:49 +0000</pubDate>
      <link>https://forem.com/bharathkumar28/nextjs-16-type-safety-async-pageprops-typed-routes-3ilc</link>
      <guid>https://forem.com/bharathkumar28/nextjs-16-type-safety-async-pageprops-typed-routes-3ilc</guid>
      <description>&lt;p&gt;Next.js has quietly become one of the most type-safe full-stack frameworks out there — yet many teams still use only a fraction of what it offers.&lt;/p&gt;

&lt;p&gt;In this post, I’ll walk through practical, production-ready type safety features in modern Next.js (App Router), including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Next.js TypeScript plugin&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Statically Typed Links&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Route-aware type helpers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto complete environment variables&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Typed &lt;em&gt;NextRequest&lt;/em&gt; and &lt;em&gt;NextResponse&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not a beginner guide — it focuses on features that actually prevent bugs in real-world applications.&lt;/p&gt;



&lt;h2&gt;
  
  
  Next.js TypeScript plugin
&lt;/h2&gt;

&lt;p&gt;Next.js ships with a custom TypeScript plugin that enhances type-checking beyond what plain &lt;code&gt;tsc&lt;/code&gt; can do.&lt;/p&gt;

&lt;p&gt;It understands Next.js concepts such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File-based routing&lt;/li&gt;
&lt;li&gt;Server vs Client Components&lt;/li&gt;
&lt;li&gt;Metadata APIs&lt;/li&gt;
&lt;li&gt;Layout and page conventions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ensure VS Code uses this plugin:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Command Palette &lt;code&gt;(Ctrl / ⌘ + Shift + P)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Search for TypeScript: Select TypeScript Version&lt;/li&gt;
&lt;li&gt;Choose Use Workspace Version&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This allows VS Code to pick up Next.js–specific type rules automatically via &lt;code&gt;next-env.d.ts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5fc1c14u54jzavpetofh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5fc1c14u54jzavpetofh.png" alt="Search in CMD Palette" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh7h76op3jhhtvc9lio4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh7h76op3jhhtvc9lio4.png" alt="Select TS Version" width="800" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once enabled, you’ll get IntelliSense and in-context documentation for Next.js-specific APIs such as metadata and caching options. &lt;/p&gt;

&lt;p&gt;Showing available options and in-context documentation&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp4wf1gqckuzu1f9155q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp4wf1gqckuzu1f9155q.png" alt="Intellisense" width="800" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Other useful checks provided by the plugin include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensuring the &lt;code&gt;"use client"&lt;/code&gt; directive is used correctly&lt;/li&gt;
&lt;li&gt;Preventing client-only hooks (like useState) from being used in Server Components&lt;/li&gt;
&lt;li&gt;Catching invalid exports in &lt;code&gt;page.tsx&lt;/code&gt;, &lt;code&gt;layout.tsx&lt;/code&gt;, and &lt;code&gt;route.ts&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Statically Typed Links
&lt;/h2&gt;

&lt;p&gt;Next.js can generate statically typed routes to prevent typos and invalid navigation.&lt;/p&gt;

&lt;p&gt;Enable typed routes in &lt;code&gt;next.config.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  typedRoutes: true,
}

export default nextConfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next.js will generate route definitions inside &lt;code&gt;.next/types&lt;/code&gt;, which TypeScript uses to validate links and navigation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fth0wy2v2who5v2bmjsnm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fth0wy2v2who5v2bmjsnm.png" alt="Route Types" width="800" height="98"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Invalid routes are caught at compile time&lt;/li&gt;
&lt;li&gt;Route refactors are safer&lt;/li&gt;
&lt;li&gt;IntelliSense suggests only valid paths&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Route-Aware Type Helpers
&lt;/h2&gt;

&lt;p&gt;Next.js generates global route-aware helpers for App Router types. These are available without imports and are generated during &lt;code&gt;next dev&lt;/code&gt;, &lt;code&gt;next build&lt;/code&gt;, or via &lt;code&gt;next typegen&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Available helpers include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PageProps&lt;/li&gt;
&lt;li&gt;LayoutProps&lt;/li&gt;
&lt;li&gt;RouteContext&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Without PageProps
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Details({
  params,
  searchParams,
}: {
  params: { slotId: string };
  searchParams: { name?: string };
}) {
  const { slotId } = params;
  const { name } = searchParams;

  return (
    &amp;lt;div&amp;gt;
      Slot: {slotId} &amp;lt;br /&amp;gt;
      Name: {name}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This approach is explicit and works well for smaller components.&lt;/p&gt;



&lt;h3&gt;
  
  
  With PageProps
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default async function Details(props: PageProps&amp;lt;"/details/[slotId]"&amp;gt;) {
  const { slotId } = await props.params;
  const { name } = await props.searchParams;

  return (
    &amp;lt;div&amp;gt;
      Slot: {slotId} &amp;lt;br /&amp;gt;
      Name: {name}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This version is more concise and automatically stays in sync with the route definition.&lt;/p&gt;



&lt;h3&gt;
  
  
  Without LayoutProps
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import type { ReactNode } from "react";

export default function RootLayout({
  children,
}: {
  children: ReactNode;
}) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body&amp;gt;{children}&amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  With LayoutProps
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function RootLayout(props: LayoutProps&amp;lt;"/"&amp;gt;) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body&amp;gt;
        {props.children}
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  Without RouteContext
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function GET(
  _request: NextRequest,
  { params }: { params: Promise&amp;lt;{ id: string }&amp;gt; }
) {
  const { id } = await params;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  With RouteContext
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function GET(
  _request: NextRequest,
  ctx: RouteContext&amp;lt;"/api/[id]"&amp;gt; // you will get intellisense
) {
  const { id } = await ctx.params;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using RouteContext gives you full IntelliSense for route params and avoids manual typing.&lt;/p&gt;



&lt;h2&gt;
  
  
  Auto complete environment variables
&lt;/h2&gt;

&lt;p&gt;Enable it in next.config.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![next env config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ozpitstpxw6dxf5g7o7.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you will get intellisense support &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyx0wnyfww7mp0t4nrbcc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyx0wnyfww7mp0t4nrbcc.png" alt="Typed Env" width="788" height="188"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Typed NextRequest and NextResponse
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextRequest, NextResponse } from "next/server";

export async function GET(
  _request: NextRequest
) {

  return NextResponse.json(
    { msg: 'Hello!!! })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NextRequest extends the Web Request API with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Typed cookies&lt;/li&gt;
&lt;li&gt;Parsed URLs via nextUrl&lt;/li&gt;
&lt;li&gt;Middleware-friendly helpers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NextResponse extends the Web Response API with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;json()&lt;/li&gt;
&lt;li&gt;redirect()&lt;/li&gt;
&lt;li&gt;Cookie helpers&lt;/li&gt;
&lt;li&gt;Edge-friendly APIs&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Next.js type safety isn’t about writing more types —&lt;br&gt;
it’s about letting the framework encode architectural rules directly into your editor.&lt;/p&gt;

&lt;p&gt;When used well, TypeScript becomes a guardrail, not a burden,&lt;br&gt;
and IntelliSense becomes an extension of your system design.&lt;/p&gt;




&lt;p&gt;Reference - &lt;a href="https://nextjs.org/docs/app/api-reference/config/typescript" rel="noopener noreferrer"&gt;Next.js - TypeScript&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Connect with Me
&lt;/h2&gt;

&lt;p&gt;If you enjoyed this post or want to follow my work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/bharath-kumar-s-a4339aa7/" rel="noopener noreferrer"&gt;Bharath Kumar S&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/Bharath-Kumar-S" rel="noopener noreferrer"&gt;Bharath Kumar&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to &lt;strong&gt;connect, star my projects, or reach out&lt;/strong&gt; — I love discussing Next.js, TypeScript, and modern frontend best practices!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>typescript</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>JavaScript BDD cucumber api test framework</title>
      <dc:creator>Bharath Kumar S</dc:creator>
      <pubDate>Fri, 17 Sep 2021 20:57:30 +0000</pubDate>
      <link>https://forem.com/bharathkumar28/javascript-bdd-cucumber-api-test-framework-1lfh</link>
      <guid>https://forem.com/bharathkumar28/javascript-bdd-cucumber-api-test-framework-1lfh</guid>
      <description>&lt;p&gt;&lt;br&gt;
   &lt;strong&gt;JavaScript BDD cucumber api Test framework &lt;br&gt;
&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  NPM packages used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a class="mentioned-user" href="https://dev.to/cucumber"&gt;@cucumber&lt;/a&gt;/cucumber - BDD framework&lt;/li&gt;
&lt;li&gt;ajv - JSON schema validationm &lt;/li&gt;
&lt;li&gt;axios - Rest Client&lt;/li&gt;
&lt;li&gt;chai - Assert library&lt;/li&gt;
&lt;li&gt;chai-as-promised - Assert library&lt;/li&gt;
&lt;li&gt;cucumber-html-reporter - html reporter&lt;/li&gt;
&lt;li&gt;dotenv - for env file&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ts-node(typescript execution environment for node) in cucumberOpts. &lt;/li&gt;
&lt;li&gt;All scripts written with JavaScript &amp;amp; Cucumber Gerkhin.&lt;/li&gt;
&lt;li&gt;Neat folder structures with js files easy to maintain&lt;/li&gt;
&lt;li&gt;Page Object design pattern implementation.&lt;/li&gt;
&lt;li&gt;Extensive hooks implemented for BeforeFeature, AfterScenarios etc in world file under support directory.&lt;/li&gt;
&lt;li&gt;HTML report withAssert errors on failure feature scenarios.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  To Get Started
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Pre-requisites
&lt;/h4&gt;

&lt;p&gt;1.NodeJS installed globally in the system.&lt;br&gt;
&lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;https://nodejs.org/en/download/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Visual Studio Code or any&lt;/p&gt;
&lt;h4&gt;
  
  
  Setup Scripts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Clone the repository into a folder&lt;/li&gt;
&lt;li&gt;Go inside the folder and run following command from terminal/command prompt
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;All the dependencies from package.json would be installed in node_modules folder.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Run Scripts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Now just run the test command which starts the test execution
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwxxokzy07a3s07q1u90.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwxxokzy07a3s07q1u90.gif" alt="Alt Text" width="1045" height="551"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Writing Features
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: PurgoMalum Sanity Tests
    PurgoMalum is a simple, free, RESTful web service for filtering and removing content of profanity, obscenity and other unwanted text.

    Background:
        Given RESTful web service "https://www.purgomalum.com" is up and running

    @sanity
    Scenario Outline: Validating Response Types
        When validating RESTful web service for "&amp;lt;type&amp;gt;" response type with text "this is some test input"
        Then Validate the response "&amp;lt;response&amp;gt;"
        Examples:
            | type  | response                |
            | xml   | this is some test input |
            | json  | this is some test input |
            | plain | this is some test input |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Writing Step Definitions
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given(`RESTful web service {string} is up and running`, timeout, async function (url) {
   &amp;lt;!-- implementation --&amp;gt;
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Schema for validation (ajv is used for JSON schema validation)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class PurgoMalumSchema {
    constructor() {
    }

    /**
   * jsonSchema for success case
   */
    jsonSchema() {
        return {
            type: "object",
            properties: {
                result: { type: "string" }
            },
            required: ["result"],
            additionalProperties: false
        }
    }

    /**
    * jsonSchema for negative case
    */
    jsonErrorSchema() {
        return {
            type: "object",
            properties: {
                error: { type: "string" }
            },
            required: ["error"],
            additionalProperties: false
        }
    }


    /**
   * xml for success case
   */
    xmlSchema(text) {
        return `&amp;lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&amp;gt;&amp;lt;PurgoMalum xmlns="http://www.purgomalum.com"&amp;gt;&amp;lt;result&amp;gt;${text}&amp;lt;/result&amp;gt;&amp;lt;/PurgoMalum&amp;gt;`
    }

    /**
    * xml for negative case
    */
    xmlErrorSchema(text) {
        return `&amp;lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&amp;gt;&amp;lt;PurgoMalum xmlns="http://www.purgomalum.com"&amp;gt;&amp;lt;error&amp;gt;${text}&amp;lt;/error&amp;gt;&amp;lt;/PurgoMalum&amp;gt;`
    }

}

module.exports = { PurgoMalumSchema : new PurgoMalumSchema() };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Rest Client
&lt;/h4&gt;

&lt;p&gt;Rest Client is under utilities directory in Utilities.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  /**
 * @param {string=} URL - API endpoint.
 * @param {object=} Options - headers, payload and auth.
 */
  async getRequest(URL, options = {}) {
    let response = await axios.get(URL, options);
    expect(response.status).to.match(/^20[0-2]$/);
    return response;
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Cucumber Hooks
&lt;/h4&gt;

&lt;p&gt;Test hooks in world.js under support directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before(async function (testCase) {
    // console.log(testCase.gherkinDocument.feature.description)
});

After(function (testCase) {
    // console.log(testCase.result.status)
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Docker
&lt;/h4&gt;

&lt;p&gt;Following DockerFile is used to create a docker image and run the container&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:16-alpine3.14

WORKDIR /app

# copy project files
COPY . .

# dependencies will be installed only if the package.json file changes
RUN npm ci

# rerun E2E tests only if any of the previous files change
CMD npm run test

# Simple docker file just for demonstration. Advanced concepts to be included in docker compose or groovy script is jenkins pipeline
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpjoxjilisn8s0qqrctd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpjoxjilisn8s0qqrctd.gif" alt="Alt Text" width="1046" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  HTML Reports
&lt;/h4&gt;

&lt;p&gt;report.js is used to backup the existing html report to history folder. &lt;/p&gt;

&lt;p&gt;Current report is in report directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2j4428rcxyn8c9nqj50f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2j4428rcxyn8c9nqj50f.gif" alt="Alt Text" width="760" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git repo : &lt;a href="https://github.com/Bharath-Kumar-S/node_bdd_api_tests/" rel="noopener noreferrer"&gt;https://github.com/Bharath-Kumar-S/node_bdd_api_tests/&lt;/a&gt;&lt;br&gt;
I hope this was helpful. Please leave your feedback.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>api</category>
      <category>cucumber</category>
    </item>
    <item>
      <title>Cypress Assertions</title>
      <dc:creator>Bharath Kumar S</dc:creator>
      <pubDate>Sun, 07 Feb 2021 17:46:49 +0000</pubDate>
      <link>https://forem.com/bharathkumar28/cypress-assertions-58ag</link>
      <guid>https://forem.com/bharathkumar28/cypress-assertions-58ag</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is Cypress?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Cypress is a next generation front end testing tool built for the modern web. Learn about &lt;a href="https://www.cypress.io/" rel="noopener noreferrer"&gt;Cypress.io&lt;/a&gt; and its features.&lt;/p&gt;

&lt;p&gt;Cypress bundles the popular &lt;a href="https://docs.cypress.io/guides/references/assertions.html#Chai" rel="noopener noreferrer"&gt;Chai&lt;/a&gt; assertion library, as well as helpful extensions for &lt;a href="https://docs.cypress.io/guides/references/assertions.html#Sinon-Chai" rel="noopener noreferrer"&gt;Sinon&lt;/a&gt; and &lt;a href="https://docs.cypress.io/guides/references/assertions.html#Chai-jQuery" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt;, bringing you dozens of powerful assertions for free.&lt;/p&gt;

&lt;p&gt;Cypress bundles chai no need to add as a dependency to your project.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pre-requisites&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Node.js and npm &lt;a href="https://www.npmjs.com/get-npm" rel="noopener noreferrer"&gt;https://www.npmjs.com/get-npm&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Setup&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a directory for the project and cd to it:  &lt;code&gt;mkdir cypress-assertions &amp;amp;&amp;amp; cd cypress-assertions&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm init --y&lt;/code&gt; to setup a new npm package project.&lt;/li&gt;
&lt;li&gt;Install Cypress via npm &lt;code&gt;npm i cypress --save-dev&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify Cypress by running &lt;code&gt;npx cypress open&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Now cypress folder along with cypress.json file will be created in the project directory.&lt;/li&gt;
&lt;li&gt;"integration" folder contains cypress test examples.&lt;/li&gt;
&lt;li&gt;Ignore the examples folder by adding as ignored test is cypress.json
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "ignoreTestFiles": "**/examples/*.js"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;Creating and Run Tests&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Under the “integration” folder create a new file. Name it “sample_assert.js”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="cypress" /&amp;gt;

describe('Sample assert', () =&amp;gt; {
    it('first test', () =&amp;gt; {
       expect(2).to.equal(2);
     })
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffzp2j5qsuzrphhea43pq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffzp2j5qsuzrphhea43pq.png" alt="image" width="634" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In beforeEach block specify the url that needs to be navigated before each test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="cypress" /&amp;gt;

describe('Sample assert', () =&amp;gt; {

beforeEach(() =&amp;gt;{
        cy.visit(`https://example.cypress.io/commands/actions`);
})

it('first test', () =&amp;gt; {
       expect(2).to.equal(2);
})

})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check for Visibility of element.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5u32aqz6b8pamb5dox2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5u32aqz6b8pamb5dox2t.png" alt="image" width="367" height="88"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; it(`Assert - Visibility of element`,()=&amp;gt;{
        cy.get(`[id="email1"]`).should(`be.visible`);
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fass1arw1z1v58ho00xj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fass1arw1z1v58ho00xj3.png" alt="image" width="630" height="290"&gt;&lt;/a&gt; &lt;br&gt;
&lt;strong&gt;&lt;em&gt;Check for Disabled element.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo05luprkk1np2z02wgt4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo05luprkk1np2z02wgt4.png" alt="image" width="353" height="90"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; it(`Assert - Disabled element`,()=&amp;gt;{
        cy.get(`textarea`).should(`be.disabled`);
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fidon8rdqufs21fzp42fk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fidon8rdqufs21fzp42fk.png" alt="image" width="629" height="202"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Check for Focused element.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy43nrpqzt9xhyfgf8w8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy43nrpqzt9xhyfgf8w8d.png" alt="image" width="459" height="118"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuw3b48rs6d9e6qnrzs5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuw3b48rs6d9e6qnrzs5g.png" alt="image" width="462" height="110"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it(`Assert - Focused element`, () =&amp;gt; {
        cy.get('.action-focus').focus()
            .should(`be.focused`)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxit2kfli67np6vuw16c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxit2kfli67np6vuw16c.png" alt="image" width="637" height="365"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Check for blank input box&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffegzmrj2ce6reqwet9kh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffegzmrj2ce6reqwet9kh.png" alt="image" width="364" height="87"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it(`Assert - Blank Input box`, () =&amp;gt; {
        cy.get(`[id="email1"]`).should(`have.value`,``);
}) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftkz24jhlzu2mirbzbs5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftkz24jhlzu2mirbzbs5e.png" alt="image" width="630" height="410"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Check if checkbox is checked&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fct8qjdqgyu9pzgn89uts.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fct8qjdqgyu9pzgn89uts.png" alt="image" width="303" height="90"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it(`Assert - Checkbox is checked`, ()=&amp;gt;{    
 cy.get(`[value="checkbox1"]`).first().click().should(`be.checked`)
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F048xjpc3ae0s2cgndum4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F048xjpc3ae0s2cgndum4.png" alt="image" width="634" height="482"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Check for Object comparison&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it(`Assert - Object assertions`,() =&amp;gt; {
        let obj = {
            name: 'Bharath' 
        }
        expect(obj).to.deep.equal({ name: 'Bharath' })
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkh638smac3sjfsa145s0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkh638smac3sjfsa145s0.png" alt="image" width="631" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git repo: &lt;a href="https://github.com/Bharath-Kumar-S/cypress-assertions" rel="noopener noreferrer"&gt;https://github.com/Bharath-Kumar-S/cypress-assertions&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I hope this was helpful. Please leave your feedback.&lt;/p&gt;

</description>
      <category>cypress</category>
      <category>chai</category>
      <category>assert</category>
      <category>javascript</category>
    </item>
    <item>
      <title>API Tests with Cypress.IO</title>
      <dc:creator>Bharath Kumar S</dc:creator>
      <pubDate>Sat, 06 Feb 2021 17:17:42 +0000</pubDate>
      <link>https://forem.com/bharathkumar28/api-tests-with-cypress-io-3f76</link>
      <guid>https://forem.com/bharathkumar28/api-tests-with-cypress-io-3f76</guid>
      <description>&lt;p&gt;&lt;em&gt;What is Cypress?&lt;/em&gt;&lt;br&gt;
Cypress is a next generation front end testing tool built for the modern web. Learn about &lt;a href="https://www.cypress.io/" rel="noopener noreferrer"&gt;Cypress.io&lt;/a&gt; and its features.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pre-requisites&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Node.js and npm &lt;a href="https://www.npmjs.com/get-npm" rel="noopener noreferrer"&gt;https://www.npmjs.com/get-npm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Any API you would like to use&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Setup&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a directory for the project and cd to it:  &lt;code&gt;mkdir cypress-api-automation-tests &amp;amp;&amp;amp; cd cypress-api-automation-tests&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm init --y&lt;/code&gt; to setup a new npm package project.&lt;/li&gt;
&lt;li&gt;Install Cypress via npm &lt;code&gt;npm i cypress --save-dev&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify Cypress by running &lt;code&gt;npx cypress open&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Now cypress folder along with cypress.json file will be created in the project directory.&lt;/li&gt;
&lt;li&gt;"integration" folder contains cypress test examples.&lt;/li&gt;
&lt;li&gt;Edit the "cypress.json" file to add baseURL for all the tests
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"baseUrl": "https://jsonplaceholder.typicode.com/"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Creating and Run Tests&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Under the “integration” folder create a new file. Name it “typicode-api-test.js”
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="cypress" /&amp;gt;

describe('JSON Typicode', () =&amp;gt; {
    it('Get all user posts', () =&amp;gt; {
       cy.request('/posts')
       .then((response) =&amp;gt; {
           expect(response.status).to.equal(200);
        })
     })
 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2.In Cypress, run the test and notice the results.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4q4h0kdftylj0l7cp0hz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4q4h0kdftylj0l7cp0hz.png" alt="image" width="638" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try to assert on few other other objects returned in the response and verify it’s working properly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Assertions&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Check for available keys in the response object.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to check if userId, id, title and body keys are present in the response object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="cypress" /&amp;gt;

describe('JSON Typicode', () =&amp;gt; {
    it('Get all user posts', () =&amp;gt; {
        cy.request('/posts')
            .then((response) =&amp;gt; {
                let first_response_object = Object.keys(response.body[0]);
                let keys = [`userId`, `id`, `title`, `body`];
                for (let key of keys) {
                    expect(first_response_object).to.includes(key)
                }
            })
    })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result will be &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvuwlk7jycb5bfybse0el.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvuwlk7jycb5bfybse0el.png" alt="image" width="622" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Object.keys(object) will return array of available keys.&lt;/li&gt;
&lt;li&gt;And we iterate over the keys array and asserted with includes method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Post a new user post.&lt;/strong&gt;&lt;br&gt;
request body will be the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
            "userId": 1,
            "id": 1,
            "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
            "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
          }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyb6s66ulht7chr169k2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyb6s66ulht7chr169k2c.png" alt="image" width="626" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ignore the examples folder by adding as ignored test is cypress.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "baseUrl": "https://jsonplaceholder.typicode.com/",
    "ignoreTestFiles": "**/examples/*.js"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git repo : &lt;a href="https://github.com/Bharath-Kumar-S/cypress-api-automation-tests" rel="noopener noreferrer"&gt;https://github.com/Bharath-Kumar-S/cypress-api-automation-tests&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this was helpful. Please leave your feedback.&lt;/p&gt;

</description>
      <category>cypress</category>
      <category>api</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
