<?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: Dmitrii Bormotov</title>
    <description>The latest articles on Forem by Dmitrii Bormotov (@bormando).</description>
    <link>https://forem.com/bormando</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%2F545185%2Fa804faea-7a4e-4abe-b5db-05754b83c6d4.png</url>
      <title>Forem: Dmitrii Bormotov</title>
      <link>https://forem.com/bormando</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bormando"/>
    <language>en</language>
    <item>
      <title>Modular Import in Page Objects</title>
      <dc:creator>Dmitrii Bormotov</dc:creator>
      <pubDate>Sat, 04 Feb 2023 07:14:54 +0000</pubDate>
      <link>https://forem.com/bormando/modular-import-in-page-objects-11kc</link>
      <guid>https://forem.com/bormando/modular-import-in-page-objects-11kc</guid>
      <description>&lt;p&gt;Ahoy, mate!&lt;/p&gt;

&lt;p&gt;This topic may be useful for test automation engineers who'd like to make their code look better!&lt;/p&gt;

&lt;p&gt;I wrote about &lt;a href="https://hackernoon.com/cypress-with-page-object-model" rel="noopener noreferrer"&gt;Page Objects in Cypress&lt;/a&gt; earlier - take a look if you haven't already! Modular import isn't a new thing, and if you haven't heard about it and its profits before - you can find more in an article from &lt;a class="mentioned-user" href="https://dev.to/fahadaminshovon"&gt;@fahadaminshovon&lt;/a&gt; :&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/fahadaminshovon" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F415104%2F86d971d8-4b2c-4aa9-b669-90b42dcba7a8.jpg" alt="fahadaminshovon"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/fahadaminshovon/-how-to-use-indexjs-fileproperly-302f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to use index.js file(Properly)&lt;/h2&gt;
      &lt;h3&gt;B.M. Fahad-ul-Amin ・ Mar 29 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Source code of project from this article on &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/bormando/swag-tests/pull/2/files" rel="noopener noreferrer"&gt;https://github.com/bormando/swag-tests/pull/2/files&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In short, it structures your code better, let's see how...&lt;/p&gt;




&lt;h1&gt;
  
  
  How it was
&lt;/h1&gt;

&lt;p&gt;It's pretty usual, when during a test you navigate from one page to another. In that case you need to import all pages involved into that spec file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import AuthPage from '../pages/auth.page'
import ProductsPage from '../pages/products.page'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if that test involves more pages? And usually spec file combines multiple test suites - which probably means A LOT of pages if we combine all tests.&lt;/p&gt;




&lt;h1&gt;
  
  
  How to improve it
&lt;/h1&gt;

&lt;p&gt;We can declare a folder that contains page objects to be a module (and technically it is). To do that, simply add &lt;code&gt;index.js&lt;/code&gt; file in the (&lt;code&gt;page&lt;/code&gt;) folder.&lt;/p&gt;

&lt;p&gt;This file is an "entry point" of our "pages" module. You say there what would you like to export from the module, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export * from './auth.page'
export * from './products.page'
export * from './cart.page'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;*&lt;/code&gt; means &lt;u&gt;everything&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;If you'd like to export ready-to-use page instances in &lt;a href="https://www.cypress.io" rel="noopener noreferrer"&gt;Cypress&lt;/a&gt; with this structure, you'll need to rewrite exports as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Page from './page'
...

