<?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>DEV Community: Takshak Ramteke</title>
    <description>The latest articles on DEV Community by Takshak Ramteke (@takshakramteke).</description>
    <link>https://dev.to/takshakramteke</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%2F731438%2Fff9ede94-b544-4241-8d4f-e08e4e68772b.jpeg</url>
      <title>DEV Community: Takshak Ramteke</title>
      <link>https://dev.to/takshakramteke</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/takshakramteke"/>
    <language>en</language>
    <item>
      <title>🗿 Get Some (Github) Action</title>
      <dc:creator>Takshak Ramteke</dc:creator>
      <pubDate>Mon, 15 Aug 2022 17:50:18 +0000</pubDate>
      <link>https://dev.to/takshakramteke/get-some-github-action-1mmg</link>
      <guid>https://dev.to/takshakramteke/get-some-github-action-1mmg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Github Actions&lt;/strong&gt;, If you haven't heard already then please allow me tell you calling it amazing would be an understatement !&lt;/p&gt;

&lt;p&gt;I personally think, It is one of those once in a decade things that endup having a super huge impact on the whole industry, &lt;/p&gt;

&lt;p&gt;GitHub Actions is one of those things that just perfectly embodies rule 34(for devs), think anything of the top of your head and there's a high chance that there's a github action made for it already.&lt;/p&gt;

&lt;p&gt;And Im not joking either, there's literally a github action for everything you may need e.g.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[x] Deploying a next.js app to github pages,&lt;/li&gt;
&lt;li&gt;[x] making automatic releases,&lt;/li&gt;
&lt;li&gt;[x] greet a new contributor,&lt;/li&gt;
&lt;li&gt;[x] setting up entire dev enviornment,
And much more !&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And So today in this blog i'd like to ask you to come along with me on a little adventure, as we go through some stuff about github actions and dare i mention try creating one of our very own github action, &lt;/p&gt;

&lt;p&gt;And if you hadn't already guessed by the big image, yes we'll be having ourselves some docker goodness as well, So without further ado, lets begin&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Github Action ?
&lt;/h3&gt;

&lt;p&gt;Well on the surface "GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline."&lt;/p&gt;

&lt;p&gt;But as you may guess there's more to it than that Github actions goes beyond just the realm of devops and allows us to run workflows in our repo when some or the other event occur &lt;/p&gt;

&lt;p&gt;Now when talking about Github Actions, we should also talk about &lt;/p&gt;

&lt;h3&gt;
  
  
  The Components of Github Actions
&lt;/h3&gt;

&lt;p&gt;There are two componets to a github actions &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;an &lt;strong&gt;Action&lt;/strong&gt;, which is the action itself and&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;Workflow&lt;/strong&gt;, which is a automated processes that &lt;em&gt;uses an action&lt;/em&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A workflow can contain one or more set of different actions which are run in their own seprate containers either in parallel or in the specified sequence &lt;/p&gt;

&lt;p&gt;now since we've discussed the components of github actions, It's only fair to have a look at &lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Github Actions
&lt;/h3&gt;

&lt;p&gt;As of now there are only two types of actions&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Container actions&lt;/strong&gt; : These are the actions that use a Dockerfile, These allow the enviornment to be packaged with github action code and can only be executed in github Hosted linux enviornments, needless to say this is the one we'll be looking at today.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript actions&lt;/strong&gt; : Yet another implementation of JS, these type of actions decouple the github actions code from the enviornment allowing faster execution but accepting greater dependency management responsibility.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was all just a small intro about Github actions, if you want to learn more about it in depth i recommend checking out the &lt;a href="https://docs.github.com/en/actions" rel="noopener noreferrer"&gt;docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now That we have some background knowledge of what a Github action is, Let's start by setting up our first &amp;amp; very own github action &lt;/p&gt;

&lt;p&gt;(spoiler alert it takes only 5 steps to do so)&lt;/p&gt;

&lt;p&gt;ps. create a new empty repo before you start following along&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 : Adding a Dockerfile
&lt;/h2&gt;

&lt;p&gt;In the newly created repo create a docker file with the following contents in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; debian:9.5-slim&lt;/span&gt;

&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; index.sh /index.sh&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x /index.sh
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["/index.sh"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Dockerfile is like a blueprint to our container that is going to run our code for this action, i recommend you do this on a seprate branch from main&lt;/p&gt;

&lt;p&gt;Here at line 1 we tell github that the base image for this pirticular action should be debian which is a linux distro then further ahead &lt;br&gt;
We tell it to use the index.sh script as the entrypoint into our action &lt;/p&gt;

&lt;p&gt;You might be wondering &lt;strong&gt;why bash&lt;/strong&gt;, well the reason for that is, We don't have any extra programs on debian image other than the essential linux programs (like seriously not even curl is intalled in there), &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2 : Adding the entrypoint script
&lt;/h2&gt;

&lt;p&gt;Now in the same directory as the dockerfile create a index.sh script with the contents you want to execute, I've just keet it simple for the sake of simplicity in this blog&lt;br&gt;
please I encourage you to experiment with this yourself&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"message : &lt;/span&gt;&lt;span class="nv"&gt;$INPUT_MESSAGE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you can't tell already, all this line does is print out what ever the value of INPUT_MESSAGE is simple, we'll pass in this variable when we use this action inside of a workflow&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 : Adding some metadata for our action
&lt;/h2&gt;

&lt;p&gt;To add this metadata we'll have to create a yaml file, this file act's as a sort of configuration file for our action. Also it's in here that we'll specify an input parameter in order to read &lt;code&gt;MESSAGE&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;So go ahead and create a &lt;code&gt;action.yml&lt;/code&gt; file in the same folder as the other two files, with the following content's in it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;get&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;some&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;github&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;action"&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;action&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;get&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;some&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;github&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;action"&lt;/span&gt;
&lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TakshakRamteke@users.noreply.github.com"&lt;/span&gt;

&lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;MESSAGE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Message&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;print&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;out"&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;runs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;using&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;docker"&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Dockerfile"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While I personally think most of this is self explanatory, the super important things to look out for are the inputs and runs, &lt;/p&gt;

&lt;p&gt;As you can probably tell in the inputs section we're setting up the &lt;code&gt;MESSAGE&lt;/code&gt; variable that we used previously in our bash code, here you can define as many inputs as you want and you can also provide a default value for them if you want to &lt;/p&gt;

&lt;p&gt;As for the &lt;code&gt;runs&lt;/code&gt; section, this is where we define how this action is supposed to be run e.g. in this one we tell it to run using docker and use the Dockerfile to build our image&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 : Add a workflow
&lt;/h2&gt;

&lt;p&gt;Now as we discussed earlier, in order to run a action we'll need to use it inside of a workflow&lt;/p&gt;

&lt;p&gt;To do that we need to create a &lt;em&gt;yml&lt;/em&gt; file inside of the &lt;code&gt;.github/worlflows/&lt;/code&gt; directory, So go ahead and create the aforementioned folder and inside of that create a &lt;code&gt;.yml&lt;/code&gt; file and add the following content into it, (i called mine &lt;code&gt;getsome.yml&lt;/code&gt; btw)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;workflow&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;get&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;some&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;github&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;action"&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;push&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;builds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Get some github action&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v1&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./action&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;MESSAGE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GOT&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;SOME&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;GITHUB&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;ACTION&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;🏆"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the first line is just the name that we want to give our action and it goes without saying that you can name it whatever you want&lt;/p&gt;

&lt;p&gt;the next line tho is where we specify the event on which this action to trigger on, for this one we keep it simple and just use the push event, which simply means that the action/workflow will run whenever something is pushed onto this branch, there are quite a lot of triggers that you can chose from tho,&lt;/p&gt;

&lt;p&gt;The next section is where all the magic happens, this part is called the action block and it is in here that we provide info on how to run our action, here's a little breakdown of this section&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;jobs:&lt;/code&gt; is the base component of a workflow&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build:&lt;/code&gt; is the identifier we're attaching to this job, you can name it however you like, i called it build because it builds our docker image 🤷&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name:&lt;/code&gt; is the name of the job, this is displayed on GitHub when the workflow is running&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;runs-on:&lt;/code&gt; defines the type of machine to run the job on. By default it is run on a GitHub-hosted runner, you can specify your own as well tho.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;steps:&lt;/code&gt;  are the &lt;em&gt;linear&lt;/em&gt; sequence of operations that make up a job, simple&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uses: actions/checkout@v1&lt;/code&gt; uses a community action called &lt;a href="https://github.com/actions/checkout" rel="noopener noreferrer"&gt;&lt;code&gt;checkout&lt;/code&gt;&lt;/a&gt; to allow the workflow to access the contents of the repository&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uses: ./action&lt;/code&gt; provides the relative path to the action you created in the &lt;code&gt;action&lt;/code&gt; directory of your repository&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;with&lt;/code&gt;: is used to specify the input variables that will be available to your action in the runtime environment. In this case, the input variable is &lt;code&gt;MESSAGE&lt;/code&gt; and i've assigned it a value of "GOT SOME GITHUB ACTION 🏆"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's basically a high level overview of each key that we use in this current workflow, not to mention there are quite literally ton of more other option that you can use&lt;/p&gt;

&lt;p&gt;Now onto our last step which is &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 : Trigger your workflow
&lt;/h2&gt;

&lt;p&gt;As the final step there isn't much to do here but make sure that if you've been following along At this point you're tree should something like so :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
|-- .github
|   `-- workflows
|       `-- getsome.yml
|-- action
|   |-- Dockerfile
|   |-- action.yml
|   `-- index.sh
`-- readme.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is then well done, all that's left to do is to stage and commit these changes and push them to github&lt;/p&gt;

&lt;p&gt;As soon as you do that navigate to the actions tab on you github repo and there you should see a an action running, click on it to see the action you just created in action and it should look something similar to 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%2Fuploads%2Farticles%2Fgc8y478yvq6xcyozr5dr.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%2Fgc8y478yvq6xcyozr5dr.png" alt="Action in Action" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see something similar to this, then &lt;strong&gt;Congratulations 🥂&lt;/strong&gt; you've just made your first github action&lt;/p&gt;

&lt;p&gt;Although it is quite the basic and we barely scratched the surface i highly encourage you to check out the &lt;a href="https://docs.github.com/en/actions" rel="noopener noreferrer"&gt;Github actions docs&lt;/a&gt; to learn more about it, &lt;/p&gt;

&lt;p&gt;The reason i wrote this blog is that i personally had quite a lot of fun building it and so i thought is should share it with others as well, Hope you folks liked and enjoyed it to and as always wish to see you in the next one 👋&lt;/p&gt;

&lt;p&gt;oh btw please feel free to checkout the &lt;a href="https://github.com/TakshakRamteke/get-some-github-action" rel="noopener noreferrer"&gt;github repo&lt;/a&gt; for this one, I'll be adding some more examples there soon&lt;/p&gt;

</description>
      <category>docker</category>
      <category>github</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>🌐 Around the headless landscape : Introduction</title>
      <dc:creator>Takshak Ramteke</dc:creator>
      <pubDate>Mon, 25 Jul 2022 17:51:00 +0000</pubDate>
      <link>https://dev.to/takshakramteke/around-the-headless-landscape-introduction-1aen</link>
      <guid>https://dev.to/takshakramteke/around-the-headless-landscape-introduction-1aen</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hey !!!&lt;/strong&gt;, Glad to see you there, as you might have guessed this is sort of a little introduction blog for a blog series that i started called &lt;em&gt;&lt;a href="https://dev.to/TakshakRamteke"&gt;Around the Headless landscape&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this series, we'll embark on a little adventure (whoo) where we'll have a look around all the majour headless cms providers and play with them to see how we can integrate them into our applications (&lt;a href="https://nextjs.org" rel="noopener noreferrer"&gt;next.js for me&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;So take out your laptops, strap on your seatbelts and get ready, because this one is going to be a lot more fun than you'd expect...&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%2Ffkrikngzz44vzwrj8ej2.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%2Ffkrikngzz44vzwrj8ej2.gif" alt="https://c.tenor.com/Cvwzv7Dy6DUAAAAC/edward-cowboy-bebop.gif" width="498" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But wait...&lt;/em&gt; If you're new around headless CMS space, Don’t worry i’ve got you covered 🙃, lets first quickly go over &lt;strong&gt;Some basic stuff&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So &lt;strong&gt;what even is a headless CMS ?&lt;/strong&gt;, well good question&lt;/p&gt;

&lt;p&gt;Let's say our friend edward over here finally found the treasure, now after all these year's of being a space cowboy, he finally want's to settle down &amp;amp; with all that money he want's to start his own ship business (fair enough ig 🤷‍♂️)&lt;/p&gt;

&lt;p&gt;Now for obvious purposes edward also want's to have a website for his business, now edward is a smart kid in his early day's he had learned a lot about computer science and to no ones surprise has awesome frontend skills&lt;/p&gt;

&lt;p&gt;but unfortunately he ain't no good with backend stuff, just making api call's and that's all he know's about backend&lt;/p&gt;

&lt;p&gt;Now in this situation edward can easily levrage some traditional &lt;em&gt;content management system (CMS)&lt;/em&gt; like wordpress. He can just, find a suitable theme, slap on some cool plugins, configure some stuff and tada he's got a fully functional website&lt;/p&gt;

&lt;p&gt;except there's a teeny-tiny problem here, edward's partner faye doesn't really like the look and feel of wordpress because of multiple reasons the biggest of which is &lt;em&gt;limited customisability to the frontend&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;now here's the main&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem with Traditional CMS
&lt;/h2&gt;

&lt;p&gt;you see when using traditional CMS you're (generally) locked in with a particular set of frontend and backend with little to no wiggle room at all, e.g. just like in the case with Wordpress the flexibility with frontend is kinda limited&lt;/p&gt;

&lt;p&gt;and that's where a&lt;/p&gt;

&lt;h2&gt;
  
  
  Headless CMS Come's In
&lt;/h2&gt;

&lt;p&gt;The whole point of a headless CMS is to have a seprate backend that act's as a single source of truth for all your content which is accessible via some api call's&lt;/p&gt;

&lt;p&gt;This way you can have whatever frontend you want to or even better display the same content on various platform via native apps&lt;/p&gt;

&lt;p&gt;So now all edward has to do now is to swap out wordpress with a headless cms provider for backend and he's pretty much good with any frontend that suit's him well&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 TL;DR&lt;/p&gt;

&lt;p&gt;A headless CMS is one seprate backend that act's as a single source of truth for all your content which is accessible via some api call's as compared to a traditional CMS where everything is coupled together&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that is pretty much as you'd need to know about a headless cms as long as you are familiar with frontend and making some api call's&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I will be using JavaScript (TypeScript) for the most part, but please feel free to switch that around however you see fit, after all the logic is going to be the same as always&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and that wrap's up this blog, well have a much more in depth look at every single headless provider in the further episodes of the series until then&lt;/p&gt;

&lt;p&gt;Please let me know if you have any questions in the comments and&lt;/p&gt;

&lt;p&gt;Thank you very much for reading this blog, hope to see you in the next one  ✌️&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>introduction</category>
      <category>jamstack</category>
    </item>
    <item>
      <title>🧪 E2E tests made easy with Cypress + Cucumber</title>
      <dc:creator>Takshak Ramteke</dc:creator>
      <pubDate>Fri, 01 Jul 2022 17:50:28 +0000</pubDate>
      <link>https://dev.to/takshakramteke/e2e-tests-made-easy-with-cypress-cucumber-1hj1</link>
      <guid>https://dev.to/takshakramteke/e2e-tests-made-easy-with-cypress-cucumber-1hj1</guid>
      <description>&lt;p&gt;If you're a developer I'm pretty sure end to end testing is something you've heard about a lot &lt;/p&gt;

&lt;p&gt;While it may “sound” like daunting task at first what if i tell you that there is a relatively easy way to implement it…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="err"&gt;Feature &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;Test&lt;/span&gt; &lt;span class="err"&gt;redirection&lt;/span&gt;

&lt;span class="err"&gt;Scenario &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;Test&lt;/span&gt; &lt;span class="err"&gt;the&lt;/span&gt; &lt;span class="err"&gt;redirect&lt;/span&gt; 
    &lt;span class="nf"&gt;Given &lt;/span&gt;that im on &lt;span class="s"&gt;"Home"&lt;/span&gt; page
    &lt;span class="nf"&gt;When &lt;/span&gt;i click &lt;span class="s"&gt;"#redirect"&lt;/span&gt;
    &lt;span class="nf"&gt;Then &lt;/span&gt;i should see &lt;span class="s"&gt;"Redirected"&lt;/span&gt; as &lt;span class="s"&gt;"h1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What you read just now is a fully functional test written in what is called a &lt;a href="https://cucumber.io/docs/gherkin/reference/" rel="noopener noreferrer"&gt;Gherkin&lt;/a&gt; syntax used by Cucumber which is a BDD testing tool and its open source ofcourse&lt;/p&gt;

&lt;p&gt;But Cucumber on it's own isn't really capable of doing E2E tests And That's where Cypress comes in to save the day&lt;/p&gt;

&lt;p&gt;Now, that's fine and all but&lt;/p&gt;

&lt;h3&gt;
  
  
  How exactly do we do it you may ask
&lt;/h3&gt;

&lt;p&gt;Well apparantly its quite the simple process thanks to the magic✨ that's open source and the hardwork of &lt;a href="https://github.com/badeball/cypress-cucumber-preprocessor" rel="noopener noreferrer"&gt;&lt;em&gt;badeball&lt;/em&gt;&lt;/a&gt; who created the &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.npmjs.com/package/cypress-cucumber-preprocessor" rel="noopener noreferrer"&gt;cypress-cucumber-preprocessor&lt;/a&gt;&lt;/em&gt; 🔥 which if you couldn’t guess already allows us to use cucumber along side cypress&lt;/p&gt;

&lt;p&gt;now as you might expect (almost) nothing in the tech industry works without a bit of configuration and this tool is no exception, though the good thing is that it is pretty simple to configure and as a matter of fact it can be done in 3 super easy steps&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 :&lt;/strong&gt; Install all the dependencies&lt;/p&gt;

&lt;p&gt;ofcoure 🤷 duh we’d have to do this one &amp;amp; it’s kinda self explanatory, you only need to install a few things i.e &lt;code&gt;cypress&lt;/code&gt;, &lt;code&gt;@badeball/cypress-cucumber-preprocessor&lt;/code&gt;, &lt;code&gt;esbuild&lt;/code&gt; and lastly &lt;code&gt;cypress-esbuild-preprocessor&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;To do so simply run the following command and watch it complete&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add --dev cypress @badeball/cypress-cucumber-preprocessor esbuild cypress-esbuild-preprocessor typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save-dev cypress @badeball/cypress-cucumber-preprocessor esbuild cypress-esbuild-preprocessor typescript&lt;/code&gt; if that’s your thing&lt;/p&gt;

&lt;p&gt;now you can throw in Typescript (💜) into this if you want to which I obviously did, but it’s totally optional &amp;amp; upto you&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 :&lt;/strong&gt;  Generating the basic configuration&lt;/p&gt;

&lt;p&gt;Now that we have all what we need let’s start the actual configuration but here’s the plot twist,&lt;/p&gt;

&lt;p&gt;Initially though you will not have the basic cypress configuration, to generate it simply run&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn cypress open&lt;/code&gt; or &lt;code&gt;npx cypress open&lt;/code&gt; if npm’s your thing &lt;/p&gt;

&lt;p&gt;And follow the dialogs to configure the e2e testing and that should give you a basic configuration that we need&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 :&lt;/strong&gt; The Actual Configuration&lt;/p&gt;

&lt;p&gt;Okay this time for sure&lt;/p&gt;

&lt;p&gt;Now that we have all the basic configuration we need lets start by telling cypress to use the .feature files (that’s the extension for a test written with cucumber), To do that all we need to do is specify the “specPattern” property in the &lt;em&gt;cypress.config.ts&lt;/em&gt; (or .js if youre using js)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cypress&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;e2e&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="nf"&gt;setupNodeEvents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="c1"&gt;//&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;specPattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;**/*.feature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that that’s out of the way lets focus on the other part which is actually using the preprocessor to do that we’ll have to use a bundler to process these &lt;em&gt;.feature&lt;/em&gt; files, there are many bundlers out there so you can use any bundler you want to, I personally prefer using esbuild because it is fast and easy to configure &lt;/p&gt;

&lt;p&gt;And so to do this all we have to do setup an &lt;em&gt;on()&lt;/em&gt; event handler and configure our cypress-cucumber-preprocessor plugin and the bundler inside of the &lt;em&gt;setupNodeEvents&lt;/em&gt; function that allows us to tap into, modify, or extend the internal behavior of Cypress&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cypress&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addCucumberPreprocessorPlugin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@badeball/cypress-cucumber-preprocessor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;createBundler&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@bahmutov/cypress-esbuild-preprocessor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;createEsbuildPlugin&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@badeball/cypress-cucumber-preprocessor/esbuild&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;e2e&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="nf"&gt;setupNodeEvents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nf"&gt;addCucumberPreprocessorPlugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;file:preprocessor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;createBundler&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;createEsbuildPlugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;specPattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;**/*.feature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And That’s all we’re done with the configuration all that’s left is to take it for a spin and write some tests&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing your First Test
&lt;/h3&gt;

&lt;p&gt;To write a test just add a &lt;em&gt;.feature&lt;/em&gt; file inside of the &lt;em&gt;“ cypress/e2e/ ”&lt;/em&gt; folder and creative a respective &lt;em&gt;spec&lt;/em&gt; file for it &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;what is a spec file?&lt;/strong&gt; you may ask well its a file that tells cypress how to process the statements inside of the feature file, you’ll see what i mean in just a sec&lt;/p&gt;

&lt;p&gt;So lets quickly write a feature file first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="kd"&gt;Feature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; Google.com
  &lt;span class="kn"&gt;Scenario&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; visting the frontpage
      &lt;span class="nf"&gt;When &lt;/span&gt;I visit google.com
      &lt;span class="nf"&gt;Then &lt;/span&gt;I should see Google as the Title
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it, all this test does is navigate to &lt;a href="http://google.com" rel="noopener noreferrer"&gt;google.com&lt;/a&gt; and check whether the title for the website is google or not, simple as that 🙃&lt;/p&gt;

&lt;p&gt;Now obviously you can do more complex stuff with this but for the sake of demo and simplicity let’s keep it to that for now&lt;/p&gt;

&lt;p&gt;And let’s move on to writing the actual spec file for this test, to do that just create a file ending in .ts (or .js) with the same name as that of the feature file e.g. google.ts if you called it google.feature&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;When&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Then&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@badeball/cypress-cucumber-preprocessor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;When&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I visit google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;visit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nc"&gt;Then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I should see Google as the Title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;should&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Google&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to run this test just run &lt;code&gt;yarn cypress run&lt;/code&gt; or &lt;code&gt;npx cypress run&lt;/code&gt; and if you followed through correctly then you’ll see the test pass 😌&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Step Definitions
&lt;/h3&gt;

&lt;p&gt;You don’t have to actually write a spec file for each &lt;em&gt;.feature&lt;/em&gt; file what you can do is use a common spec file and define all the reoccurring step definitions inside of it to do so add the following line inside of your &lt;em&gt;package.json&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"cypress-cucumber-preprocessor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"stepDefinitions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"cypress/e2e/common/index.ts"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and now you can define all the common step definitions inside of the index.ts and yes you can call this file whatever you want i call it index.ts because i kinda like it 🤷‍♂️&lt;/p&gt;

&lt;h3&gt;
  
  
  Reusable Step definitions
&lt;/h3&gt;

&lt;p&gt;YES, you read it right you can actually write reusable step definitions for the feature statements that you will probably use multiple times e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="kd"&gt;Feature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; Google.com
  &lt;span class="kn"&gt;Scenario&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; visting the frontpage
    &lt;span class="nf"&gt;When &lt;/span&gt;I visit &lt;span class="s"&gt;"google.com"&lt;/span&gt;
        &lt;span class="nf"&gt;Then &lt;/span&gt;I should see &lt;span class="s"&gt;"Google"&lt;/span&gt; as the &lt;span class="s"&gt;"title"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the double quotes on &lt;a href="http://google.com" rel="noopener noreferrer"&gt;google.com&lt;/a&gt;, Thats what we're going to use to make this statement reusable&lt;/p&gt;

&lt;p&gt;The main part is tho happens in the spec file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;When&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Then&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@badeball/cypress-cucumber-preprocessor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;When&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`I visit {string}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;visit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`https://&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nc"&gt;Then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`I should see {string} as the {string}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;should&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contain&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What we do here is take arguments from the feature statements inside the double quotes and then we use them as parameters in the callbacks&lt;/p&gt;

&lt;p&gt;And thus, We can now use these two statements as many times as we want to by just changing the values inside the double quotes &lt;/p&gt;

&lt;p&gt;And That is How you can make End to End Testing much more easy and Fun for beginners on your team&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hello there 👋, Thank you for reading to the bottom, Hope you liked this blog and that it was Helpfull to you in some way or the other, This is the first blog post i ever wrote so please feel free to point out some short commings if you find any constructive criticism is always welcomed&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thank you for Reading, and I hope to see you on next one&lt;/p&gt;

</description>
      <category>testing</category>
      <category>opensource</category>
      <category>cypress</category>
      <category>cucumbe</category>
    </item>
  </channel>
</rss>