export const CartPage = new class extends Page {
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code above says that new instance of the class will be created when you'll import this page in your tests. It's a bit different than &lt;code&gt;default&lt;/code&gt; export like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default new CartPage()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;default&lt;/code&gt; export lets you set any name you like when you import whatever you do, while the other construction sets a specific name for the instance that you export.&lt;/p&gt;

&lt;h1&gt;
  
  
  How it looks now
&lt;/h1&gt;

&lt;p&gt;Now you don't call every page file to import the page you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {AuthPage, ProductsPage} from '../pages'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pages&lt;/code&gt; folder is a module now and you name objects you'd like to get from there that were exported.&lt;/p&gt;

&lt;p&gt;This practice may be used with other modules as well, like &lt;a href="https://hackernoon.com/writing-better-tests-with-cypress-page-elements" rel="noopener noreferrer"&gt;Page Elements&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>qa</category>
      <category>automation</category>
      <category>cypress</category>
    </item>
    <item>
      <title>TypeScript Setup for REST API Tests</title>
      <dc:creator>Dmitrii Bormotov</dc:creator>
      <pubDate>Sun, 13 Nov 2022 18:21:16 +0000</pubDate>
      <link>https://forem.com/bormando/typescript-setup-for-rest-api-tests-188o</link>
      <guid>https://forem.com/bormando/typescript-setup-for-rest-api-tests-188o</guid>
      <description>&lt;p&gt;Ahoy, mate!&lt;/p&gt;

&lt;p&gt;This topic may be useful for test automation engineers who just started to learn &lt;strong&gt;TypeScript&lt;/strong&gt;. It also extends my previous post:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/bormando" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F545185%2Fa804faea-7a4e-4abe-b5db-05754b83c6d4.png" alt="bormando"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/bormando/minimal-rest-api-tests-in-node-js-2jde" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Minimal REST API tests in Node.js&lt;/h2&gt;
      &lt;h3&gt;Dmitrii Bormotov ・ Dec 24 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#rest&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#node&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#testing&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#qa&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;TypeScript&lt;/strong&gt; is a &lt;strong&gt;JavaScript&lt;/strong&gt; superset in &lt;strong&gt;Node.js&lt;/strong&gt;, which brings static types and other useful features to your project.&lt;/p&gt;

&lt;p&gt;Under the hood, it transforms the code you written to the one that your platform understands (&lt;em&gt;ES5 standard&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Source code of project from this article on &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/bormando/mochapi/tree/future" rel="noopener noreferrer"&gt;https://github.com/bormando/mochapi/tree/future&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;You may clone a &lt;strong&gt;GitHub&lt;/strong&gt; repo with few example tests from here: &lt;a href="https://github.com/bormando/mochapi/tree/main" rel="noopener noreferrer"&gt;https://github.com/bormando/mochapi/tree/main&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After cloning, you must execute this command to download all required dependencies:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check, if cloned project is working, you may run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It should display something like this in the end:&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%2Fto92ymjxwvfowdfyumr1.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%2Fto92ymjxwvfowdfyumr1.png" alt="Code_tRvTtwQQkA" width="246" height="139"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Install TypeScript dependencies
&lt;/h1&gt;

&lt;p&gt;These are standard &lt;strong&gt;TypeScript&lt;/strong&gt; dependencies that we'll need to download:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;typescript&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ts-node&lt;/code&gt; (&lt;em&gt;to transform code from TypeScript to EcmaScript 5 standard on run&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, keep in mind that some &lt;strong&gt;Node.js&lt;/strong&gt; packages like &lt;code&gt;mocha&lt;/code&gt; &amp;amp; &lt;code&gt;chai&lt;/code&gt; doesn't come with &lt;strong&gt;TypeScript&lt;/strong&gt;, so you'll have to install them separately as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@types/mocha&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@types/chai&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install them all, you'll need to execute in terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -D typescript ts-node @types/mocha @types/chai&lt;/code&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  TypeScript configuration
&lt;/h1&gt;

&lt;p&gt;Now, as we've finished dependencies installation, we need to configure &lt;strong&gt;TypeScript&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Simply execute &lt;code&gt;npx tsc --init&lt;/code&gt; in your project root which will create &lt;code&gt;tsconfig.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I recommend these options for new projects:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Don't forget to save changes.&lt;/p&gt;




&lt;h1&gt;
  
  
  ES5 vs TypeScript
&lt;/h1&gt;

&lt;p&gt;You may read about base differences between &lt;strong&gt;ES5&lt;/strong&gt; and &lt;strong&gt;TypeScript&lt;/strong&gt; here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/geekculture/typescript-vs-javascript-e5af7ab5a331" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afill%3A88%3A88%2F1%2AFkVz3b518e9j6c_OuvfOfQ.png" alt="Avelon Pang"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/geekculture/typescript-vs-javascript-e5af7ab5a331" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;TypeScript vs. JavaScript. Why was TypeScript developed when we… | by Avelon Pang | Geek Culture | Medium&lt;/h2&gt;
      &lt;h3&gt;Avelon Pang ・ &lt;time&gt;Jun 23, 2021&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In our current project, all you'll have to do is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rename &lt;code&gt;markets.test.js&lt;/code&gt; to &lt;code&gt;markets.test.ts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Change imports in &lt;code&gt;markets.test.ts&lt;/code&gt; file...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const axios = require('axios');
const assert = require('chai').assert;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from 'axios';
import { assert } from 'chai';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the small changes but this is all we need to make sure that our &lt;strong&gt;TypeScript&lt;/strong&gt; setup works fine (since this is the point of current article).&lt;/p&gt;




&lt;h1&gt;
  
  
  Reconfigure shortcut
&lt;/h1&gt;

&lt;p&gt;Shortcut for running &lt;strong&gt;Mocha&lt;/strong&gt; tests in &lt;strong&gt;ES5&lt;/strong&gt; looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"test": "npx mocha src/specs"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You may find it in &lt;code&gt;scripts&lt;/code&gt; section inside of &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;To convert code &lt;strong&gt;TypeScript&lt;/strong&gt; code to &lt;strong&gt;JavaScript&lt;/strong&gt; on-run, you need to change this shortcut on something like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"test": "npx mocha --require ts-node/register src/specs/**/*.test.ts"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ts-node/register&lt;/code&gt; works as a converter in this case.&lt;/p&gt;

&lt;p&gt;Also notice &lt;code&gt;src/specs/**/*.test.ts&lt;/code&gt; in the end - now we have to specify test files pattern, as &lt;strong&gt;Mocha&lt;/strong&gt; looks for &lt;code&gt;.js&lt;/code&gt; files by default.&lt;/p&gt;




&lt;h1&gt;
  
  
  Running tests
&lt;/h1&gt;

&lt;p&gt;We're good to go by now, so all you have to do is execute in terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And then you must see report in your terminal output:&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%2Fto92ymjxwvfowdfyumr1.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%2Fto92ymjxwvfowdfyumr1.png" alt="Code_tRvTtwQQkA" width="246" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading, hope you've learned something new.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>testing</category>
      <category>api</category>
      <category>qa</category>
    </item>
    <item>
      <title>Node.js debugging in automated tests</title>
      <dc:creator>Dmitrii Bormotov</dc:creator>
      <pubDate>Thu, 14 Jul 2022 20:24:03 +0000</pubDate>
      <link>https://forem.com/bormando/nodejs-debugging-in-automated-tests-ead</link>
      <guid>https://forem.com/bormando/nodejs-debugging-in-automated-tests-ead</guid>
      <description>&lt;p&gt;Ahoy, mate!&lt;/p&gt;

&lt;p&gt;This topic may be useful for those who started test automation in &lt;strong&gt;Node.js&lt;/strong&gt; recently. The article is written in POV of test automation engineer, but I'm sure that every other beginner in &lt;strong&gt;Node.js&lt;/strong&gt; will find it useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's debugging and why I'd need it?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Debugging" rel="noopener noreferrer"&gt;Debugging is the process of finding and resolving bugs.&lt;/a&gt; In other words, when we run some code and it doesn't act as expected - we seek for lines of code that cause this misbehaviour.&lt;/p&gt;

&lt;p&gt;There are two ways of getting information from your code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Logging.&lt;/li&gt;
&lt;li&gt;Attaching a debugger.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Logging
&lt;/h2&gt;

&lt;p&gt;I think you're already familiar with this one. When you execute some command, you simply use &lt;code&gt;console.log()&lt;/code&gt; to log its result into console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const result = 2 + 3
console.log(result) // 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const response = await axios.get(url)
const body = response.data
console.log(body)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sounds familiar?&lt;/p&gt;

&lt;h2&gt;
  
  
  Attaching a debugger
&lt;/h2&gt;

&lt;p&gt;Instead of logging every inch of your app, it'd probably be a good idea to just point a few lines of code in your project where you'd like to stop for a while and inspect what's going on at these specific lines.&lt;/p&gt;

&lt;p&gt;Let's say that we execute an &lt;strong&gt;HTTP request&lt;/strong&gt; with &lt;a href="https://www.npmjs.com/package/axios" rel="noopener noreferrer"&gt;Axios&lt;/a&gt; and for some reason your tests are failing and you see that response body doesn't match the one that expected.&lt;/p&gt;

&lt;p&gt;Time to &lt;del&gt;log this sh&lt;/del&gt; attach a debugger!&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Studio Code
&lt;/h2&gt;

&lt;p&gt;First, simply mark a line of code (click to the left of the line number) where you'd like to stop when your tests will be executed. There &lt;strong&gt;red dots&lt;/strong&gt; are &lt;strong&gt;breakpoints&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%2Fuploads%2Farticles%2Fe0qv1xd3gsiuhuyyv8a2.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%2Fe0qv1xd3gsiuhuyyv8a2.png" alt="Breakpoints in Visual Studio Code" width="800" height="359"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After that, instead of using your regular terminal, open `JavaScript Debug Terminal:&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%2F0769sfi5dea4yyfpyn4w.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%2F0769sfi5dea4yyfpyn4w.png" alt="JavaScript Debug Terminal" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this terminal you may simply use the command that you were using to execute your tests (like &lt;code&gt;npm test&lt;/code&gt;) as usual.&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%2F6xqa90uaw882bg6davbh.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%2F6xqa90uaw882bg6davbh.png" alt="Debug process in Visual Studio Code" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your test run will make a stop at the breakpoint &lt;strong&gt;(1)&lt;/strong&gt;. You'll see the cached data that you may reach from the current line of code &lt;strong&gt;(2)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You may go to the next breakpoint from there &lt;strong&gt;(3)&lt;/strong&gt; or restart your current run &lt;strong&gt;(4)&lt;/strong&gt; or detach debugger &lt;strong&gt;(5)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You may find other ways to attach a debugger in &lt;strong&gt;VSC&lt;/strong&gt;, but I prefer this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  WebStorm
&lt;/h2&gt;

&lt;p&gt;It's pretty similar to &lt;strong&gt;Visual Studio Code&lt;/strong&gt; in the first step - you mark the line of code that you need as a breakpoint:&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%2F2sjuc437qnxlbis7sbjc.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%2F2sjuc437qnxlbis7sbjc.png" alt="Breakpoints in WebStorm" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then you run your code almost as usual, but use &lt;strong&gt;debug&lt;/strong&gt; (bug) icon instead:&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%2F4lpepon5sejyttjmyuxh.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%2F4lpepon5sejyttjmyuxh.png" alt="Debugger icon in WebStorm" width="672" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your test run will make a stop at the breakpoint &lt;strong&gt;(1)&lt;/strong&gt;. You'll see the cached data that you may reach from the current line of code &lt;strong&gt;(2)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You may go to the next breakpoint from there &lt;strong&gt;(3)&lt;/strong&gt; or restart your current run &lt;strong&gt;(4)&lt;/strong&gt; or stop execution &lt;strong&gt;(5)&lt;/strong&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%2F1ma4ttd0m0pnb2qxbi8q.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%2F1ma4ttd0m0pnb2qxbi8q.png" alt="Debugging process in WebStorm" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Debugger helps us with inspection of the data that we store in application's cache. You don't need to add &lt;code&gt;console.log()&lt;/code&gt; anymore to see what's going on (especially, if there's more than one thing that you want to log).&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%2F6tio5kyqoaeln4erruq0.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%2F6tio5kyqoaeln4erruq0.png" alt="HTTP response data in debugger" width="800" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think most of you'll agree that this method is more useful and interactive than logging. Plus, it's more readable when you have a lot of data to process (like a very long array or an object), since you can fold/unfold whole sections (objects/arrays). &lt;/p&gt;

&lt;p&gt;Thanks for reading, hope you've learned something new.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webstorm</category>
      <category>vscode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Babel Setup for REST API Tests</title>
      <dc:creator>Dmitrii Bormotov</dc:creator>
      <pubDate>Thu, 28 Jan 2021 20:15:05 +0000</pubDate>
      <link>https://forem.com/bormando/babel-setup-for-rest-api-tests-1dhf</link>
      <guid>https://forem.com/bormando/babel-setup-for-rest-api-tests-1dhf</guid>
      <description>&lt;p&gt;Ahoy, mate!&lt;/p&gt;

&lt;p&gt;This topic may be useful for beginners in Test Automation or those testers who works with other languages (&lt;em&gt;like Java or Python&lt;/em&gt;) and new to &lt;strong&gt;JavaScript&lt;/strong&gt; (&lt;em&gt;Node.js&lt;/em&gt;). It also expands my previous post:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/bormando" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F545185%2Fa804faea-7a4e-4abe-b5db-05754b83c6d4.png" alt="bormando"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/bormando/minimal-rest-api-tests-in-node-js-2jde" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Minimal REST API tests in Node.js&lt;/h2&gt;
      &lt;h3&gt;Dmitrii Bormotov ・ Dec 24 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#rest&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#node&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#testing&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#qa&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Babel&lt;/strong&gt; is a tool that convert &lt;strong&gt;ES5&lt;/strong&gt; to modern versions (&lt;em&gt;ES6+&lt;/em&gt;) of code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ES&lt;/strong&gt; (&lt;em&gt;ECMAScript&lt;/em&gt;) is a &lt;strong&gt;JavaScript&lt;/strong&gt; standard meant to ensure the interoperability of web pages across different web browsers. &lt;strong&gt;ECMAScript&lt;/strong&gt; is commonly used for client-side scripting on the &lt;strong&gt;W&lt;/strong&gt;orld &lt;strong&gt;W&lt;/strong&gt;ide &lt;strong&gt;W&lt;/strong&gt;eb, and it is increasingly being used for writing server applications and services using &lt;strong&gt;Node.js&lt;/strong&gt;. By default, &lt;strong&gt;Node.js&lt;/strong&gt; uses &lt;strong&gt;ES5&lt;/strong&gt;, which was released a long time ago, in 2009.&lt;/p&gt;

&lt;p&gt;Source code of project from this article on &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/bormando/mochapi/tree/modern" rel="noopener noreferrer"&gt;https://github.com/bormando/mochapi/tree/modern&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;You may clone a &lt;strong&gt;GitHub&lt;/strong&gt; repo with few example tests from here: &lt;a href="https://github.com/bormando/mochapi/tree/main" rel="noopener noreferrer"&gt;https://github.com/bormando/mochapi/tree/main&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After cloning, you must execute this command to download all required dependencies:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check, if cloned project is working, you may run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It should display something like this in the end:&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%2Fto92ymjxwvfowdfyumr1.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%2Fto92ymjxwvfowdfyumr1.png" alt="Code_tRvTtwQQkA" width="246" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Install Babel dependencies
&lt;/h1&gt;

&lt;p&gt;These are standard &lt;strong&gt;Babel&lt;/strong&gt; dependencies that we'll need to download:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@babel/cli&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@babel/core&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@babel/plugin-transform-runtime&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@babel/preset-env&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@babel/register&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install them, you'll need to execute in terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -D @babel/cli @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register&lt;/code&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Babel configuration
&lt;/h1&gt;

&lt;p&gt;Now, as we've finished dependencies installation, we need to configure &lt;strong&gt;Babel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Simply create &lt;code&gt;.babelrc&lt;/code&gt; file in root directory of our project and add this data to it:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Don't forget to save changes.&lt;/p&gt;




&lt;h1&gt;
  
  
  ES5 to ES6+
&lt;/h1&gt;

&lt;p&gt;You may read about most of the changes between &lt;strong&gt;ES5&lt;/strong&gt; and &lt;strong&gt;ES6+&lt;/strong&gt; with examples here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://muthuks.medium.com/difference-between-es-5-and-es-6-e993c7ab0a70" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afill%3A88%3A88%2F2%2A1T54aHagpvEuKZI64PTmzg.jpeg" alt="Muthukumaraswamy"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://muthuks.medium.com/difference-between-es-5-and-es-6-e993c7ab0a70" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Difference between ES 5 and ES 6. Let me summarises the difference es5 vs… | by Muthukumaraswamy | Medium&lt;/h2&gt;
      &lt;h3&gt;Muthukumaraswamy ・ &lt;time&gt;Jan 31, 2019&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        muthuks.Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In our current project, all you'll have to do is to change imports in &lt;code&gt;markets.test.js&lt;/code&gt; file…&lt;/p&gt;

&lt;p&gt;From this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const axios = require('axios');
const assert = require('chai').assert;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from 'axios';
import { assert } from 'chai';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the small changes but this is all we need to make sure that our &lt;strong&gt;Babel&lt;/strong&gt; setup works fine (since this is the point of current article).&lt;/p&gt;




&lt;h1&gt;
  
  
  Reconfigure shortcut
&lt;/h1&gt;

&lt;p&gt;Shortcut for running &lt;strong&gt;Mocha&lt;/strong&gt; tests in &lt;strong&gt;ES5&lt;/strong&gt; looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"test": "npx mocha src/specs"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You may find it in &lt;code&gt;scripts&lt;/code&gt; section inside of &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;To convert code &lt;strong&gt;ES6+&lt;/strong&gt; code to &lt;strong&gt;ES5&lt;/strong&gt; on-run, you need to change this shortcut on something like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"test": "npx mocha --require @babel/register src/specs"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--require @babel/register&lt;/code&gt; works as a converter in this case.&lt;/p&gt;




&lt;h1&gt;
  
  
  Running tests
&lt;/h1&gt;

&lt;p&gt;We're good to go by now, so all you have to do is execute in terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And then you must see report in your terminal output:&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%2Fto92ymjxwvfowdfyumr1.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%2Fto92ymjxwvfowdfyumr1.png" alt="Code_tRvTtwQQkA" width="246" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading, hope you've learned something new.&lt;/p&gt;

</description>
      <category>qa</category>
      <category>rest</category>
      <category>testing</category>
      <category>babel</category>
    </item>
    <item>
      <title>Minimal REST API tests in Node.js</title>
      <dc:creator>Dmitrii Bormotov</dc:creator>
      <pubDate>Thu, 24 Dec 2020 19:07:55 +0000</pubDate>
      <link>https://forem.com/bormando/minimal-rest-api-tests-in-node-js-2jde</link>
      <guid>https://forem.com/bormando/minimal-rest-api-tests-in-node-js-2jde</guid>
      <description>&lt;p&gt;Ahoy, mate!&lt;/p&gt;

&lt;p&gt;This topic may be useful for beginners in Test Automation or those testers who works with other languages (&lt;em&gt;like Java or Python&lt;/em&gt;) and new to &lt;strong&gt;JavaScript&lt;/strong&gt; (&lt;em&gt;Node.js&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Source code of project from this article on &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/bormando/mochapi/tree/main" rel="noopener noreferrer"&gt;https://github.com/bormando/mochapi/tree/main&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Tools
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;REST&lt;/strong&gt; (&lt;em&gt;&lt;strong&gt;RE&lt;/strong&gt;presentational &lt;strong&gt;S&lt;/strong&gt;tate &lt;strong&gt;T&lt;/strong&gt;ransfer&lt;/em&gt;) is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other.&lt;/p&gt;

&lt;p&gt;This is the one of most popular &lt;strong&gt;API&lt;/strong&gt; architectures, so we're going to test one of it's creatures.&lt;/p&gt;

&lt;p&gt;For minimal configuration we're going to need these:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test runner&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This tool allows us to define test scenarios and combine them into test suites. It also allows us to run these scenarios and suites. One of the most popular test runners for &lt;strong&gt;Node.js&lt;/strong&gt; is &lt;strong&gt;Mocha&lt;/strong&gt; - we'll use this one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Assertion library&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Assertion library is a set of assertions (&lt;em&gt;or expectations&lt;/em&gt;) for our test scenarios. Test runners usually contains some basic assertions set, but we're going to include this one too so we could accustom beginners to these libraries, especially &lt;strong&gt;Chai&lt;/strong&gt; (this is our choice for current article).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;HTTP client&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And this one makes &lt;strong&gt;REST API&lt;/strong&gt; test automation possible. This is a tool that sends requests to &lt;strong&gt;HTTP (API) server&lt;/strong&gt;. One of the most popular solutions in this area is &lt;strong&gt;Axios&lt;/strong&gt; - this is our guy.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll also need &lt;a href="https://www.postman.com/" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; or similar tool (&lt;em&gt;f.e. SoapUI, TestMace, Insomnia&lt;/em&gt;) to send few requests manually.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; as IDE.&lt;/p&gt;

&lt;p&gt;As an example of &lt;strong&gt;REST API&lt;/strong&gt; server, we'll use public endpoint of crypto market &lt;strong&gt;Bitfinex&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GET&lt;/strong&gt; &lt;a href="https://api-pub.bitfinex.com/v2/ticker/tBTCUSD" rel="noopener noreferrer"&gt;https://api-pub.bitfinex.com/v2/ticker/tBTCUSD&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;First of all, we'll need to create a project directory. After that, we must open it in &lt;strong&gt;console&lt;/strong&gt; (&lt;em&gt;terminal in MacOS/Linux or CMD/PowerShell in Windows&lt;/em&gt;) and execute command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this command execution you'll find &lt;strong&gt;package.json&lt;/strong&gt; file in your project's root directory. This file contains your package info, we'll get back to it later.&lt;/p&gt;

&lt;p&gt;Next, we need to install dependencies (chosen tools from previous section):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i -D mocha chai axios&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, when we have our package initialized and dependencies installed - we need to create files and folders structure...&lt;/p&gt;

&lt;p&gt;In project's root directory we'll create &lt;strong&gt;src&lt;/strong&gt; directory, and then &lt;strong&gt;specs&lt;/strong&gt; as a subdirectory of &lt;strong&gt;src&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;src&lt;/strong&gt; is a primary place for our project's code,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;specs&lt;/strong&gt; contains test suites.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;specs&lt;/strong&gt; directory we create &lt;strong&gt;markets.test.js&lt;/strong&gt; file. Here we'll define our test scenarios.&lt;/p&gt;

&lt;p&gt;At current state our project structure should look like this:&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%2Frq9igtltmxf25ixnuimg.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%2Frq9igtltmxf25ixnuimg.png" alt="Code_BCgWQlQPsA" width="141" height="119"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Test cases
&lt;/h1&gt;

&lt;p&gt;Let's make a &lt;strong&gt;GET&lt;/strong&gt; request to the &lt;strong&gt;API&lt;/strong&gt; endpoint that we're testing: &lt;a href="https://api-pub.bitfinex.com/v2/ticker/tBTCUSD" rel="noopener noreferrer"&gt;https://api-pub.bitfinex.com/v2/ticker/tBTCUSD&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%2Fi%2F075fjjs0qlhg1zdjjcme.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%2F075fjjs0qlhg1zdjjcme.png" alt="Postman_YbiqvDHkpH" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the response body looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    23003,
    26.09947727,
    23004,
    32.433429860000004,
    -948,
    -0.0396,
    23003,
    13562.61526307,
    24052.99388042,
    21884
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response body&lt;/strong&gt; contains list of numbers and this structure won't change if you'll execute this request few more times, only values will (&lt;em&gt;since this pair is being traded without stop&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;So, we can define at least 3 test scenarios here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Status-code of response must be &lt;strong&gt;200&lt;/strong&gt; (&lt;em&gt;OK&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;Response body must contain list with length of 10 values (&lt;em&gt;nor more nor less&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;Response body must contain list with number values only.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Coding
&lt;/h1&gt;

&lt;p&gt;Finally, we can start writing code to automate our test scenarios. First of all, we have to define our test suite - let's name it &lt;strong&gt;'price data'&lt;/strong&gt;, since we're checking on &lt;strong&gt;BTC/USD&lt;/strong&gt; pair on crypto market:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('price data', () =&amp;gt; {
    // test scenarios and/or hooks
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Previously, we have defined test scenarios for automation, so let's hold on for a second and think for something that they have in common. Of course, it's the data that they check on. So what can we do to not to duplicate our code (and not to execute a request in each test)? We'll use hooks (or actually, a hook)!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const axios = require('axios');

describe('price data', () =&amp;gt; {
    let data;

    before(async () =&amp;gt; {
        await axios.get('https://api-pub.bitfinex.com/v2/ticker/tBTCUSD')
            .then((response) =&amp;gt; {
                data = response;
            });
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we've added &lt;strong&gt;Axios&lt;/strong&gt; import into our test suite, so we could execute requests to our &lt;strong&gt;API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Hook &lt;strong&gt;'before'&lt;/strong&gt; is being executed before all the tests in our test suite, so we gather data using &lt;strong&gt;Axios&lt;/strong&gt; and store it into data variable, that is defined just above the &lt;strong&gt;'before'&lt;/strong&gt; hook.&lt;/p&gt;

&lt;p&gt;Also, pay attention that &lt;strong&gt;await&lt;/strong&gt; is used so we could wait for request to finish execution so we could continue. If you won't use await - you'll have &lt;strong&gt;data&lt;/strong&gt; variable undefined in your tests.&lt;/p&gt;

&lt;p&gt;Next, we're going to add our three test scenarios and import &lt;strong&gt;Chai&lt;/strong&gt; to check on assertions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const axios = require('axios');
const assert = require('chai').assert;

describe('price data', () =&amp;gt; {
    let data;

    before(async () =&amp;gt; {
        await axios.get('https://api-pub.bitfinex.com/v2/ticker/tBTCUSD')
            .then((response) =&amp;gt; {
                data = response;
            });
    });

    it('has 200 response code', () =&amp;gt; {
        assert.equal(data.status, 200, 'the response code is not 200');
    });

    it('contains 10 values', () =&amp;gt; {
        assert.equal(data.data.length, 10, 'number of values is not 10');
    });

    it('values should be numbers', () =&amp;gt; {
        for (const value of data.data) {
            assert.isNumber(value, `value '${value}' is not a number`);
        }
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First one simply checks if status field from our test data is &lt;strong&gt;200&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Second scenario gets length of response body's list and collates it with 10.&lt;/p&gt;

&lt;p&gt;Third and final case is using &lt;strong&gt;for loop&lt;/strong&gt; to cycle through response body list's values and checks if every value is a number.&lt;/p&gt;

&lt;p&gt;Seems pretty easy to understand and code, huh?&lt;/p&gt;




&lt;h1&gt;
  
  
  Running tests
&lt;/h1&gt;

&lt;p&gt;Let's get back to &lt;strong&gt;package.json&lt;/strong&gt; file that is being stored in our project's root directory...&lt;/p&gt;

&lt;p&gt;Find &lt;code&gt;test&lt;/code&gt; key and replace it's &lt;code&gt;value&lt;/code&gt; (&lt;em&gt;not key&lt;/em&gt;) with &lt;code&gt;npx mocha src/specs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can add description and author values if you like, but that's not not necessary.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;package.json&lt;/code&gt; file should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "mochapi",
  "version": "1.0.0",
  "description": "API test automation with Mocha and Axios",
  "scripts": {
    "test": "npx mocha src/specs"
  },
  "keywords": [],
  "author": "Dmitrii Bormotov",
  "license": "ISC",
  "devDependencies": {
    "axios": "^0.21.0",
    "chai": "^4.2.0",
    "mocha": "^8.2.1"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can run your tests by simply executing command in console while in your project's root directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run test&lt;/code&gt; or &lt;code&gt;npm test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After run completion, you'll see report like this:&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%2Fto92ymjxwvfowdfyumr1.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%2Fto92ymjxwvfowdfyumr1.png" alt="Code_tRvTtwQQkA" width="246" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you may consider yourself &lt;em&gt;REST API&lt;/em&gt; test automator. :)&lt;/p&gt;

&lt;p&gt;Thanks for reading, hope you've learned something new.&lt;/p&gt;

</description>
      <category>rest</category>
      <category>node</category>
      <category>testing</category>
      <category>qa</category>
    </item>
  </channel>
</rss>
