<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muhammet Topcu on Medium]]></title>
        <description><![CDATA[Stories by Muhammet Topcu on Medium]]></description>
        <link>https://medium.com/@muhammettopcu?source=rss-f60deb85e587------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8rawr5_F3AScEhwtvVYn9A.jpeg</url>
            <title>Stories by Muhammet Topcu on Medium</title>
            <link>https://medium.com/@muhammettopcu?source=rss-f60deb85e587------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:30:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muhammettopcu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 6]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-6-5ce4bfd6f2e0?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ce4bfd6f2e0</guid>
            <category><![CDATA[keda]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 20:41:55 GMT</pubDate>
            <atom:updated>2025-12-10T14:41:48.648Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 6</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqPMs5aGPNnNdjffMfnAdA.jpeg" /></figure><p>Welcome to the 6th part of the blog post series called “Creating an End-to-End Web Test Automation Project from Scratch.” It was a long series, I know. But we are in the final round! So please, just bear with me! 🐻</p><p>So far, we have covered many topics, from the creation of a project to integrating it with CI/CD pipeline. If you need to review the previous chapters, you can find the articles at the links below.</p><ol><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><a href="https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a"><em>Bonus: Recording Failed Scenario Runs in Ruby</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1"><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f"><em>Let’s Dockerize Our Web Test Automation Project</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-1-f8e02c223603"><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-5-40023c5feecc"><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></a></li><li><strong><em>Auto-Scaling and Kubernetes Integration with KEDA</em></strong></li></ol><h3>Auto-Scaling and Kubernetes Integration with KEDA</h3><p>You will make a magic touch, which will enable you to auto-scale your Selenium Grid with the help of <strong>KEDA</strong>, <strong>Kubernetes Event-driven Autoscaling</strong>. KEDA will help you scale your nodes not according to CPU or RAM usage but according to the queue size of our tests to be run! Now, if you are ready, let’s get down to it!</p><h4>Minikube Installation</h4><p>First you are going to install <strong>minikube</strong> to create a kubernetes instance in your local machine.</p><p>Let’s install minikube with brew:</p><pre>brew install minikube</pre><p>If you do not want to use brew or if you have another OS, you can go to the <a href="https://minikube.sigs.k8s.io/docs/start/">official minikube site </a>and install it by choosing our <strong>OS</strong> and <strong>CPU Architecture</strong> type.</p><p>Now let’s start minikube:</p><pre>minikube start --vm-driver=docker</pre><p>Here, the -<strong>-vm-driver</strong> is the driver type of which a minikube can be deployed. For <strong>MacOS</strong>, Docker is recommended. <a href="https://minikube.sigs.k8s.io/docs/drivers/">See the full list of drivers for minikube</a>.</p><p>After successfully starting your minikube, browse your dashboard with:</p><pre>minikube dashboard</pre><p>It will automatically open the dashboard on your default browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0z7HgArJB-k7FSzG" /></figure><p>Now since you have your kubernetes up and running, let’s add your <strong>Selenium Grid</strong> and your <strong>Nodes</strong> to your <strong>Cluster</strong>!</p><h4>Grid And Node Yaml</h4><p>For your Grid and Node configurations, you will use example yaml files for these in <a href="https://github.com/kubernetes">the official Kubernetes GitHub repository</a>. Let’s navigate to <a href="https://github.com/kubernetes/examples/tree/master/staging/selenium">this repository</a>. You need to download these three yaml files:</p><ul><li><strong>selenium-hub-deployment.yaml </strong>=&gt; To deploy selenium hub.</li><li><strong>selenium-hub-svc.yaml</strong> =&gt; A service for nodes to connect to the hub.</li><li><strong>selenium-node-chrome-deployment.yaml</strong> =&gt; To deploy Chrome node.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*faKEh_RkfWR5Y8LF" /></figure><p>In <strong>selenium-node-chrome-deployment.yaml, </strong>let’s<strong> </strong>change replica count to `<strong>1</strong>`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*tpZAieBteQ7NRg_e" /></figure><p><strong>Note</strong>: If you have a computer which has Apple Silicon with Arm64 Architecture, you need to make these small changes in the following files as well:</p><p>In <strong>selenium-hub-deployment.yaml</strong> file, change the container image to `<strong>seleniarm/hub</strong>`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*MAY5i6IEbufmH1KT" /></figure><p>In <strong>selenium-node-chrome-deployment.yaml </strong>file, change the container image to `<strong>seleniarm/node-chromium</strong>`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*o2bR57HKBSvrgpan" /></figure><p>Now let’s connect them to your k8s cluster.</p><ol><li>Hub Deployment:</li></ol><pre>kubectl create -f selenium-hub-deployment.yaml</pre><p>2. Service Deployment:</p><pre>kubectl create -f selenium-hub-svc.yaml</pre><p>3. Node Deployment:</p><pre>kubectl create -f selenium-node-chrome-deployment.yaml</pre><p>Now let’s check if your deployments are successful with the command below.</p><pre>kubectl get deploy</pre><p>If your deployments were successful, you should see something like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*69t1JSq1DPTICifn" /></figure><p>Now let’s check your service with:</p><pre>kubectl get services</pre><p>You can see your service as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cpG49cPW9cW7AAHx" /></figure><p>Now let’s find out the url of your grid with the command below:</p><pre>minikube service selenium-hub - url</pre><p>Your grid is on one of these ports below. Usually the first one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*U34TFh-sDPn4pW0X" /></figure><p>After entering correct port, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xr6emE4iN90RCS-G" /></figure><p>Next, you will configure <strong>KEDA</strong>.</p><h4>KEDA Yaml Configuration</h4><p>From <a href="https://github.com/kedacore/keda/releases">the KEDA releases page</a>, download the latest KEDA version. At the moment of writing this blogpost, the latest version is <strong>2.10.1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/0*9aX5eSyaW4Uw6YtV" /></figure><p>And you need to create a scaled-object for your Chrome node. Let’s create a file named <strong>scaled-object-chrome.yaml </strong>and populate it with the code below:</p><pre>apiVersion: keda.sh/v1alpha1<br>kind: ScaledObject<br>metadata:<br>  name: selenium-chrome-scaledobject<br>  namespace: default<br>  labels:<br>    deploymentName: selenium-node-chrome<br>spec:<br>  minReplicaCount: 0<br>  maxReplicaCount: 4<br>  scaleTargetRef:<br>    name: selenium-node-chrome<br>  pollingInterval: 1  <br>  triggers:<br>    - type: selenium-grid<br>      metadata:<br>        url: &#39;http://selenium-hub.default:4444/graphql&#39;<br>        browserName: &#39;chrome&#39;<br>        activationThreshold: &quot;5&quot;</pre><p>In here:</p><ul><li><strong>minReplicaCount</strong> is the number of replicas when there are not any tests in the queue.</li><li><strong>maxReplicaCount</strong> is the max number of replicas when the activation threshold is reached. In this instance, this means that you won’t have more than <strong>4</strong> Chrome nodes no matter how many tests are in queue.</li><li><strong>activationThreshold</strong> is the threshold to scale up your Chrome node. If the queue reaches 5, it initiates a replication.</li></ul><p>Now let’s integrate them into your Cluster.</p><pre>kubectl apply -f keda-2.10.1.yaml</pre><p>After that, let’s apply your scaled-object. Since your Chrome deployment in the default namespace, you will apply your scaled-object to there too.</p><pre>kubectl apply -f ./scaled-object-chrome.yaml - namespace=default</pre><p>Now give it a few moments and check your Selenium Grid again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DlZ5cv1YzdUgm7SF" /></figure><p>No nodes!? Why? Because you configured your <strong>minReplicaCount </strong>as 0. So when there aren’t any tests in the queue, <strong>KEDA</strong> scales down your nodes to zero. Now I call this resource management!</p><p>Okay, let’s change the <strong>remote_url</strong> variable in the test automation project to our current <strong>Selenium Grid Port</strong>, which is <strong>64824</strong> in this instance, and run 8 tests in parallel with the `<strong>parallel_cucumber -n 8</strong>` command. And let’s see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*hi_UjGUsZh7ubXnN" /></figure><p>Now that’s it! You have a grid that is auto-scaled with the help of Kubernetes and KEDA!</p><p>This is the end of a long journey. Thanks for bearing with me with this eight-chapter-long blogpost series.</p><p>Before closing up, let’s summarise what you have accomplished so far:</p><p>✅You created a test automation project using Ruby — Capybara — Cucumber and Installed all dependencies.</p><p>✅You learned how to write CSS selectors.</p><p>✅You wrote test scenarios to be used on your test automation project.</p><p>✅You recorded failed test scenarios as video files in Ruby.</p><p>✅You used remote connections to run your tests in different machines.</p><p>✅You used Selenium Grid and ran your tests in parallel.</p><p>✅You dockerized your test automation project so that it can be run in any environment.</p><p>✅You recorded failed test runs in a Docker container using Selenium Video image.</p><p>✅You integrated CI/CD pipeline to your project by using Jenkins.</p><p>✅You configured auto-scaling for your project by using KEDA.</p><p>Hope to see you in upcoming sprints!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ce4bfd6f2e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-6-5ce4bfd6f2e0">Creating End-to-End Web Test Automation Project from Scratch — Part 6</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 5]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-5-40023c5feecc?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/40023c5feecc</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[eng]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 10:35:27 GMT</pubDate>
            <atom:updated>2024-07-12T11:43:16.308Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 5</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cGIJi1Sbfs9qIc2PLg1LJg.jpeg" /></figure><p>Welcome to the 5th part of the blog post series called “Creating an End-to-End Web Test Automation Project from Scratch.” So far, we have covered many topics, from the creation of a project to containerizing it with Docker. If you need to review the previous chapters, you can find the articles at the links below.</p><ol><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><a href="https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a"><em>Bonus: Recording Failed Scenario Runs in Ruby</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1"><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f"><em>Let’s Dockerize Our Web Test Automation Project</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-1-f8e02c223603"><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></a></li><li><strong><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></strong></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ol><p>In this chapter, you will integrate CI/CD into your project with Jenkins and execute your test in a Docker container on a scheduled basis. Also, you will create a job that rebuilds and pushes your Docker image to the hub! Let’s start!</p><h3>Jenkins Installation</h3><p>First, install Jenkins via <strong>homebrew</strong>:</p><pre>brew install jenkins-lts</pre><p>After the installation, start Jenkins:</p><pre>brew services start jenkins-lts</pre><p>The default port for Jenkins is <strong>8080</strong>. Go to the Jenkins page at “<strong>http://localhost:8080”</strong></p><p>Jenkins will create a password for you in a file and state its location.</p><ol><li>Go to that location</li><li>Copy the password</li><li>Paste it into the input field on Jenkins page and continue.</li><li>Then create a username/password pair for yourself.</li></ol><p>For the official installation guide, please refer to <a href="https://www.jenkins.io/doc/book/installing/macos/">Jenkins Documentation </a>.</p><h3>Configurations</h3><h4>Environment</h4><p>Before creating jobs for Jenkins, you need to configure it first. Go to <strong>Dashboard</strong> -&gt; <strong>Manage</strong> <strong>Jenkins</strong> -&gt; <strong>Configure System</strong>. Under the <strong>Global properties</strong>, check <strong>Environment variables</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ky6dWT1dgF6s0AZ4MzSBZA.png" /></figure><p>By stating your path here, you enable Jenkins to run Ruby, Docker and other applications on your machine.</p><p>You can get all your path variables via the command below:</p><pre>echo $path</pre><p>Note that you need to replace blanks with colons. For example:</p><p><strong>Your Path:</strong></p><pre>/Users/muhammettopcu/Library/Android/sdk/tools /Users/muhammettopcu/Library/Android/sdk/platform-tools /Users/muhammettopcu/.jbang/bin /opt/homebrew/bin /opt/homebrew/sbi</pre><p><strong>Your Path for Jenkins:</strong></p><pre>/Users/muhammettopcu/Library/Android/sdk/tools:/Users/muhammettopcu/Library/Android/sdk/platform-tools:/Users/muhammettopcu/.jbang/bin:/opt/homebrew/bin</pre><p><strong>Note</strong>: If you are on Windows, concatenate them with <strong>semicolons</strong>.</p><h4>Plug-ins</h4><p>Now go to <strong>Dashboard</strong> -&gt; <strong>Manage</strong> <strong>Jenkins</strong> -&gt; <strong>Manage Plugins.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D04_VOPjirFO_ik9kA-Ljw.png" /></figure><p>In this screen, you will install the plugins that you need:</p><ol><li><a href="https://plugins.jenkins.io/cucumber-reports/"><strong>Cucumber Reports </strong></a>: This enables you to have test reports visually.</li><li><a href="https://plugins.jenkins.io/git-parameter/"><strong>Git Parameter </strong></a>: This lets you pick a branch on your project and run the code inside.</li><li><a href="https://plugins.jenkins.io/github/"><strong>GitHub </strong></a><em>(if not installed already)</em>: This one enables you to integrate with GitHub features such as Webhooks.</li><li><a href="https://plugins.jenkins.io/docker-build-publish/"><strong>CloudBees Docker Build and Publish </strong></a><strong>: </strong>This is to build a Docker image and publish it.</li></ol><h4>Credentials</h4><p>Now you will configure credentials for both <strong>GitHub</strong> and <strong>DockerHub</strong>.</p><p>You need to navigate to <strong>Dashboard</strong> -&gt; <strong>Manage Jenkins</strong> -&gt; <strong>Credentials.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OA8BqtuEqNRB0awOd6uwVQ.png" /></figure><p>Then click <strong>“(global)”</strong> domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*r9GLN5y2eFltpmrT" /></figure><p>Click <strong>+Add Credentials</strong> button to add your credentials.</p><p>For <strong>DockerHub</strong>:</p><ol><li><strong>Kind</strong>: Username with password.</li><li><strong>Username</strong>: Username of your DockerHub account.</li><li><strong>Password</strong>: Access Token generated on DockerHub.</li></ol><ul><li>To create your access token, log in to your <strong>DockerHub</strong> account. Go to <strong>Account Settings</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*8tt7KMb95RRmYmlBaJ9hUA.png" /></figure><ul><li>Then go to the <strong>Security</strong> panel.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*A1UAJjx-oV04ciNPUpTEaQ.png" /></figure><ul><li>Click on the <strong>New Access Token </strong>button. Give your access token a name and <strong>R-W-D </strong>rights. Then click on <strong>Generate</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*S89iSPh-iG3JVHgTriM6zg.png" /></figure><p>4.<strong> ID</strong>: ID to be used in Jenkinsfile or for other configurations: <strong>dockerhub</strong>.</p><p>5.<strong> Description</strong>: Description of the credential. Here, <strong>dockerhub</strong> again.</p><p>For <strong>GitHub</strong>:</p><ol><li><strong>Kind</strong>: Username with password.</li><li><strong>Username</strong>: Username of your GitHub account.</li><li><strong>Password</strong>: Access Token generated on GitHub.</li></ol><ul><li>To create your access token, log in to your <strong>GitHub</strong> account. Go to <strong>Settings</strong> -&gt; <strong>Developer</strong> <strong>settings </strong>-&gt; <strong>Personal Access Tokens </strong>and click the <strong>Generate new token</strong> button. Give a name to your token and generate it.</li></ul><p>4.<strong> ID</strong>: ID to be used in Jenkinsfile or for other configurations: <strong>github</strong>.</p><p>5.<strong> Description</strong>: Description of the credential. Here, <strong>github</strong> again.</p><h4>Ruby Web Project</h4><p>Also, let’s make a small addition to your code to generate Cucumber reports:</p><ol><li>First, create a new folder named “<strong>reports</strong>” under your project directory.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*A3Q1c1vNJbtcBfQx.png" /></figure><p>2. Then in the <strong>cucumber.yml</strong> file <strong>(if you don’t have yet, create one under the project directory)</strong>, add `--<strong>format json --out reports/reports.json</strong>` to your default profile. This will let you create test execution reports under the reports folder in JSON format, named<strong> reports.json</strong>.</p><pre>default: &quot;--format json --out reports/reports.json&quot;</pre><h4>Dockerfile</h4><p>This time, you will not build your Docker image with the files residing in your local. Instead, you will get the files directly from the <strong>GitHub</strong> <strong>repository</strong>. So you need to alter your <strong>dockerfile</strong>!</p><p>The first couple of lines are the same:</p><pre>FROM ruby:3.0<br><br>RUN apt update &amp;&amp; apt install git<br>#RUN apk update &amp;&amp; apk add --no-cache build-base &amp;&amp; apk add git<br>RUN apt-get install -y ffmpeg &amp;&amp; apt-get install bc<br>WORKDIR /usr/src/app</pre><p>You will make changes starting from this line:</p><pre>RUN curl -o /usr/src/app/Gemfile https://raw.githubusercontent.com/kloia/dockerize-ruby-web-project/master/Gemfile</pre><p>With the `<strong>curl</strong>` command, you download your <strong>Gemfile</strong> from your remote directory to the <strong>workdir</strong>. Note that<strong> </strong><a href="https://raw.githubusercontent.com/"><strong>https://raw.githubusercontent.com</strong></a> enables you to download individual files as plain text.</p><pre>RUN gem install bundler &amp;&amp; bundle install</pre><p>First, install your gems.</p><pre>RUN cd /usr/src/app &amp;&amp; git init &amp;&amp; git remote add origin https://github.com/kloia/dockerize-ruby-web-project.git &amp;&amp; git fetch &amp;&amp; git checkout -f origin/master</pre><p>Now let’s look at the above RUN command bit by bit:</p><ul><li><strong>`cd /usr/src/app`</strong> navigates to <strong>workdir</strong>.</li><li><strong>`git init`</strong> initialises git.</li><li><strong>`git remote add origin </strong><a href="https://github.com/kloia/dockerize-ruby-web-project.git%60"><strong>https://github.com/kloia/dockerize-ruby-web-project.git`</strong></a> adds your existing GitHub project as a remote repository to git.</li><li><strong>`git fetch`</strong> fetches everything from the remote repository.</li><li><strong>`git checkout -f origin/master`</strong> Forces checkout to origin/master. “<em>Why force it?” </em>Otherwise, you can’t checkout since the Gemfile you downloaded in the earlier step conflicts with this command.</li></ul><p>The rest of the file is the same.</p><pre>CMD parallel_cucumber -n 2<br>EXPOSE 5000:5000</pre><p>So your final dockerfile looks like this below:</p><pre>FROM ruby:3.0<br>RUN apt update &amp;&amp; apt install git<br>#RUN apk update &amp;&amp; apk add --no-cache build-base &amp;&amp; apk add git<br>RUN apt-get install -y ffmpeg &amp;&amp; apt-get install bc<br>WORKDIR /usr/src/app<br>RUN curl -o /usr/src/app/Gemfile https://raw.githubusercontent.com/kloia/dockerize-ruby-web-project/master/Gemfile<br>RUN gem install bundler &amp;&amp; bundle install<br>RUN cd /usr/src/app &amp;&amp; git init &amp;&amp; git remote add origin https://github.com/kloia/dockerize-ruby-web-project.git &amp;&amp; git fetch &amp;&amp; git checkout -f origin/master<br>CMD parallel_cucumber -n 2<br>EXPOSE 5000:5000</pre><h3>Jenkins Job Creations</h3><h4>Test Run Job with Parameters</h4><p>Let’s create a <strong>jenkinsfile </strong>with your favourite file editor. The first part of your file is:</p><pre>pipeline {<br>    agent any<br>        parameters {      <br>        choice(name: &#39;Headless&#39;, choices: [&#39;true&#39;, &#39;false&#39;], description: &#39;&#39;)<br>        choice(name: &#39;Browser&#39;, choices: [&#39;remote-chrome&#39;, &#39;remote-firefox&#39;], description: &#39;&#39;)<br>        string(name: &#39;ThreadCount&#39;, defaultValue: &#39;1&#39;, description: &#39;&#39;)<br>        string(name: &#39;Retry&#39;, defaultValue: &#39;1&#39;, description: &#39;&#39;)<br>            gitParameter name: &#39;BRANCH_TAG&#39;,<br>                        type: &#39;PT_BRANCH&#39;,<br>                        defaultValue: &#39;master&#39;,<br>                        selectedValue: &#39;DEFAULT&#39;,<br>                        quickFilterEnabled: true,<br>                        sortMode: &#39;DESCENDING_SMART&#39;,<br>                        tagFilter: &#39;*&#39;,<br>                        branchFilter: &#39;origin/(.*)&#39;,<br>                        useRepository: &#39;.*.git&#39;,<br>                        description: &#39;Select your branch&#39;<br>    }</pre><ul><li>In the parameters section, you create your sections for the parameters, which you will use while running <strong>parallel_cucumber </strong>command in the command line.</li><li>The <strong>gitParameter</strong> lets you choose different branches on which you run your code. Note that you also have a <strong>video_recording</strong> branch with the configurations of <a href="https://blog.kloia.com/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><strong>Chapter 2.1 </strong></a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*kyslX9hln_FfbEik_Lyb8w.png" /></figure><p>Now next, you are going to define your stages.</p><pre>stages {<br>        stage(&#39;Checkout &amp; Run Tests&#39;) {<br>            steps {<br>                sh &quot;docker run muhammettopcu/dockerize-ruby-web:latest git checkout ${params.BRANCH_TAG} &amp;&amp; parallel_cucumber -n ${params.ThreadCount.toInteger()} -o &#39;headless=${Headless} browser=${Browser} --retry ${params.Retry.toInteger()}&#39;&quot;<br>            }<br>        }<br>    }<br><br><br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCbHoLYBt3AYrxLJqqsK0A.png" /></figure><p>You use the ` <strong>docker run</strong>` command with two parts:</p><ul><li><strong>`git checkout ${params.BRANCH_TAG}`</strong> checkouts to a specified branch.</li><li><strong>`parallel_cucumber -n ${params.ThreadCount.toInteger()} -o ‘headless=${Headless} browser=${Browser} — retry ${params.Retry.toInteger()}’</strong>` runs cucumber with the specified arguments in Jenkins build.</li></ul><p>And last, let’s define your post actions.</p><pre>post {<br>       always {<br>           cucumber([<br>               buildStatus: &#39;null&#39;,<br>               customCssFiles: &#39;&#39;,<br>               customJsFiles: &#39;&#39;,<br>               failedFeaturesNumber: -1,<br>               failedScenariosNumber: -1,<br>               failedStepsNumber: -1,<br>               fileIncludePattern: &#39;**/*.json&#39;,<br>               jsonReportDirectory: &#39;reports&#39;,<br>               pendingStepsNumber: -1,<br>               reportTitle: &#39;Cucumber Report&#39;,<br>               skippedStepsNumber: -1,<br>               sortingMethod: &#39;ALPHABETICAL&#39;,<br>               undefinedStepsNumber: -1<br>           ])<br>       }<br>       success{<br>           script{<br>               sh &quot;echo successful&quot;<br>          }<br>       }<br>       failure{<br>           script{<br>               sh &quot;echo failed&quot;<br>          }<br>       }<br>       aborted{<br>           script{<br>               sh &quot;echo aborted&quot;<br>           }<br>       }<br>   }<br>}</pre><p>In the <strong>always</strong> action, you define your Cucumber plug-in. Note that `<strong>jsonReportDirectory: ‘reports’`</strong> is the directory that you created for the report files in your project. You might ask <em>“But I am running my tests in a Docker container. The reports would be generated inside the container. How will Jenkins reach these?”</em> A valid point, indeed! It works because Docker Plugin automatically syncs Jenkins’ workspace and the container’s workdir. If it didn’t, you would have needed to do it manually with <strong>volumes</strong> when executing `<strong>docker run</strong>` command.</p><p>For the <strong>success</strong>, <strong>failure</strong> and <strong>aborted</strong> events, there is only a simple <strong>echo</strong> command. You may want to implement a notification script for your favourite messaging applications such as <strong>Discord</strong> or <strong>Slack</strong>. If you are interested in doing this, me and my colleagues have covered this topic in a recent webinar, here is the <a href="https://youtu.be/c1_K2ceChQM?t=11244">link for the recording.</a></p><p>This is it. Let’s save and move it to your project directory. It is named <strong>jenkins_cucumber </strong>without any extensions. Do not forget to push it to your GitHub repository since you’ll make Jenkins pull it from there.</p><p>Now go to Jenkins and create your first job with the jenkinsfile that you created. First, you need to click the <strong>New Item</strong> button on the <strong>Dashboard</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*M4Qm3mc83AsRzkNezbCOWQ.png" /></figure><p>Now write your job name and choose <strong>Pipeline</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KlAc7DSyL1QLALViEd3wFA.png" /></figure><p>Now configure your Job:</p><ul><li>If you want it to run every hour such as 07:00, 08:00, you need to use <br>`<strong>0 * * * *</strong>`</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5ev0P5IPyh8-bblSMo7Cw.png" /></figure><p>This is called “<strong>cron expression</strong>”. You can configure it according to your own needs. For detailed information, please refer to <a href="https://www.jenkins.io/doc/book/pipeline/syntax/#cron-syntax">Jenkins Documentation </a>.</p><p>Now in the Pipeline section, choose <strong>Pipeline script from SCM</strong> and as SCM choose <strong>Git</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJl_mvobp2CSdJp6rt8nyQ.png" /></figure><p>Now state your GitHub repository and credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rRPgfCf5UEaTd4lHuI5pWA.png" /></figure><p>And finally, you need to give the path of your jenkinsfile here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*p8hbv5xd1yZWMcIZ4UQcoQ.png" /></figure><p>Note that this path is of your `<strong>jenkinsfile` </strong>residing in your Github repository. If you did not put it in the root directory, then change the path accordingly.</p><p>Now you can see your job in the Dashboard!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dHZNkMOPBc8hX0zKP1pthg.png" /></figure><p>Let’s spin up your Selenium server with Docker Compose and run your job manually, just for this time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*TopOcXK2Lg4kqxMTcrpw1A.png" /></figure><p>Choose your parameters and click “<strong>Build” </strong>button. The tests are running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FO13tbxQq6l0FzAizyQwdg.png" /></figure><p>Let’s see your results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lyACrROeyo5eBtJI1rTPUA.png" /></figure><p>Some of them failed. Open the build on the left side by clicking on it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*GLtj_HFmF0amnqONqM2g8w.png" /></figure><p>On the opened panel, click <strong>Cucumber Reports</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*PmxoJlvasKwgZDpd.png" /></figure><p>Hey, your test results are visualized!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9NJyiFRC-XeOTiDAquJ3w.png" /></figure><h4>Automated Docker Image Build with GitHub Webhook</h4><p>Now let’s create a Jenkins job that rebuilds your project image and pushes it to <strong>DockerHub </strong>. You will trigger this job with GitHub webhook, <strong>which pings Jenkins only when there is a push action in your repository.</strong></p><pre>pipeline {<br>  agent any<br>  options {<br>    buildDiscarder(logRotator(numToKeepStr: &#39;5&#39;))<br>  }<br>  environment {<br>    DOCKERHUB_CREDENTIALS = credentials(&#39;dockerhub&#39;)<br>  }<br>  stages {<br>    stage(&#39;Build&#39;) {<br>      steps {<br>        sh &quot;docker build -t muhammettopcu/dockerize-ruby-web:latest https://github.com/kloia/dockerize-ruby-web-project.git&quot;<br>      }<br>    }<br>    stage(&#39;Login&#39;) {<br>      steps {<br>        sh &quot;echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin&quot;<br>      }<br>    }<br>    stage(&#39;Push&#39;) {<br>      steps {<br>        sh &quot;docker push muhammettopcu/dockerize-ruby-web:latest&quot;<br>      }<br>    }<br>  }<br>  post {<br>    always {<br>      sh &#39;docker logout&#39;<br>    }<br>  }<br>}</pre><p>1. In the <strong>options</strong> block, you restrict your Job to keep only the latest five builds. The older ones are discarded.</p><p>2. In the environment block, you assign DockerHub credentials to a variable named <strong>DOCKERHUB_CREDENTIALS</strong>.</p><p>3. You have three stages this time:</p><ul><li><strong>Build</strong>: It builds your project with a tag number. ( <em>In this instance, I just wanted to overwrite my builds, so I used `</em><strong><em>latest</em></strong><em>` as a tag number. You may want to implement an algorithm to track your version numbers.</em>)</li><li><strong>Login</strong>: It logins to DockerHub account with the credentials you created in the previous steps.</li><li><strong>Push</strong>: It pushes your newly created image to your DockerHub repository.</li></ul><p>4. And in the always block, you log out from docker.</p><p>Now let’s create your job. You know the drill this time.</p><p>The only thing different from the previous job is the <strong>Build Triggers </strong>section. Choose “<strong>GitHub hook trigger for GITScm polling” </strong>option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QQR--gPEnF3QX01ZenNrvw.png" /></figure><p><strong>Note</strong>: The Jenkins file name for this job should be different from the first one.</p><p>Now go to the directory of your project on GitHub. In there, navigate to <strong>Settings</strong> -&gt; <strong>Webhooks.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ejhcLJWplnV-2yrOna7laQ.png" /></figure><p>On this page, click “<strong>Add webhook”</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*n6dNtYn7diFPRMT1jIamtw.png" /></figure><p>The <strong>Payload URL </strong>should be in this form: <a href="https://your-jenkins-domain/github-webhook/"><strong>https://&lt;your-jenkins-domain&gt;/github-webhook/</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HAfZ3EQsfno3QrPvcl6s-w.png" /></figure><p>Since I am testing Jenkins on my local machine, I need to expose my <strong>8080</strong> port to the internet. Either I use “<strong>port forwarding</strong>” or “<strong>reverse proxy” </strong>for this.</p><p>My internet provider uses <strong>CGNAT</strong>, so the first one is not an option for me. Therefore I chose <a href="https://localhost.run/"><strong>localhost.run</strong></a> service.</p><p>Why did I prefer this service? <strong>Ngrok</strong> is another option but the free version puts an intermediate layer that gives warning to the user who wants to reach the website. It is for phishing protection, but because of this layer Webhook can not reach Jenkins.</p><p>If you already own a premium Ngrok service or if you run your Jenkins in any other public server, you may not need to use this option.</p><p>So, you need to create an SSH key pair for this:</p><ol><li>Type `<strong>ssh-keygen -b 4096 -t rsa</strong>` and press enter.</li><li>A file name prompt will be shown. Simply press enter to use the default value.</li><li>You will enter the passphrase for the SSH key pair in the upcoming step.</li></ol><p>Now expose your port with the command below:</p><pre>ssh -R 80:localhost:8080 nokey@localhost.run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xE2ZaTZ3dWtWqPgkt1Pbzw.png" /></figure><p>Type your passphrase and press enter.</p><p><em>It gave me the “</em><a href="https://a82b03292e9fbd.lhr.life/"><em>https://a82b03292e9fbd.lhr.life</em></a><em>” URL to reach my port.</em> Write your own to WebHook’s Payload section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*6HJXDcwHP5n6hXoot15S2w.png" /></figure><p>Then choose “<strong>Just the push event.” </strong>option and click “<strong>Add webhook” </strong>button. Note that you can specify your webhook’s triggers with the “<strong>Let me select individual events.” </strong>option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*ydxJRp5d6Y6wUeBuryOtpA.png" /></figure><p>Now you have your WebHook ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kr3B_SAou2Rfhiz2zDFKeA.png" /></figure><p>Let’s make a change in your project file and push it to your repository! <em>For demonstration purposes, I changed </em><strong><em>README.md</em></strong><em> file by adding just a whitespace character.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-05VOtypSaJCaBFXLIVZg.png" /></figure><p>And Jenkins Job got triggered automatically!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-tIHlA2PT8dZOeC8z2GUA.png" /></figure><p>Now let’s check the <strong>DockerHub</strong> repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6CMuxDJE3KQ0DdtcwTyJaw.png" /></figure><p>The new build went through as well!</p><p>With this, we concluded CI/CD integration. So far, we covered how to install and configure Jenkins, create Jenkinsfiles, create and configure webhooks, create pipelines, and set up reverse proxying for your port.</p><p>In the next and final part of this blog post series, you will integrate Kubernetes with your project! See you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40023c5feecc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-5-40023c5feecc">Creating End-to-End Web Test Automation Project from Scratch — Part 5</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch-Part 4.1]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-1-f8e02c223603?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8e02c223603</guid>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Thu, 13 Jun 2024 10:58:57 GMT</pubDate>
            <atom:updated>2024-06-14T11:32:13.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmZh9lGsXczqF_khFrAFTQ.png" /></figure><p>In the <a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f">previous blog post</a>, you have dockerized your test automation project and <strong>Selenium Grid</strong>. In this bonus chapter, you are going to record scenario runs on Docker with Selenium Video image!</p><ol><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><a href="https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a"><em>Bonus: Recording Failed Scenario Runs in Ruby</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1"><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f"><em>Let’s Dockerize Our Web Test Automation Project</em></a></li><li><strong><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></strong></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ol><h3>Recording Scenario Runs on Docker with Selenium Video!</h3><p>Selenium provides a Docker image to record test executions on Selenium nodes in Docker. You are going to configure your Docker compose file to utilize this feature. Note that Selenium Video Docker image is pretty new, so there are a few setbacks:</p><ol><li>Selenium Video image supports <strong>amd64</strong> architecture only. So you can not use it on MacBooks with <strong>Apple Silicon</strong> or on <strong>Raspberry Pi,</strong> for example. The experimental <a href="https://github.com/seleniumhq-community/docker-seleniarm"><strong>seleniarm </strong></a>images do not have Selenium Video support currently, unfortunately.</li><li>For each Selenium node, there has to be one and only one video container. So the mapping is <strong>1:1</strong>.</li><li>Every node needs to have only one browser instance, since video image records the desktop. You can not specifically record an application separately.</li><li>The whole test run is recorded <strong>as</strong> <strong>one video</strong>. So you can not have individual videos of each test scenario.</li><li>The recording starts right after the browser node is connected to the grid and it stops when the containers are terminated. It may result in long recordings having mostly empty desktop scenes.</li></ol><p><em>I am going to use my </em><strong><em>Windows</em></strong><em> machine throughout this walkthrough since its CPU supports Selenium Video image.</em></p><p>Since you are going to use official Selenium images, you need to change the following lines in your seleniarm based compose file, which you created in <a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1">part 4</a> :</p><ol><li>Changing selenium-hub image: <strong>seleniarm/hub</strong> =&gt; <strong>selenium/hub</strong></li><li>Changing chrome image: <strong>seleniarm/node-chromium</strong> =&gt; <strong>selenium/node-chrome</strong></li><li>And adding Video image to your file as shown below:</li></ol><pre>chrome_video:<br>   image: selenium/video<br>   volumes:<br>     - ./videos:/videos<br>   depends_on:<br>     - chrome<br>   environment:<br>     - DISPLAY_CONTAINER_NAME=chrome<br>     - FILE_NAME=chrome_video.mp4</pre><p>Here, `<strong>volumes:</strong>` section lets you have a copy of the files created in the docker container in your host machine. The <strong>first directory is the host directory</strong> and <strong>the second one is the container’s directory</strong>. So when the video container is terminated, the video file in the `<strong>/videos`</strong> directory of the container will be copied to your specified directory. In this case, it will create a video folder in the directory of your compose file.</p><p>So your final compose file looks like this:</p><pre>version: &quot;3&quot;<br>services:<br> selenium-hub:<br>     image: selenium/hub<br>     container_name: selenium-hub<br>     ports:<br>       - &quot;4442:4442&quot;<br>       - &quot;4443:4443&quot;<br>       - &quot;4444:4444&quot;<br>     networks:<br>       - dockerize-network<br> chrome:<br>   image: selenium/node-chrome<br>   shm_size: 2gb<br>   depends_on:<br>     - selenium-hub<br>   environment:<br>     - SE_EVENT_BUS_HOST=selenium-hub<br>     - SE_EVENT_BUS_PUBLISH_PORT=4442<br>     - SE_EVENT_BUS_SUBSCRIBE_PORT=4443<br>     - SE_NODE_MAX_INSTANCES=4<br>     - SE_NODE_MAX_SESSIONS=4<br>     - SE_NODE_SESSION_TIMEOUT=180<br>   networks:<br>     - dockerize-network<br> chrome_video:<br>   image: selenium/video<br>   volumes:<br>     - /tmp/videos:/videos<br>   depends_on:<br>     - chrome<br>   environment:<br>     - DISPLAY_CONTAINER_NAME=chrome<br>     - FILE_NAME=chrome_video.mp4<br> dockerize-network:<br>   name: dockerize-network<br>   driver: bridge</pre><p><em>Note that I have removed</em><strong><em> firefox node</em></strong><em> from the compose file since my Windows machine is not powerful enough :D You can leave it as it is if you want.</em></p><p>Now you can start execution!</p><ol><li>Start the grid with `<strong>docker compose -f docker-compose-selenium.yml up</strong>` command.</li><li>Run your web project via `<strong>docker run — network dockerize-network muhammettopcu/dockerize-ruby-web:1.0</strong>`</li><li>After the execution, terminate your grid with the `<strong>docker compose -f docker-compose-selenium.yml down</strong>` command.</li></ol><p>Then you will see that your video is now available in the folder you stated!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*Qdd4BYQS9CXeDn3MhtMRFg.png" /></figure><p>Now the thing is, as the number of scenarios in your project grows, this video will also grow and it would be hard to find individual scenarios. And I have a solution for this. You are going to split this video with <strong>ffmpeg</strong> software!</p><p>First, you are going to create a bash file for this purpose, and then dockerize it!</p><h3>Splitting Video to Individual Parts with ffmpeg</h3><p>First let’s examine your video:</p><ol><li>The video starts with an empty desktop like below:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzd6_j_ITOYJY2QfKcTOFA.png" /></figure><p>2. Then, when a scenario run starts, your browser shows up.</p><p>3. And between the scenario runs, you see this black screen again.</p><p>So here is the algorithm to find the beginning and the ending of all test scenarios:</p><ol><li>Take a screenshot of the first frame of your video, which is basically a screenshot of your container’s desktop.</li><li>Find every frame resembling this frame throughout the video.</li><li>Compare every frame with the next frame. If the time difference between these two frames is bigger than 1 second, then it means the first frame is the beginning of a scenario and the second one is the ending of it.</li><li>Get a list of all beginning and ending frames.</li><li>Split the video according to these timestamps.</li></ol><p>First things first: you are going to use <strong>ffmpeg</strong> to process your video. Install it.</p><pre>brew install ffmpeg</pre><p><em>Brew!? Why brew? Wasn’t I working on a Windows machine? Yes, I am going to run this docker image on my Windows machine but I will develop it on my Mac! That’s the power of Docker!</em></p><p>Now, make sure that your <strong>bash</strong> is updated. For installing the newer bash version, follow <a href="https://itnext.io/upgrading-bash-on-macos-7138bd1066ba"><strong>this article </strong></a>.</p><p>And finally, install <strong>bc </strong>(basic calculator) to make arithmetic operations in bash. You are going to need it.</p><pre>brew install bc</pre><p>Before you start, you might want to grab your favorite beverage. It will be a long walkthrough :)</p><p>Let’s create an empty file with your preferred text editor. You are going to write a shell script!</p><pre>#!/bin/bash<br><br>#Take the screenshot of the first frame of the video<br>ffmpeg -i /Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4 -vframes 1 /Users/muhammettopcu/Desktop/video_edit/screenshot.png</pre><p>The above code lets you take a screenshot of the first frame of your video:</p><ul><li><strong>#!/bin/bash</strong> makes your system regard this file as a shell script.</li><li><strong>/Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4</strong> is the path of your video file.</li><li><strong>/Users/muhammettopcu/Desktop/video_edit/screenshot.png </strong>is the path where the screenshot will be saved.</li></ul><pre>#Get the list of all frames resembling the image with a %85 ratio<br>ffmpeg -i /Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4 -loop 1 -i /Users/muhammettopcu/Desktop/video_edit/screenshot.png -an -filter_complex &quot;blend=difference:shortest=1,blackframe=85:32&quot; -f null - &gt; /Users/muhammettopcu/Desktop/video_edit/output.txt 2&gt;&amp;1</pre><p>This is one of the most critical lines. It gets every frame of your video file and blends it with the screenshot that you have just taken. <strong>When two frames are blended together, if two identical pixels overlap, the result is a black pixel. </strong>There are two variables for this comparison:</p><ul><li><strong>Amount: </strong>The percentage of the pixels that have to be below the threshold; it is 85 for in this instance.</li><li><strong>Threshold: </strong>The threshold below which a pixel value is considered black; it is 32 in this example.</li></ul><p>By changing these values, you can make more precise comparisons.</p><p>After filtering these similar pixels, you save them to file with <strong>/Users/muhammettopcu/Desktop/video_edit/output.txt</strong> path.</p><p>Here is a sample of what output.txt:</p><pre>[Parsed_blackframe_1 @ 0x600000f2c0b0] frame:243 pblack:97 pts:1244160 t:16.200000 type:P last_keyframe:0<br>[Parsed_blackframe_1 @ 0x600000f2c0b0] frame:244 pblack:97 pts:1249280 t:16.266667 type:P last_keyframe:0<br>frame=  291 fps=193 q=-0.0 size=N/A time=00:00:19.33 bitrate=N/A speed=12.8x    <br>frame=  397 fps=197 q=-0.0 size=N/A time=00:00:26.46 bitrate=N/A speed=13.2x    <br>[Parsed_blackframe_1 @ 0x600000f2c0b0] frame:490 pblack:97 pts:2508800 t:32.666667 type:P last_keyframe:250<br>[Parsed_blackframe_1 @ 0x600000f2c0b0] frame:491 pblack:97 pts:2513920 t:32.733333 type:P last_keyframe:250</pre><p>Here the “<strong>t:&lt;SS.MS&gt;</strong>” is the second that a frame is shown. “<strong>frame</strong>” indicates which frame it is.</p><p>So in this example, as you can see, there is not any blackframe between the <strong>244th</strong> and <strong>490th</strong> frames. Which basically means that between them, a scenario is executed!</p><p>So now, you need to process this file and get the timestamp of these blackframe pairs which have more than 1-second time difference between them!</p><pre>file=&#39;/Users/muhammettopcu/Desktop/video_edit/output.txt&#39;<br>regex=&#39;t:([0-9\.]+)&#39;<br>detected=&#39;/Users/muhammettopcu/Desktop/video_edit/detected.txt&#39;<br><br>global_rematch() {<br>   local file=$1 regex=$2<br>   timeStamps=()<br>   while IFS= read -r line; do<br>       [[ $line =~ $regex ]]<br>       if [[ &quot;${BASH_REMATCH[1]}&quot; == &quot;&quot; ]]; then<br>           :<br>       else<br>           timeStamps+=(&quot;${BASH_REMATCH[1]}&quot;)<br>       fi<br>   done &lt; $file<br>}<br><br>global_rematch &quot;$file&quot; &quot;$regex&quot;</pre><p>Let’s examine this code bit together:</p><ul><li><strong>`file</strong>` is the location of your output.txt file.</li><li>`<strong>regex</strong>` is the pattern of your frame time. It will catch every value after `<strong>t:</strong>` value of each frame. Check it <a href="https://regex101.com/r/XdoHPJ/1">here.</a></li><li>`<strong>detected</strong>` is the file in which you will store these blackframe pairs.</li><li>`<strong>global_rematch()</strong>` is a function that you try to match every line in your<strong> output.txt</strong> file with the <strong>regex pattern </strong>you have. If there is a match, you store the value of `<strong>t:</strong>` in an array called <strong>timeStamps.</strong></li></ul><p>So now you have an array filled with timestamps of these blackframes. The values inside <strong>timeStamps</strong> look like this =&gt; (… 16.200000 16.266667 32.666667 32.733333 …)</p><p>Now you need to compare these values and cherry-pick the pairs which have more than 1-second difference!</p><pre># Function to convert seconds to HH:MM:SS format using awk<br>seconds_to_hms() {<br>   local seconds=$1<br><br>   local hours=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int(secs / 3600) }&#39;)<br>   local minutes=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int((secs / 60) % 60) }&#39;)<br>   local seconds=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%06.3f&quot;, secs % 60 }&#39;)<br><br>   echo &quot;$hours:$minutes:$seconds&quot;<br>}</pre><p>Before comparison, you need to convert the seconds to <strong>HH:MM:SS</strong> format. So you are going to use the above function for the elected timestamps to convert them.</p><p>Now let’s compare!</p><pre>newTime=()<br><br>for ((i=1;i&lt;${#timeStamps[@]};i++)); do<br>   if (( $(echo &quot;${timeStamps[$i+1]}-${timeStamps[$i]} &gt; 1&quot; |bc -l) )); then<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i]}&quot;))<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i+1]}&quot;))<br>   fi<br>done</pre><ul><li>Here you have a new array named <strong>newTime.</strong></li><li>You loop through every element (which are timestamps of each blackframe) of timeStamps array and compare them with the next frame’s timestamp by using <strong>bc</strong>. If <strong>the difference between them is more than 1</strong>, then it converts both time stamps into <strong>HH:MM:SS format </strong>by using <strong>seconds_to_hms</strong> function and append them to the <strong>newTime</strong> array!</li></ul><pre># Write array elements to file<br>for element in &quot;${newTime[@]}&quot;; do<br>   echo &quot;$element&quot; &gt;&gt; &quot;$detected&quot;<br>done</pre><p>With the above code, you write each element of <strong>newTime </strong>array into the file named “<strong>detected.txt”. </strong>The file looks like this:</p><pre>00:00:16.267<br>00:00:32.667<br>00:00:33.467<br>00:01:12.000<br>00:01:13.133<br>00:02:00.000<br>00:02:00.733<br>00:02:47.667<br>00:02:48.333<br>00:03:04.200<br>00:03:04.800<br>00:03:19.600<br>00:03:20.267<br>00:03:33.867<br>00:03:34.600<br>00:03:45.667</pre><p>And your bash script so far looks like this:</p><pre>#!/bin/bash<br><br>#Take the screenshot of the first frame of the video<br>ffmpeg -i /Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4 -vframes 1 /Users/muhammettopcu/Desktop/video_edit/screenshot.png<br><br>#Get the list of of all frames resembling to the image with %85 ratio<br>ffmpeg -i /Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4 -loop 1 -i /Users/muhammettopcu/Desktop/video_edit/screenshot.png -an -filter_complex &quot;blend=difference:shortest=1,blackframe=85:32&quot; -f null - &gt; /Users/muhammettopcu/Desktop/video_edit/output.txt 2&gt;&amp;1<br><br>file=&#39;/Users/muhammettopcu/Desktop/video_edit/output.txt&#39;<br>regex=&#39;t:([0-9\.]+)&#39;<br>detected=&#39;/Users/muhammettopcu/Desktop/video_edit/detected.txt&#39;<br><br>global_rematch() {<br>   local file=$1 regex=$2<br>   timeStamps=()<br>   while IFS= read -r line; do<br>       [[ $line =~ $regex ]]<br>       if [[ &quot;${BASH_REMATCH[1]}&quot; == &quot;&quot; ]]; then<br>           :<br>       else<br>           timeStamps+=(&quot;${BASH_REMATCH[1]}&quot;)<br>       fi<br>   done &lt; $file<br>}<br><br><br># Function to convert seconds to HH:MM:SS format using awk<br>seconds_to_hms() {<br>   local seconds=$1<br><br>   local hours=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int(secs / 3600) }&#39;)<br>   local minutes=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int((secs / 60) % 60) }&#39;)<br>   local seconds=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%06.3f&quot;, secs % 60 }&#39;)<br><br>   echo &quot;$hours:$minutes:$seconds&quot;<br>}<br><br>global_rematch &quot;$file&quot; &quot;$regex&quot;<br><br>newTime=()<br><br>for ((i=1;i&lt;${#timeStamps[@]};i++)); do<br>   if (( $(echo &quot;${timeStamps[$i+1]}-${timeStamps[$i]} &gt; 1&quot; |bc -l) )); then<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i]}&quot;))<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i+1]}&quot;))<br>   fi<br>done<br><br># Write array elements to file<br>for element in &quot;${newTime[@]}&quot;; do<br>   echo &quot;$element&quot; &gt;&gt; &quot;$detected&quot;<br>done</pre><p>Now here, you are going to use two scripts created by a github user with a username <a href="https://github.com/NapoleonWils0n/ffmpeg-scripts"><strong>NapoleonWils0n </strong></a>. The scripts you are going to use are:</p><ol><li><a href="https://github.com/NapoleonWils0n/ffmpeg-scripts/blob/master/scene-time"><strong>scene-time </strong></a>: Adds duration to the timestamps and creates a new file with this.</li><li><a href="https://github.com/NapoleonWils0n/ffmpeg-scripts/blob/master/scene-cut"><strong>scene-cut </strong></a><strong>: </strong>Cuts the video according to the above-mentioned file.</li></ol><p>You can download them from his directory.</p><p>So by running scene time, you will convert your time stamps <strong>&lt;scene-start&gt;,&lt;scene-duration&gt; </strong>duos. Run the script with the command below:</p><pre>scene-time -i /Users/muhammettopcu/Desktop/video_edit/detected.txt -o /Users/muhammettopcu/Desktop/video_edit/cutlist.txt</pre><p>In here:</p><ul><li><strong>-i</strong> is input file’s path.</li><li><strong>-o</strong> is output file’s path.</li></ul><p>After the execution, the cutlist file which is created by scene-time looks like below:</p><pre>00:00:16.267,00:00:16.4<br>00:00:32.667,00:00:00.8<br>00:00:33.467,00:00:38.533<br>00:01:12,00:00:01.133<br>00:01:13.133,00:00:46.867<br>00:02:00,00:00:00.733<br>00:02:00.733,00:00:46.934<br>00:02:47.667,00:00:00.666<br>00:02:48.333,00:00:15.867<br>00:03:04.2,00:00:00.6<br>00:03:04.8,00:00:14.8<br>00:03:19.6,00:00:00.667<br>00:03:20.267,00:00:13.6<br>00:03:33.867,00:00:00.733<br>00:03:34.6,00:00:11.067</pre><p>Now let’s run scene-cut script with the cutlist.txt file that you have created:</p><pre>bash /usr/local/bin/scene-cut -i /Users/muhammettopcu/Desktop/video_edit/chrome_video.mp4 -c /Users/muhammettopcu/Desktop/video_edit/cutlist.txt</pre><p>Here:</p><ul><li><strong>-i </strong>is input file’s path which is your video.</li><li><strong>-c</strong> is cutlist file’s path.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVtCKTVCMRW-s6xuKn7olw.png" /></figure><p>Now you can see that main video is split and separate videos are created according to time stamps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjAr02x80FQFDEvlULVsKw.png" /></figure><p>But the thing is, as you can see from thumbnails, while every odd-numbered videos are actual test runs, the even-named ones are short videos containing only the desktop screen. Why is that?</p><p>Because the script named <strong>scene-cut </strong>creates videos for each time stamp, <strong>not for each pair</strong> <strong>of them</strong>.</p><p>Then you need to tweak the scene-cut script a little bit. Let’s open the script with a text editor. Below is the code creating videos.</p><pre>#===============================================================================<br># read file and set IFS=, read = input before , duration = input after ,<br>#===============================================================================<br><br>count=1<br>while IFS=, read -r start duration; do<br> trim_video<br> count=&quot;$((count+1))&quot;<br>done &lt; &quot;${cutfile}&quot;</pre><p>Let’s modify it like below:</p><pre>count=1<br>name=1<br>while IFS=, read -r start duration; do<br> if [ $((count%2)) -eq 1 ];then<br>   trim_video<br>   name=&quot;$((name+1))&quot;<br> fi<br> count=&quot;$((count+1))&quot;<br>done &lt; &quot;${cutfile}&quot;</pre><p>With this modification, you skip all the lines that are multiples of two.</p><p>And replace the `<strong>count</strong>` below with `<strong>name</strong>`, so even though you skip some of them, the videos are named correctly.</p><p><strong>Before:</strong></p><pre>output=&quot;${input_name}-${count}.mp4&quot; </pre><p>After:</p><pre>output=&quot;${input_name}-${name}.mp4&quot; </pre><p>Done. Let’s run again!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_erEDfSMYwhowHaWB2B9zA.png" /></figure><p>Now you can see that only 8 videos are created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0stG8jLIXIRFF0Ylh3fjDg.png" /></figure><p>Everything works as intended!</p><p><em>You might have realised up to this point that I installed and configured everything on MacOS. And the video that I created via Selenium Video was on my host machine.</em></p><p><em>Do I need to repeat everything on every device to accomplish this? Not necessarily. All we need to do is dockerize this script. Then I can run it on my Windows machine without all this hassle!</em></p><h3>Dockerizing Video Split Script</h3><p>Let’s create a dockerfile.</p><pre>FROM ubuntu:latest<br><br>RUN apt update &amp;&amp; apt-get install -y ffmpeg &amp;&amp; apt-get install -y bc<br><br>WORKDIR /usr/src/app<br><br>COPY . /usr/src/app<br><br>ENV PATH &quot;$PATH:/usr/src/app&quot;<br><br>CMD /usr/src/app/split-video-docker<br><br>EXPOSE 5000:5000</pre><ul><li>Using <strong>ubuntu:latest</strong> base image for your script. You can use lightweight one if you want.</li><li>Updating <strong>apt</strong>, install<strong> ffmpeg </strong>and <strong>bc </strong>with <strong>-y</strong> flags so that any prompt are answered as “<strong>yes”</strong>.</li><li>Adding <strong>“/usr/src/app”</strong> to your path environment, so that you can run your scripts there.</li><li>The first thing that will run when your container spins up is the “<strong>split-video-docker” </strong>script, which is your bash script.</li></ul><p>But before building your image, you need to configure your “<strong>split-video-docker” </strong>according to container’s structure:</p><pre>#!/bin/bash<br><br>#Find the video file<br>video_path=$(find /usr/src/app/video -type f -name &quot;*.mp4&quot;)<br><br>#Take the screenshot of the first frame of the video<br>ffmpeg -i $video_path -vframes 1 /usr/src/app/video/screenshot.png<br><br>#Get the list of of all frames resembling to the image with %85 ratio<br>ffmpeg -i $video_path -loop 1 -i /usr/src/app/video/screenshot.png -an -filter_complex &quot;blend=difference:shortest=1,blackframe=85:32&quot; -f null - &gt; /usr/src/app/video/output.txt 2&gt;&amp;1<br><br>file=&#39;/usr/src/app/video/output.txt&#39;<br>regex=&#39;t:([0-9\.]+)&#39;<br>detected=&#39;/usr/src/app/video/detected.txt&#39;</pre><p>Here you added `<strong>video_path=$(find /usr/src/app/video — type f -name “*.mp4” )`</strong> line to find your video file in the on `<strong>/usr/src/app/video` </strong>directory of the container. I almost hear you saying <em>“But the video file won’t be in the container but in your host machine!”</em>. Indeed, that’s why you are going to mount a <strong>volume</strong> on it! But for now, bear with me 🙂</p><p>As you can see, the paths of each file are changed accordingly as well.</p><p>Note that all scripts will be located in the <strong>/usr/src/app </strong>directory and every file to be used with scripts or created via scripts will be in the <strong>/usr/src/app/video </strong>directory. Below you can find your image’s structure:</p><pre>root@236a6678c313:/usr/src/app# where your script files are located<br>.<br>|-- dockerfile<br>|-- scene-cut <br>|-- scene-time<br>|-- split-video-docker<br>`-- video<br>    `-- chrome_video.mp4 #video file mounted with volume</pre><p>Let’s continue:</p><pre>scene-time -i /usr/src/app/video/detected.txt -o /usr/src/app/video/cutlist.txt<br><br>scene-cut -i $video_path -c /usr/src/app/video/cutlist.txt<br><br>rm /usr/src/app/video/cutlist.txt /usr/src/app/video/detected.txt /usr/src/app/video/output.txt /usr/src/app/video/screenshot.png</pre><p>Here, the destinations are changed as well and the files other than the videos that get removed at the end of the script.</p><p>Next, in <strong>scene-cut </strong>script, let’s change the output path like this:</p><pre>trim_video () {<br>   output=&quot;/usr/src/app/video/${input_name}-${name}.mp4&quot;<br>   ffmpeg \<br>   -nostdin \</pre><p>With this, you ensure that the split video files will be saved in the <strong>/usr/src/app/video/</strong> directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*VsrLVjBhRjls5JN44QMCpA.png" /></figure><p>The final bash script should look like this:</p><pre>#!/bin/bash<br><br>#Find the video file<br>video_path=$(find /usr/src/app/video -type f -name &quot;*.mp4&quot;)<br><br>#Take the screenshot of the first frame of the video<br>ffmpeg -i $video_path -vframes 1 /usr/src/app/video/screenshot.png<br><br>#Get the list of of all frames resembling to the image with %85 ratio<br>ffmpeg -i $video_path -loop 1 -i /usr/src/app/video/screenshot.png -an -filter_complex &quot;blend=difference:shortest=1,blackframe=85:32&quot; -f null - &gt; /usr/src/app/video/output.txt 2&gt;&amp;1<br><br>file=&#39;/usr/src/app/video/output.txt&#39;<br>regex=&#39;t:([0-9\.]+)&#39;<br>detected=&#39;/usr/src/app/video/detected.txt&#39;<br><br>global_rematch() {<br>   local file=$1 regex=$2<br>   timeStamps=()<br>   while IFS= read -r line; do<br>       [[ $line =~ $regex ]]<br>       if [[ &quot;${BASH_REMATCH[1]}&quot; == &quot;&quot; ]]; then<br>           :<br>       else<br>           timeStamps+=(&quot;${BASH_REMATCH[1]}&quot;)<br>       fi<br>   done &lt; $file<br>}<br><br><br># Function to convert seconds to HH:MM:SS format using awk<br>seconds_to_hms() {<br>   local seconds=$1<br><br>   local hours=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int(secs / 3600) }&#39;)<br>   local minutes=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%02d&quot;, int((secs / 60) % 60) }&#39;)<br>   local seconds=$(awk -v secs=&quot;$seconds&quot; &#39;BEGIN { printf &quot;%06.3f&quot;, secs % 60 }&#39;)<br><br>   echo &quot;$hours:$minutes:$seconds&quot;<br>}<br><br>global_rematch &quot;$file&quot; &quot;$regex&quot;<br><br>newTime=()<br><br><br>: &lt;&lt;&#39;END_COMMENT&#39;<br>for ((i=1;i&lt;${#timeStamps[@]};i++)); do<br>   if (( $(echo &quot;${timeStamps[$i+1]}-${timeStamps[$i]} &gt; 1&quot; |bc -l) )); then<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i]}&quot;))<br>       newTime+=($(seconds_to_hms &quot;${timeStamps[$i+1]}&quot;))<br>   fi<br>Done<br>END_COMMENT<br><br># Write array elements to file<br>for element in &quot;${newTime[@]}&quot;; do<br>   echo &quot;$element&quot; &gt;&gt; &quot;$detected&quot;<br>done<br><br>scene-time -i /usr/src/app/video/detected.txt -o /usr/src/app/video/cutlist.txt<br><br>scene-cut -i $video_path -c /usr/src/app/video/cutlist.txt<br><br>rm /usr/src/app/video/cutlist.txt /usr/src/app/video/detected.txt /usr/src/app/video/output.txt /usr/src/app/video/screenshot.png </pre><p>If everything is correct, let’s build your image. I am going to use <strong>buildx </strong>since I want this image to be compatible with both my MacOS M1 machine and Windows amd64 machine. You can change the platform according to your needs.</p><pre>docker buildx build -t muhammettopcu/video-splitter:1.0 --push --platform linux/amd64,linux/arm64 .</pre><p><em>With this, I build my images and push them to my repository on </em><strong><em>dockerhub</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*iHwnyHzhxBWWoXLw-1Smkg.png" /></figure><p>Good, both of them pushed successfully. Now let’s try it on Windows!</p><p><em>The video file that I obtained by Selenium Video is in this location: </em><strong><em>C:\Users\muhammettopcy\Desktop\docker\videos</em></strong></p><p><em>Now I am going to use -v command when I run my image since I want to bind this location with Docker container’s video location:</em></p><pre>docker run -v C:\Users\muhammettopcy\Desktop\docker\videos:/usr/src/app/video muhammettopcu/video-splitter:1.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*ZOx2ys1wJjAF6xyN.gif" /></figure><p>It works! Now you can use your dockerized web project and this Docker image to get individual test run videos!</p><p>With this, this blog post is concluded! I hope you get a basic knowledge about manipulating video files according to your needs. Next, we are going to integrate a CI/CD pipeline to your Ruby Web Test Automation Project with Jenkins! See you soon! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8e02c223603" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-1-f8e02c223603">Creating End-to-End Web Test Automation Project from Scratch-Part 4.1</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 4]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e5f14ec169f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 10:33:43 GMT</pubDate>
            <atom:updated>2024-05-22T14:05:07.912Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGSSOrzWu6zM2aqaWrH8rA.jpeg" /></figure><p>In the <a href="https://www.kloia.com/blog/creating-end-to-end-web-test-automation-project-from-scratch-part-3">previous blog post </a>, you have configured and executed your tests in parallel with Selenium Grid. Now it is time to dockerize your web project! Let’s start with installing docker on your machine.</p><ol><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><a href="https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a"><em>Bonus: Recording Failed Scenario Runs in Ruby</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1"><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></a></li><li><strong><em>Let’s Dockerize Our Web Test Automation Project</em></strong></li><li><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ol><h3>Installing Docker</h3><p>Docker’s official page gives elaborate instructions about installing Docker on various machine types, so I won’t get into details. You can download and install the corresponding Docker package to your device:</p><ul><li><a href="https://docs.docker.com/desktop/install/mac-install/">Docker for MacOS</a></li><li><a href="https://docs.docker.com/desktop/install/windows-install/">Docker for Windows</a></li><li><a href="https://docs.docker.com/desktop/install/linux-install/">Docker for Linux</a></li></ul><p>Let’s start Docker Desktop and open the terminal. If everything is installed successfully, you should see a similar response when you write `docker` in the terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PWJfuEnnzoqezwxXFY5zA.png" /></figure><p>Then let’s create your project image!</p><h3>Create an Image of Your Project</h3><p>Docker images are configured and created via a `<strong>dockerfile</strong>`. This is the blueprint of your image.</p><p>Let’s create a file named `<strong>dockerfile</strong>` without a file extension in your project folder and start populating the file with your configurations:</p><p><strong>Base Image: </strong>Base images are self-explanatory. They form the basis of your image. The base image comes with OS distribution, some programs, and dependencies. You can search and find images in the <a href="https://hub.docker.com/"><strong>dockerhub</strong></a>.</p><pre>FROM ruby:3.0</pre><p>Using the <strong>FROM </strong>keyword, you chose your <strong>ruby:3.0</strong> as your base image with all the dependencies you need to execute your web project. So all the things you install and configure will be upon this base image. I decided on this ruby image since it has all you need (and probably more) to run your project. But if you want to create more lightweight images, you may want to use ruby-slim or alpine images as your base image. But beware that you need to install more packages manually.</p><pre>RUN apt update &amp;&amp; apt install git<br>#RUN apk update &amp;&amp; apk add git</pre><p>With <strong>RUN</strong> keyword, you can execute commands. With `<strong>apt update &amp;&amp; apt install git</strong>`, you install git to your image. Since the <strong>ruby:3.0</strong> is a <strong>debian</strong> distribution, you use <strong>apt </strong>command. If you use an <strong>alpine</strong> based distro, you will need <strong>apk</strong> command.</p><p>Now let’s specify your working directory.</p><pre>WORKDIR /usr/src/app</pre><p>The <strong>WORKDIR</strong> instruction sets the working directory for any <strong>RUN</strong>, <strong>CMD</strong>, <strong>ENTRYPOINT</strong>, <strong>COPY</strong> and <strong>ADD</strong> instructions that follow it in the Dockerfile.</p><pre>COPY Gemfile /usr/src/app</pre><p>Then let’s copy your <strong>Gemfile</strong> to your working directory.</p><pre>RUN gem install bundler &amp;&amp; bundle install --jobs=3 --retry=3</pre><p>And then install the gems that your projects require.</p><pre>COPY . /usr/src/app</pre><p>Now let’s copy the rest of the files of your project.</p><p><strong>Note: </strong>You might ask why you separately added your gemfile to the directory, instead of copying all of your project files first and then installing gemfile contents. I will touch on this subject in the next section. Now you state with which command your image will be started:</p><pre>CMD parallel_cucumber -n 2</pre><p>And finally, you state which ports you will expose:</p><pre>EXPOSE 5000:5000</pre><p>Then putting everything together:</p><pre>FROM ruby:3.0<br><br>RUN apt update &amp;&amp; apt install git<br>#RUN apk update &amp;&amp; apk add git<br><br>WORKDIR /usr/src/app<br><br>COPY Gemfile /usr/src/app<br>RUN gem install bundler &amp;&amp; bundle install --jobs=3 --retry=3<br><br>COPY . /usr/src/app<br><br>CMD parallel_cucumber -n 2 -o &#39;-p parallel&#39;<br><br>EXPOSE 5000:5000</pre><h3>Building Docker Image</h3><p>Now you have your dockerfile ready, let’s build your image!</p><p>First, navigate to your project directory in the terminal.</p><pre>docker build -t muhammettopcu/dockerize-ruby-web:1.0 .</pre><p>Let’s look at the above code where:</p><ul><li>`<strong>docker build</strong>` is your main command</li><li>`<strong>-t</strong>` is an option flag that enables you to tag your image</li><li>`<strong>muhammettopcu`</strong> is my user name in dockerhub. You change it with yours.</li><li>`<strong>dockerize-ruby-web</strong>` is your image’s name</li><li>`<strong>1.0</strong>` is the version of your image</li><li>`<strong>.</strong>` refers to the current directory, in which your dockerfile resides.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9j4PPuj7PZEdYNqSWYDfA.png" /></figure><p>And your docker image is successfully created! Let’s check it with the following command:</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GVruKaPL8jWXJvD_pYTOw.png" /></figure><h3>Building Multi-Arch Images</h3><p>If you want your image to work on host machines with different CPU architectures, you need to build images compatible with different architectures.</p><pre>docker buildx build -t muhammettopcu/dockerize-ruby-web:1.0 --push --platform linux/amd64,linux/arm64 .</pre><p>As you can see, you added `<strong>buildx</strong>` command and your platform types with the `<strong>--platform</strong>` option. `<strong>--push</strong>` lets you push your images to dockerhub. Now you can see your image has different arch types!</p><p>Note that you can use different processor types as well, such as<strong> linux/arm64/v8</strong> and <strong>linux/arm/v7</strong>.</p><p>Now let’s talk about why the order of the command is important in a dockerfile and how you benefit from them.</p><h3>Docker Layers</h3><p>Docker builds the images layers upon layers. Every layer has a unique hash ID. This layered structure makes it possible to re-build, download or upload images faster by only writing the changed layers and getting the other layers from the cache.</p><p>To make it more clear, let me write it in a list:</p><ol><li>Docker uses cached files.</li><li>In a docker file, every line creates a layer.</li><li>When re-building, it uses cached files from top to bottom until it finds a changed layer.</li><li>Then docker builds the rest of the layers from scratch.</li></ol><p>When creating the dockerfile, <strong>you should write the lines from the least likely to change to the most likely to change.</strong> Let’s demonstrate this to make it more clear.</p><p>First, I am going to make a small change to your project file and rebuild your image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lO52MV5-z-ARLN6d8BPqzQ.png" /></figure><p>As you can see, I fully utilized my cache and didn’t need to download or install anything else other than updating your source code.</p><p>Now I am going to change the order of your dockerfile like below. Note that with this configuration, first, I copy all your project files to your image and then install the gems.</p><pre>FROM ruby:3.0<br><br>RUN apt update &amp;&amp; apt install git<br><br>WORKDIR /usr/src/app<br><br>COPY . /usr/src/app<br>RUN gem install bundler &amp;&amp; bundle install<br><br>#RUN apk update &amp;&amp; apk add --no-cache build-base &amp;&amp; apk add git<br><br>CMD parallel_cucumber -n 2 -o &#39;-p parallel&#39;<br><br>EXPOSE 5000:5000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgY2eTO275JwlykOtezydw.png" /></figure><p>Now let’s say I made a change in your code and want to rebuild your image. (I added a space to one of your files for this purpose.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAcu0g7n6K0zosSeIRgh0Q.png" /></figure><p>As you can see, even though I only changed the source code, I needed to re-download and install the gem dependencies. That is because when building an image, docker cancels cache usage completely after the first changed layer.</p><p>So it is best to locate your code source near the end of the file since it is the most likely to change.</p><p>Now let’s run your project and see if your code is executed or not:</p><p>First, with the `<strong>docker images</strong>` command, list the images:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BGS5vxbh_r5mdT4abRCMA.png" /></figure><p>And copy the <strong>id </strong>of the latest version of your image from here, which is “<strong>25f5ff8c731a” </strong>in my case. Then type `<strong>docker run 25f5ff8c731a </strong>`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChgoyV8_j8sVVL38d78mlA.png" /></figure><p>You see that your scenarios do not run since it can not find drivers, but do not worry. You will Dockerize <strong>Selenium Grid </strong>as well! :)</p><h3>Dockerize Selenium Grid</h3><p>Let’s download Selenium Grid images to your machine.</p><p>If you use a Macbook with <strong>Apple Silicon (M1/M2) </strong>download the below images:</p><ol><li><a href="https://hub.docker.com/r/seleniarm/hub"><strong>seleniarm/hub</strong></a></li><li><a href="https://hub.docker.com/r/seleniarm/node-chromium"><strong>seleniarm/node-chromium</strong></a></li><li><a href="https://hub.docker.com/r/seleniarm/node-firefox"><strong>seleniarm/node-firefox</strong></a></li></ol><p>Otherwise, download these:</p><ol><li><a href="https://hub.docker.com/r/selenium/hub"><strong>selenium/hub</strong></a></li><li><a href="https://hub.docker.com/r/selenium/node-chrome"><strong>selenium/node-chrome</strong></a></li><li><a href="https://hub.docker.com/r/selenium/node-firefox"><strong>selenium/node-firefox</strong></a></li></ol><p>To download these images, you need to use `<strong>docker image pull &lt;image_name&gt;</strong>` command. So since I use MacBook with M1 chip, I will use: `<strong>docker image pull seleniarm/hub</strong>`</p><p>Now if you downloaded three of them, let’s configure them with <strong>Docker Compose</strong>.</p><h3>Docker Compose Configuration</h3><p>Docker Compose is a <strong>yml</strong> file to configure more than one image for them to be run in coordination. It allows you to write simple command lines without specifying everything with long strings. Let’s create your file bit by bit.</p><pre>version: &quot;3&quot;<br>services:<br> selenium-hub:<br>     image: seleniarm/hub<br>     container_name: selenium-hub<br>     ports:<br>       - &quot;4442:4442&quot;<br>       - &quot;4443:4443&quot;<br>       - &quot;4444:4444&quot;<br>     networks:<br>       - dockerize-network</pre><ul><li>`<strong>version</strong>` is the version of your docker compose</li><li>`<strong>services</strong>` where you list your service name and the image it will use.</li><li>`<strong>selenium-hub</strong>` is the service name</li><li>`<strong>image</strong>` is your image</li><li>`<strong>container_name</strong>` is optional. If you do not state, docker would generate randomly.</li><li>`<strong>ports</strong>` is to map your host’s ports with the container’s. It is in the HOST:CONTAINER format.</li></ul><p><strong>Note: </strong>When mapping ports in the HOST:CONTAINER format, you may experience erroneous results when using a container port lower than 60, because YAML parses numbers in the format xx:yy as a base-60 value. So it is better to map them as strings.</p><ul><li>`<strong>networks</strong>` defines the network this container will be connected to.</li></ul><p>Now your nodes:</p><pre>chrome:<br>    image: seleniarm/node-chromium<br>    container_name: selenium-chrome<br>    shm_size: 2gb<br>    depends_on:<br>      - selenium-hub<br>    environment:<br>      - SE_EVENT_BUS_HOST=selenium-hub<br>      - SE_EVENT_BUS_PUBLISH_PORT=4442<br>      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443<br>      - SE_NODE_MAX_INSTANCES=4<br>      - SE_NODE_MAX_SESSIONS=4<br>      - SE_NODE_SESSION_TIMEOUT=180<br>    networks:<br>      - dockerize-network</pre><ul><li>`<strong>shm_size</strong>` is the shared memory size. You need a larger one since you run multiple browser instances on these nodes.</li><li>`<strong>depends_on</strong>` allows you to prioritize the execution of services. If a service depends on another service, it will not start until the service it depends on has started.</li><li>`<strong>environment</strong>` lets you define environment variables. Most of the variables are self-explanatory:</li><li>`<strong>SE_NODE_MAX_INSTANCES</strong>` defines how many instances of the same version of the browser can run.</li><li>`<strong>SE_NODE_MAX_SESSIONS</strong>` defines the maximum number of concurrent sessions that will be allowed.</li></ul><p>The firefox node:</p><pre>firefox:<br>   image: seleniarm/node-firefox<br>   container_name: selenium-firefox<br>   shm_size: 2gb<br>   depends_on:<br>     - selenium-hub<br>   environment:<br>     - SE_EVENT_BUS_HOST=selenium-hub<br>     - SE_EVENT_BUS_PUBLISH_PORT=4442<br>     - SE_EVENT_BUS_SUBSCRIBE_PORT=4443<br>     - SE_NODE_MAX_INSTANCES=4<br>     - SE_NODE_MAX_SESSIONS=4<br>     - SE_NODE_SESSION_TIMEOUT=180<br>   networks:<br>     - dockerize-network</pre><p>And the network configuration:</p><pre>networks:<br>   dockerize-network:<br>   name: dockerize-network<br>   driver: bridge</pre><ul><li>`<strong>network</strong>` is for the network configuration.</li><li>`<strong>dockerize-network</strong>` is the network declaration.</li><li>`<strong>name</strong>` is the name of your network.</li><li>`<strong>driver</strong>` is the type of your network.</li></ul><p>So your final yml file looks like this:</p><pre># To execute this docker-compose yml file use `docker compose -f docker-compose-seleniarm.yml up`<br># Add the `-d` flag at the end for detached execution<br># To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-seleniarm.yml down`<br>version: &quot;3&quot;<br>services:<br>  selenium-hub:<br>    image: seleniarm/hub<br>    container_name: selenium-hub<br>    ports:<br>      - &quot;4442:4442&quot;<br>      - &quot;4443:4443&quot;<br>      - &quot;4444:4444&quot;<br>    networks:<br>      - dockerize-network<br>  chrome:<br>    image: seleniarm/node-chromium<br>    shm_size: 2gb<br>    depends_on:<br>      - selenium-hub<br>    environment:<br>      - SE_EVENT_BUS_HOST=selenium-hub<br>      - SE_EVENT_BUS_PUBLISH_PORT=4442<br>      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443<br>      - SE_NODE_MAX_INSTANCES=4<br>      - SE_NODE_MAX_SESSIONS=4<br>      - SE_NODE_SESSION_TIMEOUT=180<br>    networks:<br>      - dockerize-network<br>  firefox:<br>    image: seleniarm/node-firefox<br>    shm_size: 2gb<br>    depends_on:<br>      - selenium-hub<br>    environment:<br>      - SE_EVENT_BUS_HOST=selenium-hub<br>      - SE_EVENT_BUS_PUBLISH_PORT=4442<br>      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443<br>      - SE_NODE_MAX_INSTANCES=4<br>      - SE_NODE_MAX_SESSIONS=4<br>      - SE_NODE_SESSION_TIMEOUT=180<br>    networks:<br>      - dockerize-network<br>networks:<br>  dockerize-network:<br>    name: dockerize-network<br>    driver: bridge</pre><p>Now let’s save your file and spin up your grid with the command below:</p><pre>docker compose -f docker-compose-seleniarm.yml up</pre><p>Note that here <strong>-f</strong> option means file and <strong>docker-compose-seleniarm.ym</strong>l is the name of your compose file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZvliDGehkF4E5e_mOcHkA.png" /></figure><p>Now your grid is up and running. You can check it with <a href="http://localhost:4444/">http://localhost:4444/ </a>.</p><p>Let’s see which networks you have with `<strong>docker network ls` </strong>command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*rVpoIUBrmXHzDiieXtu5iw.png" /></figure><p>Your network is here. Let’s inspect it with <strong>docker network inspect &lt;network-id&gt; </strong>to see which containers are connected to it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGu7Jj0Wch4IA5sjlddoqg.png" /></figure><p>Okay, then let’s run your project image using this network!</p><pre>docker run --network dockerize-network muhammettopcu/dockerize-ruby-web:1.0</pre><p>It looks like <strong>2</strong> of <strong>8 </strong>scenarios failed. Since these node images include debugging packages, you can watch the browsers in your container!</p><p>First, click on the Sessions Tab, then the camera icon beside the session you want to see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnvN6aooV2odrRFeuGsy5A.png" /></figure><p>The password for the VNC is “<strong>secret” </strong>by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*_2SErc2RLini1z2Kng3bNw.png" /></figure><p>Now you can see what is going on in your container!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJZQWu02hhsjo615pjn6Dw.png" /></figure><p>As a final note, you can scale the node number of your browsers by using <strong>`--scale`</strong> option.</p><p>For example, let’s say that you want to spin up the grid with 4 Firefox nodes and 2 Chrome nodes. Then you can use:</p><pre>docker compose -f docker-compose-seleniarm.yml up --scale chrome=2 --scale firefox=4</pre><p>With this, we completed Dockerizing Selenium Grid and our project. In the next chapter, we will look at how to integrate a CI/CD pipeline into our project with Jenkins. But before that, we will have a bonus chapter as well! Stay tuned :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e5f14ec169f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-4-3e5f14ec169f">Creating End-to-End Web Test Automation Project from Scratch — Part 4</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 3]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/043efed41cd1</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[parallel-execution]]></category>
            <category><![CDATA[qa]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 11:47:55 GMT</pubDate>
            <atom:updated>2024-02-12T12:18:11.845Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_aF7M_LXutlh0XMLoet_g.png" /></figure><p>In the previous parts of this blog post series, we created our project and wrote a scenario together. I hope you were able to write 4 scenarios. Because you are going to run them in parallel and remotely!</p><ol><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><a href="https://medium.com/@muhammettopcu/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a"><em>Bonus: Recording Failed Scenario Runs in Ruby</em></a></li><li><strong><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></strong></li><li><em>Let’s Dockerize Our Web Test Automation Project</em></li><li><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ol><h3>Remote Driver Configuration</h3><p>In <a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71">Part 1</a>, you configured your drivers to run your tests on your local machine. Now you need to configure remote drivers.</p><p>First, you need a remote URL variable. As you did with all general configurations, you are going to state this inside your <strong>base_config.rb</strong> file.</p><pre>@remote_url = ENV[&#39;remote_url&#39;] || &#39;http://localhost:4444&#39;<br>  def self.remote_url<br>    @remote_url<br>  end</pre><p>With this code, you create a variable named <strong>remote_url</strong>. It means that if there is an environment variable called <strong>remote_url</strong>, your code uses the value of that variable. If not, then it uses “<a href="http://localhost:4444/"><strong>http://localhost:4444</strong></a><strong>”</strong>. Why did we choose it as your default remote_url? You will see it in the following section.</p><p><strong>Note:</strong> You can pass these environment variables with your custom values when executing this test script on the command line. You will see an example of this shortly.</p><p>Now go to the file where your driver configurations are.</p><p>In your <strong>driver.rb </strong>file, add your remote driver configurations under your <strong>case block.</strong></p><pre>when &#39;remote-chrome&#39;<br> Capybara.register_driver :selenium do |app|<br>   options = Selenium::WebDriver::Chrome::Options.new<br>   options.add_argument(&#39;--window-size=1280,720&#39;)<br>   add_default_values(options)<br>   Capybara::Selenium::Driver.new(<br>     app,<br>     browser: :remote,<br>     url: BaseConfig.remote_url,<br>     :options =&gt; options<br><br>   )<br> end<br>when &#39;remote-firefox&#39;<br> Capybara.register_driver :selenium do |app|<br>   options = Selenium::WebDriver::Firefox::Options.new<br>   options.add_argument(&#39;--window-size=1280,720&#39;)<br>   add_default_values(options)<br>   Capybara::Selenium::Driver.new(<br>     app,<br>     browser: :remote,<br>     url: BaseConfig.remote_url,<br>     :options =&gt; options<br><br>   )<br> end<br>end</pre><p>As you can see, the only thing that differs from normal drivers is that when you are creating a new driver instance, you state your browser as “<strong>remote</strong>” and give a <strong>URL</strong> that your script is to be run through. Note that this URL is the one that you configured in your <strong>base_config.rb</strong> file a second ago.</p><h3>Selenium Grid Configuration</h3><p>Now is the time to configure Selenium Grid!</p><p>Selenium Grid is what enables us to run your tests in parallel across multiple devices</p><ol><li>With Grid, you can easily run tests in parallel on multiple machines</li><li>It is possible to run your tests on different browser versions</li><li>It enables cross-platform testing (E.g.: Windows, macOS)</li></ol><p>If you are ready, let’s get down to it!</p><p>First things first, go and download <strong>Selenium Server (Grid)</strong> from <a href="https://www.selenium.dev/downloads/">its official website </a>.</p><p>Selenium Server is a <strong>.jar</strong> file, so you need <strong>Java</strong> installed on your machine to use it. You can download Java from <a href="https://www.java.com/en/download/">its official website </a>.</p><p>At the time I wrote this blog post, Selenium 4 hadn’t been released yet. You do not need to download webdrivers any more, but if you need to use earlier versions of Selenium for a reason, you can find them below:</p><p><em>You need to download the web drivers that you are going to use in your tests. These web drivers can be in the same directory as your selenium-server.jar file, or you can state their directory in the path. For this, please download the suitable version for your browser below. Note that the version of the driver should be the same as your browser’s.</em></p><p><strong><em>Chromedriver:</em></strong><em> </em><a href="http://chromedriver.chromium.org/"><em>http://chromedriver.chromium.org/</em></a></p><p><strong><em>Geckodriver (Mozilla): </em></strong><a href="https://github.com/mozilla/geckodriver/releases"><em>https://github.com/mozilla/geckodriver/releases</em></a></p><p><em>For MacOS, follow these steps:</em></p><ol><li><em>Move the </em><strong><em>chromedriver </em></strong><em>file to the “</em><strong><em>/usr/local/bin/</em></strong><em>” folder, which you can reach by opening Finder, and using </em><strong><em>cmd+shift+g</em></strong><em> combination.</em></li><li><em>Open the terminal and type `</em><strong><em>nano .bash_profile</em></strong><em>` command to edit </em><strong><em>.bash_profile</em></strong><em> file.</em></li><li><em>Add </em><strong><em>export PATH=”/usr/local/bin/chromedriver” </em></strong><em>to the last line.</em></li><li><em>Press </em><strong><em>control+x</em></strong><em>, </em><strong><em>y</em></strong><em> and </em><strong><em>enter</em></strong><em> respectively.</em></li></ol><p>Now you can initialize your Selenium Grid!</p><p>You can start <strong>Selenium Grid </strong>either in <strong>Standalone</strong> mode or with <strong>Hub &amp; Node</strong> configuration.</p><p><strong>Standalone</strong>: This mode combines all Grid components into one. With a single command, you can have a fully functional grid in a single process. But standalone mode can <strong>only run on a single machine</strong>.</p><p><strong>Hub &amp; Node</strong>: Hub &amp; Node is the most preferred mode because it allows you to:</p><ul><li>Combine different machines (with different OS and browser versions) in a single Grid</li><li>Have a single entry point to run WebDriver tests in different environments</li><li>Scaling capacity up or down without tearing down the Grid</li></ul><p>Let’s demonstrate how the standalone works.</p><h3>Spinning Up in Selenium Standalone Mode</h3><p>First, you need to spin up the grid in standalone mode by typing the command below in the terminal (use the version of your own jar file):</p><pre>java -jar selenium-server-4.9.0.jar standalone</pre><p>Note that you need to be in the same directory as the jar file or state its full directory to start it from another directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WG-K0-Nf9RRBJTlk.png" /></figure><p>As you can see, the Selenium server detects the drivers you downloaded and added to your path automatically. It then connects these drivers as nodes to your hub. (If you use Selenium &gt;4.0, it automatically detects browsers and downloads suitable webdrivers for them.)</p><p>Let’s see how your grid looks by going to <a href="http://localhost:4444/"><strong>http://localhost:4444 </strong></a>via any browser. Does this URL look familiar? Yep, that’s your default remote-url. <strong>Selenium Server sets port 4444 for Grid by default.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cXr3pv5TvIyf_YXq.png" /></figure><p>Let’s examine the grid and its components:</p><ol><li>This is your node. You can consider nodes as machines or containers.</li><li>These are the drivers that are installed on your node. You can run your tests on these browsers.</li><li>Sessions are the initialized browsers on which your tests are run. Currently, no tests are running, so it is 0.</li><li>This is the maximum number of sessions that can be opened at the same time. Default is 8, so you cannot run more than eight tests on this machine simultaneously. You can override it with --<strong>max-sessions </strong>CLI option.</li></ol><p>You can find complete CLI options for Selenium Grid <a href="https://www.selenium.dev/documentation/grid/configuration/cli_options/">here</a>.</p><p>Now let’s run one of your tests and see if the session counter increases or not…</p><p>…</p><p>…did it increase? No? You did not change your default driver; that’s why!</p><p>Let’s go to <strong>base_config.rb</strong> and change your driver to “<strong>remote-chrome”</strong>.</p><pre>@browser = ENV[&#39;browser&#39;] || &#39;remote-chrome&#39;<br>#     Available options<br>#       * chrome<br>#       * firefox<br>def self.browser<br> @browser<br>end</pre><p>Now run it again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*lXpSSyM93vcCzMDB.png" /></figure><p>Now you can see that your machine is recognised by the grid!</p><p>Now let’s try the Hub &amp; Node mode.</p><h3>Spinning Up Selenium in Hub &amp; Node Mode</h3><p>For demonstration purposes, I am going to use my MacBook as <strong>Hub</strong> and a <strong>Node</strong>. And then connect my Windows laptop as a <strong>Node</strong> as well. If you have another device at your disposal, use it as well for this example.</p><p>To start Selenium Server in Hub mode, you need to type the following command in your terminal:</p><pre>java -jar selenium-server-4.9.0.jar hub</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f-OmE-zl8Z3BajSK.png" /></figure><p>You can see that you have no nodes connected yet. Now by typing the below code, I connect my MacBook as a node to it. Note that since it is the same machine, I don’t need to state my hub address. You do it as well.</p><pre>java -jar selenium-server-4.9.0.jar node</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YDABh9lNbNDIzXXz.png" /></figure><p>Now you can see your device as a node. I am going to add my Windows machine as a node as well. To do this, download the jar file to the node machine, and type the below command into the command line of the node machine:</p><pre>java -jar selenium-server-4.9.0.jar node --hub http://192.168.0.27:4444/grid/register --port 5555</pre><p>The bold numbers should be your host’s IP number. You can see it on the terminal where you initiated your hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hmymv64owD7LsAkc.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SORm-iSvHUpBtCzE.png" /></figure><p>Now you can see both machines on your grid! But in order to use them in parallel, you need to configure your project for concurrent runs. So, let’s get down to it!</p><p><strong>Note</strong>: For every node, <strong>2 CPUs</strong> are recommended, and one Chrome instance that is up and running uses approximately <strong>120 MB</strong> of RAM. But you can find the optimal node and instance ratio for your device through trial and error.</p><h3>Parallel Test Configuration</h3><p>Let’s open your gemfile and add ‘<strong>parallel_tests’ </strong>gem to it.</p><pre># Gemfile<br>source &#39;https://rubygems.org&#39;<br><br>gem &#39;capybara&#39;<br>gem &#39;cucumber&#39;<br>gem &#39;selenium-webdriver&#39;<br>gem &#39;rspec&#39;<br>gem &#39;webdrivers&#39;<br>gem &#39;parallel_tests&#39;</pre><p>Then run `bundle update` command on the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/0*ZB_hJcT_UFmQRBIn.png" /></figure><p>Done!</p><p>You need to define a default profile for cucumber to give execute commands for your tests from the terminal.</p><p>Now create a cucumber.yml file under the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*RE35qSkjVwPe-ANq.gif" /></figure><p>And write the below line inside it:</p><pre>default: &quot;--format pretty&quot;</pre><p>This makes cucumber shell reports more readable.</p><p>Okay, now you can run your tests in parallel. There are several variations for this. Let’s see them:</p><p>1. Run your code in parallel by stating the number of sessions with -n argument. The below code will start two browser instances.</p><pre>parallel_cucumber -n 2</pre><p>2. Run your code in parallel by stating the browser type as well.</p><pre>parallel_cucumber -n 2 -o &#39;browser=remote-firefox&#39;</pre><p>3. Start multiple parallel execution processes running the same tests but in different browsers.</p><pre>parallel_cucumber -n 2 -o &#39;browser=remote-chrome&#39; &amp; parallel_cucumber -n 2 -o &#39;browser=remote-firefox&#39;</pre><p>Note that in the second and third examples, you are changing the values of environmental variables with custom values with the<strong> -o </strong>option.</p><p>Now let’s run your code in parallel!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7Mtd6GtofGlV0oyB.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t2FxWBln9WC9vdj5.png" /></figure><p>And that’s it! Now you can run your code remotely and in parallel! In the 4th part, you are going to <strong>dockerize</strong> your project and run it in containers in parallel. See you in the next chapter!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=043efed41cd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-3-043efed41cd1">Creating End-to-End Web Test Automation Project from Scratch — Part 3</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerize Your Web Test Automation Project from Scratch — Part 2.1]]></title>
            <link>https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/03d7e84d103a</guid>
            <category><![CDATA[web-testing]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[qa]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 11:53:55 GMT</pubDate>
            <atom:updated>2024-05-22T14:05:27.980Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating Your Web Test Automation Project from Scratch — Part 2.1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YdrykxKGkZyEB5rYhT3rSA.png" /></figure><p>Previously, we created the web test automation project and wrote scenarios. Before configuring the project to be run in parallel, let’s see how to save screen recordings of failed scenarios in this bonus chapter!</p><ul><li><a href="https://medium.com/@muhammettopcu/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><em>Let’s Create and Configure Our Web Test Automation Project!</em></a></li><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6"><em>Let’s Write Our Test Scenarios!</em></a></li><li><strong><em>Bonus: Recording Failed Scenario Runs in Ruby</em></strong></li><li><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></li><li><em>Let’s Dockerize Our Web Test Automation Project</em></li><li><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ul><h3>Recording Failed Scenario Runs on Ruby!</h3><p>Not every scenario runs as it should, unfortunately. To debug your code or pinpoint bugs, it’s best to have some hard evidence. Yes, I am talking about video recordings for your failed test scenarios!</p><p>Let’s install “screen-recorder” <a href="https://github.com/kapoorlakshya/screen-recorder">gem</a> by adding it to your <strong>gemfile</strong> and running the<strong> bundle update</strong> command:</p><pre>gem &#39;screen-recorder&#39;</pre><pre>bundle update</pre><p>And then let’s add it to your <strong>env</strong> file.</p><pre>require &#39;screen-recorder&#39;</pre><p>The gem you are going to use is dependent on the <strong>ffmpeg</strong> tool. Install it via brew.</p><pre>brew install ffmpeg</pre><p>With the command `<strong>which ffmpeg`</strong>, you can find the bin directory for the ffmpeg:</p><pre>➜  ~ which ffmpeg<br>/opt/homebrew/bin/ffmpeg</pre><p>Now add the directory of this binary to your env file as well:</p><pre>ScreenRecorder.ffmpeg_binary = &#39;/opt/homebrew/bin/ffmpeg&#39;</pre><p>And integrate the gem with your <strong>hook </strong>file.</p><p>As you remember, you created your <strong>hook.rb </strong>file in <a href="https://medium.com/@muhammettopcu/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71">Part 1 of this blog series</a>, and it looks like this:</p><pre>Before do<br> Driver.get_driver<br> page.driver.browser.manage.window.maximize<br>end<br><br>After do |scenario|<br> begin<br>   if scenario.failed?<br>     puts &quot;FAILED ==&gt; #{scenario.name}\n#{scenario.exception}:#{scenario.exception.message}&quot;<br>   else<br>     puts &quot;PASSED ==&gt; #{scenario.name}&quot;<br>   end<br>   Capybara.current_session.driver.quit<br> rescue Exception =&gt; exception<br>   puts &quot;FAILED ==&gt; #{exception}&quot;<br>   Capybara.current_session.driver.quit<br> end<br>end</pre><p>First, you need to configure your before hook. You already know that the before hook is initiated before your scenarios up to this point.</p><p>Change your first line to this:</p><pre>Before do |scenario|</pre><p>Cucumber provides you with a <strong>scenario</strong> object, with which you can reach the name of your scenario.</p><p>Let’s replace the blank lines in your scenario name with underscores using the command below. Using underscores instead of spaces helps you avoid file name related issues, since you are going to save the videos with scenario names.</p><pre>scenario_name = scenario.name.gsub(/[^A-Za-z0-9 ]/, &quot;&quot;).gsub(/\s+/, &quot;_&quot;)</pre><p>With the below line, print the scenario name on the console:</p><pre>puts &quot;STARTED ==&gt; #{scenario_name}&quot;</pre><p>Then create a recorder object and state the file name and location with the command below:</p><pre>@recorder = ScreenRecorder::Desktop.new(output: &quot;output/failed_tests/#{scenario_name}.mkv&quot;)</pre><p>And start your recorder.</p><pre>@recorder.start</pre><p>Now put everything together:</p><pre>Before do |scenario|<br> scenario_name = scenario.name.gsub(/[^A-Za-z0-9 ]/, &quot;&quot;).gsub(/\s+/, &quot;_&quot;)<br> Driver.get_driver<br> page.driver.browser.manage.window.maximize<br> puts &quot;STARTED ==&gt; #{scenario_name}&quot;<br> @recorder = ScreenRecorder::Desktop.new(output:<br> &quot;output/failed_tests/#{scenario_name}.mkv&quot;)<br> @recorder.start<br>end</pre><p>Up to this point, you’ve re-organized the before hook. After the before hook, your scenario will run and then the after hook will be executed.</p><p>Now configure the <strong>after hook</strong>. What you initially have is:</p><pre>After do |scenario|<br> begin<br>   if scenario.failed?<br>     puts &quot;FAILED ==&gt; #{scenario.name}\n#{scenario.exception}:#{scenario.exception.message}&quot;<br>   else<br>     puts &quot;PASSED ==&gt; #{scenario.name}&quot;<br>   end<br>   Capybara.current_session.driver.quit<br> rescue Exception =&gt; exception<br>   puts &quot;FAILED ==&gt; #{exception}&quot;<br>   Capybara.current_session.driver.quit<br> end<br>end</pre><p>Now alter your scenario name here as well:</p><pre>scenario_name = scenario.name.gsub(/[^A-Za-z0-9 ]/, &quot;&quot;).gsub(/\s+/, &quot;_&quot;)</pre><p>Since you executed your scenario, you need to stop your recorder first:</p><pre>@recorder.stop</pre><p>And you need to delete the video file if the scenario passes since you will only need the failed ones. You can delete your video file with the command below:</p><pre>File.delete(&quot;outputs/failed_tests/#{scenario_name}.mkv&quot;)</pre><p>Since you are going to save your files to this directory, you need to create it first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*iO-tAq5nOnkRsHPc.png" /></figure><p>Now re-organize your <strong>if-else </strong>and <strong>begin-rescue blocks </strong>to save only the failed scenario recordings:</p><pre>After do |scenario|<br> begin<br>   scenario_name = scenario.name.gsub(/[^A-Za-z0-9 ]/, &quot;&quot;).gsub(/\s+/, &quot;_&quot;)<br>Capybara.current_session.driver.quit<br>   @recorder.stop<br>   if scenario.failed?<br>     puts &quot;FAILED ==&gt; #{scenario_name}\n#{scenario.exception}:#{scenario.exception.message}&quot;<br>   else<br>     puts &quot;PASSED ==&gt; #{scenario_name}&quot;<br>     File.delete(&quot;outputs/failed_tests/#{scenario_name}.mkv&quot;)<br>   end<br> rescue Exception =&gt; exception<br>   puts &quot;FAILED ==&gt; #{exception}&quot;<br>   Capybara.current_session.driver.quit<br>   @recorder.stop<br> end<br>end</pre><p>Let’s run your scenarios by running the <strong>cucumber </strong>command on your terminal and see what happens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*6tg7VAVfxluOQ52P.png" /></figure><p>Failed scenario recordings have been saved, indeed!</p><p>Note that in <strong>MacOS</strong> and <strong>Linux</strong>, this gem records the whole desktop, and you cannot specify specific applications such as <strong>Chrome</strong> or <strong>Firefox</strong>. Therefore, you need to run your test scenarios one at a time.</p><p>Since this was a bonus feature, I am not going to include these changes in the upcoming parts and continue from where we left off in the second part.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03d7e84d103a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/dockerize-your-web-test-automation-project-from-scratch-part-2-1-03d7e84d103a">Dockerize Your Web Test Automation Project from Scratch — Part 2.1</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 2]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d18b42ebfe6</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[web-test-automation]]></category>
            <category><![CDATA[qa]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Wed, 22 Nov 2023 20:19:04 GMT</pubDate>
            <atom:updated>2023-11-23T13:05:10.616Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8A3oTCTPtOeMpRHnSqU9A.png" /></figure><p>Welcome to the second part of a blog post series called <strong>Creating End-to-End Web Test Automation Project from Scratch</strong>. The series consists of 8 posts in total:</p><ul><li><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><strong><em>Let’s Create and Configure Our Web Test Automation Project!</em></strong></a></li><li><strong><em>Let’s Write Our Test Scenarios!</em></strong></li><li><em>Bonus: Recording Failed Scenario Runs in Ruby</em></li><li><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></li><li><em>Let’s Dockerize Our Web Test Automation Project</em></li><li><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ul><h3>Let’s Write Our Test Scenarios!</h3><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><strong>In the previous post</strong></a>, we created our web test automation project and configured it. Now we are going to write our test scripts by covering a few topics, including <strong>Behaviour Driven Development</strong> and <strong>Page Object Model </strong>and finish our basic project. But hey, this is just the beginning. :)</p><h3>Behaviour Driven Development (BDD)</h3><p>In a nutshell<strong>, Behaviour Driven Development </strong>is a method to write test scripts in an everyday language so that every stakeholder understands what the system should do <strong>without needing any coding background</strong>.</p><p>You will implement this approach with the <strong>Cucumber</strong> framework by using <strong>Gherkin</strong> syntax. Before you dive into the code, please read my blog post titled “<a href="https://www.kloia.com/blog/mastering-cucumber-framework-slice-1-gherkin-keywords-and-cucumber-expression">Gherkin Keywords and Cucumber Expression</a>”. It will give you a fundamental understanding of what you are going to do.</p><h3>The First Test Feature</h3><p>Create a folder called “tests” under the <strong>features</strong> folder, and then create a file named “<strong>search.feature</strong>” under it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*CmtkJ3brtF9Nw39R.png" /></figure><p><strong>RubyMine</strong> IDE recognises <strong>.feature</strong> files as Cucumber files and gives specific icons to them.</p><p><strong>Note</strong>: Sometimes the IDE may not recognise feature files. If you encounter this issue, you need to add the file type to the IDE. To do this, go to <strong>RubyMine</strong> -&gt; <strong>Settings</strong> -&gt; <strong>File Types</strong> -&gt; <strong>Cucumber</strong> <strong>Scenario, </strong>then click on the <strong>“+” </strong>sign and add “<strong>*.feature” </strong>there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uy_9bJHysCj5uC0N.png" /></figure><p>Now, your first test is going to be about the search feature on amazon.com. The test steps are:</p><ol><li>Navigate to<strong> </strong><a href="http://www.amazon.com/"><strong>www.amazon.com</strong></a> website.</li><li>Fill the search bar with a keyword and click on the search icon.</li><li>Verify that the listed results are related to that keyword.</li></ol><p>Here is the test expressed in Gherkin syntax for Cucumber:</p><pre>Feature: Search related scenarios.<br><br> Scenario: Search an item on amazon.com<br>   Given go to home page<br>   When search &quot;computer&quot; on search bar on home page<br>   Then verify &quot;computer&quot; search results on search page</pre><p>If you don’t understand what these steps mean, it means that you didn’t read <a href="https://www.kloia.com/blog/mastering-cucumber-framework-slice-1-gherkin-keywords-and-cucumber-expression"><strong>the post I mentioned earlier</strong></a><strong> </strong>:) Please read it.</p><p>If you have followed the steps above, this is what you should be seeing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1zDnzyIlS2PTc5oI.png" /></figure><p>Why? Why these errors? These are just simple words, that’s why. To give these steps a purpose, you need to define them through code in the background.</p><p>To do that, create your first step definition file called “<strong>base_steps” </strong>by:</p><ol><li>Right-clicking on your first step (the line that starts with Given)</li><li>Show context actions</li><li>Create step definition</li><li>Create a new file</li></ol><p>You will see that your page is created under the “<strong>step_definitions”</strong> folder which is a default Cucumber folder.</p><p>In case your IDE does this automatically, you can just manually create a file under the step_definitions folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*lueziubffq0TFIk1.gif" /></figure><p>This is where we ended up:</p><pre>Given(/^go to home page$/) do<br> pending<br>end</pre><p>To get through this, let me talk about <strong>Page Object Model</strong> first.</p><h3>Page Object Model (POM)</h3><p>With the<strong> Page Object Model</strong>, we consider each web page as a class file. All the objects that exist on that page should be inside this class and nowhere else. By following this approach we reduce code duplication and make code maintenance much easier since a person can easily figure out where to look for the elements they are working with.</p><p>Let’s look at the schema below. In the project structure, you can see that page-specific elements and functions reside in respective files. Also, note that there are elements named “<strong>search_bar”</strong>on both pages. Since these are different pages, it is possible to use the same name for different elements having similar properties. We use them in page-specific contexts, so they do not conflict.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SXTSHWiyoa1zmJRx.png" /></figure><p><em>“Then, why did we name our step file base_page?”</em> Since visiting URLs is a general step, I prefer to put them under a step definition file named base_page. All objects and functions that cannot be categorised can be put there. Note that this is just a convention I use and not a universal rule. With time, you may also develop your own approach.</p><p>Let’s create your first page class <strong>base_page.rb</strong> file, in which you will write your navigating method!</p><h3>Your First Page</h3><p>Now create a folder called “<strong>pages</strong>” under the features folder, and then create a file named “<strong>base_page.rb”</strong> under it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*SN3aJvf44_2tRpQH.png" /></figure><p>Then define your class as <strong>BasePage</strong> and write your first class method.</p><p>Since you defined your default host in the environment file with <strong>app_host</strong> parameter <a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><strong>in the previous blog post</strong></a>, you can just write <strong>visit</strong> function and it navigates to “<a href="https://www.amazon.com/"><strong>https://www.amazon.com</strong></a><strong>” </strong>by default.</p><pre>class BasePage<br><br> def go_to_home_page<br>   visit<br> end<br><br>end</pre><p>But if you want to visit a different webpage, you can pass a parameter:</p><pre>class BasePage<br><br> def go_to_home_page<br>   visit(&#39;https://www.kloia.com&#39;)<br> end<br><br>end</pre><p>Now that you have your method, you can define your step with it.</p><pre>base_page = BasePage.new<br><br>Given(/^go to home page$/) do<br> base_page.go_to_home_page<br>end</pre><p>What does the first line do? Basically, you need to call your <strong>go_to_home_page</strong> method from a different file. In order to do that, you need an instance of that class that has the objects and methods. So you create an instance called base_page with <strong>base_page = BasePage.new </strong>line and access your methods through this instance.</p><p>Now you have your first step ready. Run your Scenario and see what happens!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r75Q6obg2dA9IElt.gif" /></figure><p>When you run the feature, you will see that your driver will navigate your browser to <a href="http://www.amazon.com/"><strong>www.amazon.com</strong></a> but then close it without doing anything else since you did not define the other steps yet.</p><p>Note that the browser has terminated after the execution of steps. This is because we defined this behaviour in our hooks. <a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71"><strong>See the previous blog post in this series</strong></a><strong>.</strong></p><p>It’s time to define your second step!</p><p>Create your second step definition like the first one, but this time name your file as <strong>home_steps.rb,</strong> since the objects and functions will be about the home page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*Z6EbTJigGWdkvheu.gif" /></figure><p>Now create your <strong>home_page.rb</strong> under the pages folder as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*W1O-c1FenFGPJ5RU.png" /></figure><p>And modify your file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*fDNGJI0X43bIioZX.gif" /></figure><p>initialize is the constructor method in ruby. You are going to define all your objects as variables inside of initialize method.</p><p>Now let’s find your first object on Amazon, <strong>search bar</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KzaEo5k9pU8wZTnX.gif" /></figure><p>You need to locate your objects with their CSS selector. For this:</p><ol><li>Open the <a href="http://www.amazon.com/"><strong>www.amazon.com</strong></a></li><li>Right-click on the page and click inspect on the right-click menu.</li><li>Click the element selection button in the upper left corner.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/38/1*kPXUUqrgod_dZXuYUGT5uw.png" /></figure><p>4. Then click on the element that you want to inspect. In this instance, it is the search bar.</p><p>5. Copy the <strong>id</strong> of the object. Which is “<strong>twotabsearchtextbox</strong>”.</p><p>6. Append # to use this id as a CSS selector: <strong>#twotabsearchtextbox</strong>. It is important to make sure that you write a CSS selector that matches only a single element on the page.</p><p><strong>Tip: </strong>You can search your CSS selector with cmd+f to see if it matches or not.</p><p>Note that the syntax for CSS selectors are critical in picking the right elements:</p><ul><li>. means class =&gt; .nav-progressive-attribute</li><li># means id =&gt; #twotabsearchtextbox</li></ul><p>For the comprehensive CSS selector sheet, please refer <a href="https://www.w3schools.com/cssref/css_selectors.php"><strong>here</strong></a>.</p><p>Now create your object variable with the selector you picked:</p><pre>class HomePage<br> def initialize<br>   @txt_search_bar_css=&quot;#twotabsearchtextbox&quot;<br> end<br>end</pre><p>Now try to create a unique selector for the search button without looking below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/104/0*-DtUuPu5qBw9G3ST" /></figure><pre>class HomePage<br> def initialize<br>   @txt_search_bar_css=&quot;#twotabsearchtextbox&quot;<br>   @btn_search_submit_css=&quot;#nav-search-submit-button&quot;<br> end<br>end</pre><p>Now you have all your objects, write a method to search a keyword.</p><pre>def search_item(item)<br> find(@txt_search_bar_css).send_keys(item)<br> find(@btn_search_submit_css).click<br>end</pre><p>First, you need to create your function <strong>search_item(item),</strong> which takes one argument named “item,” which is the product that you want to find in a string format.</p><p><strong>find</strong> method finds an object with the selector, and by appending the <strong>send_keys</strong> function to it, you can send text into the text fields. The item that you send through here is the product name you want to search for.</p><p>Note that Capybara provides you with useful functions to give commands to your webdriver such as <strong>fill_in</strong> and <strong>click_button</strong> functions, which take <strong>id</strong>, <strong>text</strong> or <strong>title</strong> as arguments.</p><pre>class HomePage<br> def initialize<br>   @txt_search_bar_id=&quot;twotabsearchtextbox&quot;<br>   @btn_search_submit_id=&quot;nav-search-submit-button&quot;<br> end<br>end</pre><pre>def search_item(item)<br> fill_in(@txt_search_bar_id, with: item)<br> click_button(@btn_search_submit_id)<br>end</pre><p>Note that while naming object selector, I used three-charactered labels as a prefix to make it easier to know what type that object is. So when you see an object starting with a <strong>txt </strong>prefix, you can understand that it is a <strong>textbox</strong>, and you can send words into it with suitable methods. As a suffix, I stated in which type selector is written such as <strong>css</strong>, <strong>xpath,</strong> or <strong>id</strong>.</p><p>You can find my naming conventions for object locators in the table below. You can create and use your own convention as well. Just make sure you stick to it.</p><pre>| Prefix        | Example           | Locator      |<br>| ------------- |-------------------|------------- |<br>| btn           | btn_login_id      |  Button      |<br>| chk           | chk_status_css    |  Checkbox    |<br>| cbx           | cbx_english_xpath |  Combo box   |<br>| lbl           | lbl_username_css  |  Label       |<br>| drp           | drp_list_xpath    |  Drop down   |<br>| slc           | slc_list_css      |  Selectbox   |<br>| txt           | txt_email_css     |  Textbox     |<br>| img           | img_logo_xpath    |  Image       |<br>| rdx           | rdx_female_xpath  |  Radiobox    |</pre><p>Also adding locator type as suffix can help you to specify locator type when using certain methods. Sometimes you may need to pass the locator type to a function as an argument. You did not need to specify in your previous elements and that is because the default selector is css. Do you remember that you chose your default selector as “<strong>:css</strong>” in the <strong>env.rb</strong> file?</p><p>If you want to use xpath locator instead, you specify it like this in the find method:</p><pre>find(:xpath, @btn_search_submit_xpath)</pre><p>Since you sent your text into the text field of the search bar, now you need to click on the search button next to it.</p><p>Let’s find your object with the <strong>find</strong> method, and then click on it by appending the <strong>click</strong> method to the find method.</p><p>Now that your function for searching for an item is ready, it is time to implement it in the step definitions you have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2M2R_Ks084b8k-CX.gif" /></figure><ol><li>Create a class instance of <strong>HomePage</strong> called <strong>home_page</strong>.</li><li>Call our <strong>search_item </strong>method through it in the body of the step definition.</li><li>Pass the arg to our function.</li></ol><p>Note that the <strong>arg</strong> you passed is the word that you write in the feature file enclosed with double quotes. So the <em>computer</em> will be passed as an argument for this instance. With this configuration, you have made your step re-usable with different keywords.</p><p>Let’s run your code again!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/0*QF27kKrc-vSkcZmA.gif" /></figure><p>As you see, it typed “computer” and clicked on the search button.</p><p>Now comes the last step in your scenario!</p><p>You need to verify that the results shown are related to the keyword that you searched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*falAEQ1KqD_rg_kY.png" /></figure><p>Now you need to find the coloured keyword inside the double quotes and compare it with your search keyword. Try to find its CSS selector, then check your result with the code below.</p><pre>class SearchPage<br> def initialize<br>   @lbl_search_result_css=&quot;.a-color-state.a-text-bold&quot;<br> end<br> end</pre><p>This time, I used class notation. Note that the <strong>lbl</strong> prefix indicates that this object is a label, so you can extract text from it. Do you realise that I have written this object in a new class named <strong>SearchPage</strong>? That’s because the search result text belongs to the search page.</p><p>So your project directory now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*s2uYi3vQ55DO1_as.png" /></figure><p>Now create a verification method for search results:</p><pre>def verify_search_results(item)<br>    find(@lbl_search_result_css).text.should include(item)<br>end</pre><p>Here I defined a method called <strong>verify_search_results </strong>that takes the search keyword “<strong>item” </strong>as an argument.</p><p>What this method does:</p><ol><li>Find the object with a specified selector by using <strong>find</strong> method.</li><li>Access its text by appending <strong>text</strong> method.</li><li>Use RSpec’s <strong>should</strong> keyword to make an assertion statement. If it is false, the step fails.</li></ol><p>What you assert is that the text of the <strong>lbl_search_result</strong> object includes your keyword itself. Why did you <strong>assert</strong> it with <strong>include</strong> but not with <strong>==</strong> operator, you might ask.</p><p>Let’s print <strong>find(@lbl_search_result).text </strong>to the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*RKIDHnwI3Rb-JbfO.png" /></figure><p>You can see that the text is within double quotes. So simply using <strong>==</strong> would fail since your keyword passed with an <strong>arg</strong> is not within double quotes.</p><p>For the verification to pass, you might try stripping this text from double quotes or enclosing your keyword with it. It is up to you. The below variation works as well:</p><pre>def verify_search_results(item)<br> find(@lbl_search_result_css).text.should ==&#39;&quot;&#39;+item+&#39;&quot;&#39;<br>end</pre><p>Now run your scenario one last time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*-8nu1k3WMspQ7CWS.gif" /></figure><p>And you are done! You have created your first scenario! Let’s meet in the comments section if you have any questions.</p><p>Next, we are going to level up your project to run it on remote browsers and to run multiple scenarios in parallel! So before going to Part 3, please try to find and write at least 4 scenarios, so you can run your own scenarios in parallel!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d18b42ebfe6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-2-0d18b42ebfe6">Creating End-to-End Web Test Automation Project from Scratch — Part 2</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End Web Test Automation Project from Scratch — Part 1]]></title>
            <link>https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5eba05a3d71</guid>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[capybara]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Fri, 27 Oct 2023 14:29:47 GMT</pubDate>
            <atom:updated>2023-11-16T10:49:06.980Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End Web Test Automation Project from Scratch — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*deiqvC-W3BUkoN9yYfygFQ.png" /></figure><p>In this series of blog posts, we will be creating an end-to-end <strong>Web Test Automation</strong> <strong>Project</strong>. The series consists of 8 posts in total:</p><ul><li><strong><em>Let’s Create and Configure Our Web Test Automation Project!</em></strong></li><li><em>Let’s Write Our Test Scenarios!</em></li><li><em>Bonus: Recording Failed Scenario Runs in Ruby</em></li><li><em>Let’s Configure Our Web Test Automation Project for Remote Browsers and Parallel Execution</em></li><li><em>Let’s Dockerize Our Web Test Automation Project</em></li><li><em>Bonus: Recording Scenario Runs on Docker with Selenium Video!</em></li><li><em>Let’s Integrate Our Dockerized Web Test Automation Project with CI/CD Pipeline!</em></li><li><em>Auto-Scaling and Kubernetes Integration with KEDA</em></li></ul><p>We are going to create our test automation project with <strong>Ruby</strong> which is a high-level programming language. <strong>Capybara Framework</strong> helps us automate browsers and <strong>Cucumber Framework </strong>allows us to write our scenarios in <strong>Behavior Driven Development</strong> format. You don’t know <strong>BDD</strong> approach? Do not worry, I will cover it.</p><p>To make our project executable on any machine without setting up environmental configurations and preventing the common programming issue of “But it works on my machine!”, we are going to dockerize our project using <strong>Docker Engine</strong>!</p><p>And finally, we are going to integrate <strong>CI/CD </strong>pipeline by using <strong>Jenkins</strong> and make our project auto-scalable by using <strong>Kubernetes</strong>.</p><p>It will be a pretty cool project, and presumably a longer one, but bear with me, it will be worth your while.</p><h3>Let’s Create and Configure Your Web Test Automation Project!</h3><p>To begin, you need a website to test. You are going to develop test suites and create automated tests for that website.</p><p>I think a popular website would be the best option since it would give you the opportunity to work on real-life cases and lets us tackle possible challenges. So here it is:</p><p>“I choose you <a href="https://www.amazon.com/">Amazon</a>!”</p><p>Now you can start installing what we are going to need.</p><p><strong>Note:</strong> All installation tutorials will be for MacOS. Package management systems or some commands may differ, but the process will be more or less the same.</p><h3>Xcode Installation</h3><p>You are going to use <strong>Homebrew</strong> as a package management system. But most of its packages require a compiler. You can install the full <strong>Xcode</strong> or just <strong>Command Line Tools</strong> from the <strong>App Store</strong> or using the command below.</p><pre>xcode-select --install</pre><h3>Homebrew Installation</h3><p>A package management system makes installing packages much easier. Note that you do not need to install Homebrew to install the following languages or frameworks, but it is <em>convenient</em>.</p><p>You can find more detailed <a href="https://docs.brew.sh/Installation"><strong>Homebrew Installation instructions here</strong></a>. You can take a look at if you want.</p><p>Install homebrew with the following command:</p><pre>/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;</pre><p>After the installation, enter this:</p><pre>brew --version</pre><p>You should see something similar to the one below If your installation is successful:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YgBtchGPg9FiUocm4lkOnw.png" /></figure><h3>Ruby Installation</h3><p>Next, you will install <strong>rbenv</strong> with its <strong>ruby-build</strong> plugin, which allows you to install more than one Ruby version on our machine and manage them easily. It is a light weighted and useful package. To install both of these:</p><pre>brew install rbenv ruby-build</pre><p>The command below gives you the instructions to load rbenv in your shell.</p><pre>rbenv init</pre><p>If you use bash as a shell, with the following command you can load rbenv in your shell.</p><pre>eval &quot;$(rbenv init -)&quot; &gt;&gt; ~/.bash_profile</pre><p>The next command reloads your .bash_profile so the changes take effect. Or you can simply close your terminal and open a new one.</p><pre>source ~/.bash_profile</pre><p>Now pick the preferred Ruby version by listing and choosing the version you want to work with. Note that Capybara supports Ruby version 3.0+ as of now. So make sure to install 3.0 or later version of it.</p><pre># lists all available versions<br>$ rbenv install -l# install a Ruby version<br>$ rbenv install -package-# check installed version<br>$ ruby -v</pre><p>To make this Ruby version the default for your machine, use the command below:</p><pre>rbenv global</pre><p>For the official and comprehensive installation guide, please refer to <a href="https://www.ruby-lang.org/en/documentation/installation/"><strong>this documentation</strong></a>.</p><h3>Bundler Installation</h3><p><strong>RubyGems</strong> serves as a package manager for the Ruby programming language. It establishes a uniform method for distributing Ruby applications and libraries. The gems are simply open-source libraries that contain Ruby code and are packaged with a little extra data.</p><p><strong>Bundler </strong>is a dependency management gem that allows you to list all required gems in a file and automatically download them. It also gives you the flexibility to declare gem versions.</p><p>Install the bundler with the command below:</p><pre>gem install bundler</pre><h3>RubyMine Installation</h3><p>I am going to use <strong>RubyMine</strong> of <strong>JetBrains</strong> as my IDE but you can choose your own favorite tool. You can download RubyMine on <a href="https://www.jetbrains.com/ruby/"><strong>this link</strong></a>, it is pretty straightforward.</p><p>Note that it gives a one-year license if you have an education e-mail. The community trial version gives you one month of trial license.</p><h3>RubyMine Configuration</h3><p><strong>RubyMine </strong>=&gt; <strong>Preferences </strong>=&gt; <strong>Plugins </strong>and search for Gherkin. Install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e24nZm2dcwtqtTBiopstZQ.png" /></figure><p><strong>Extra</strong>: Installing <strong>Cucumber+ </strong>plugin makes it easy to execute scenario runs. You might find it useful as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AmfpEOIMgYkLNTXP1oJh6w.png" /></figure><p>Why do we use Gherkin? It helps us to create code steps using English-like sentences that anyone without coding knowledge could understand.</p><p>Why do we need the plugin? It provides coding assistance for step definitions.</p><p>For comprehensive information, please refer to our blog posts about <a href="https://www.kloia.com/blog/mastering-cucumber-framework-slice-1-gherkin-keywords-and-cucumber-expression"><strong>Gherkin Syntax and Cucumber Framework</strong> </a>and <a href="https://www.kloia.com/blog/behavior-driven-development-bdd-cucumber"><strong>Behavior Driven Development</strong></a>.</p><p>Now you are all set! It’s time to create your project.</p><h3>Creating the Project</h3><p>Use <strong>File</strong> =&gt; <strong>New</strong> =&gt; <strong>Project… </strong>, name your project, and choose your Ruby SDK. Then click <strong>create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoF0WXr0ATfjOr0oEjB6tQ.png" /></figure><h3>Gemfile Configuration</h3><p>Next, you will create your gemfile. Gemfile is the list of our dependencies. You are going to need the below gems for your project.</p><pre># Gemfile<br>source &#39;https://rubygems.org&#39;<br>gem &#39;capybara&#39;<br>gem &#39;cucumber&#39;<br>gem &#39;selenium-webdriver&#39;<br>gem &#39;rspec&#39;</pre><pre>gem &#39;webdrivers&#39;, &#39;~&gt; 5.2.0&#39;</pre><p>Let me give you a brief explanation about what these gems do:</p><ul><li><a href="https://github.com/teamcapybara/capybara"><strong>capybara: </strong></a>This gem provides much more readable and easier automation methods than Selenium’s native ones.</li><li><a href="https://github.com/cucumber/cucumber-ruby"><strong>cucumber: </strong></a>Cucumber is a framework for running automated tests written in plain language.</li><li><a href="https://www.rubydoc.info/gems/selenium-webdriver/frames"><strong>selenium-webdriver: </strong></a>This gem provides Ruby bindings for Selenium.</li><li><a href="https://github.com/rspec"><strong>rspec:</strong></a> RSpec is a unit test framework for the Ruby programming language.</li><li><a href="https://github.com/titusfortner/webdrivers"><strong>webdrivers:</strong></a> This gem automatically installs and updates all supported drivers, which are essential for controlling web browsers through code. Note: If you use Selenium 4.6.0, you won’t be needing this game and Selenium would set up the required web drivers for you.</li></ul><p>After creating and saving the file with the gems listed, run ` <em>bundle install`</em> command in your project’s directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3xW-BytgNmXGxVm2JaPTg.png" /></figure><p>Congratulations, you’ve installed everything you need!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0efVvhWMuq4RXuct_RmhrQ.png" /></figure><p>Next, create Cucumber’s base folder structure:</p><pre>cucumber --init</pre><p>You will see that a <strong>feature</strong> folder is created along with some sub-folders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*Yq5zp2i2amuiFCwVRHdN5Q.png" /></figure><p>Now you can start creating some important files and populate them!</p><h3>Config Folder and base_config.rb</h3><p>It is best to store the project’s configurations explicitly in a file. To do that, create a folder named “ <strong>config </strong>“ under the root of the project and then create a file named “ <strong>base_config.rb </strong>“ under it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*TIznKJ8unAdzWYWqbffa2A.png" /></figure><p>What are you going to write in it? The project variables that do not change usually and environmental variables that you will manage dynamically. Your driver and execution configurations are examples of this.</p><pre># frozen_string_literal: true<br><br>module BaseConfig<br><br>  @wait_time = 20<br># Default wait time variable to be used on Capybara functions.<br>  def self.wait_time<br>    @wait_time<br>  end<br><br>  @browser = ENV[&#39;browser&#39;] || &#39;chrome&#39;<br>#     Available options<br>#       * chrome<br>#       * firefox<br>  def self.browser<br>    @browser<br> end<br><br>  @headless = ENV[&#39;headless&#39;] || &#39;false&#39;<br># Available options<br>#   * &#39;false&#39;<br>#   * &#39;true&#39;<br>  def self.headless<br>    @headless<br>  end<br>end</pre><ul><li><strong># frozen_string_literal: true</strong>` freezes every string literal in our file explicitly, meaning that you cannot change them in run time.</li><li><strong>@wait_time </strong>defines a custom wait time before a driver function fails. With the `<em>def self.wait_time</em>` line, you can call it outside this file by simply calling <strong>BaseConfig.wait_time</strong></li><li><strong>@browser</strong> variable lets you define the default web driver to run tests on. <strong>ENV[‘browser’] || ‘chrome</strong>’ means that if you provide an argument for the browser while running the Cucumber in the command line, it uses that argument, otherwise uses <strong>‘chrome’</strong> as your default browser value. (E.g. parallel_cucumber -o ‘browser=”firefox”’)</li><li><strong>@headless</strong> defines whether your tests would be run on the browser in headless mode or not. <strong>ENV[‘headless’] || ‘false’ </strong>is just the same as above.</li></ul><p>Now let’s create your driver configurations and make use of the above settings.</p><h3>Utils Folder and driver.rb</h3><p>Create a folder named “ <strong>utils</strong>” under the root of the project and then create a file named “ <strong>driver.rb</strong> “ under it. You can store your custom-made general functions in this folder and call them wherever you need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*HqyQWKlre1PGs9V3XOjSdw.png" /></figure><p>You need to configure your drivers by populating driver.rb file with the code below!</p><pre>class Driver<br><br>  def self.get_driver<br>    case BaseConfig.browser<br>    when &#39;chrome&#39;<br>      options = Selenium::WebDriver::Chrome::Options.new<br>      add_default_values(options)<br>      Capybara.register_driver :selenium do |app|<br>        Capybara::Selenium::Driver.new(app,<br>                                       browser: :chrome,<br>                                       options: options)<br>      end<br><br>    when &#39;firefox&#39;<br>      options = Selenium::WebDriver::Firefox::Options.new<br>      add_default_values(options)<br>      Capybara.register_driver :selenium do |app|<br>        Capybara::Selenium::Driver.new(app,<br>                                       browser: :firefox,<br>                                       options: options)<br>      end<br>  end<br><br>  def self.add_default_values(options)<br>    options.add_argument(&#39;--disable-popup-blocking&#39;)<br>    options.add_argument(&#39;--ignore-certificate-errors&#39;)<br>    options.add_argument(&#39;--disable-notifications&#39;)<br>    add_headless_options(options) if BaseConfig.headless == &#39;true&#39;<br>  end<br><br>  def self.add_headless_options(options)<br>    options.add_argument(&#39;--no-sandbox&#39;)<br>    options.add_argument(&#39;--headless&#39;)<br>    options.add_argument(&#39;--window-size=1280,720&#39;)<br>    options.add_argument(&#39;--disable-dev-shm-usage&#39;)<br>    options.add_argument(&#39;--disable-gpu&#39;)<br>    options.add_argument(&#39;--test-type=browse&#39;)<br>  end<br><br>end</pre><p>Now I am going to break it down bit by bit:</p><pre>class Driver<br><br>  def self.get_driver<br>    case BaseConfig.browser<br>    when &#39;chrome&#39;<br>      options = Selenium::WebDriver::Chrome::Options.new<br>      add_default_values(options)<br>      Capybara.register_driver :selenium do |app|<br>        Capybara::Selenium::Driver.new(app,<br>                                       browser: :chrome,<br>                                       options: options)<br>      end</pre><p>This part creates a class named <strong>Driver. </strong>The class has a <strong>get_driver</strong> method with the <em>self</em> prefix, that will enable us to call it from outside by using <strong><em>Driver.get_driver</em></strong><em>.</em></p><p>The method has a <strong>switch-case</strong> block, customized with <strong>BaseConfig.browser</strong> variable. You remember the <strong>@browser</strong> variable on our <strong>base_config.rb</strong> file? It will match with this and use the matching configurations!</p><p>Now let’s inspect the browser-specific driver configurations:</p><p><strong>- options = Selenium::WebDriver::Chrome::Options.new</strong>, with this line, you create a chrome browser options object</p><p><strong>- add_default_values(options)</strong>, with this method, you add default browser options to your web driver. Now you implement this method with the code below:</p><pre>def self.add_default_values(options)<br>    options.add_argument(&#39;--disable-popup-blocking&#39;)<br>    options.add_argument(&#39;--ignore-certificate-errors&#39;)<br>    options.add_argument(&#39;--disable-notifications&#39;)<br>    add_headless_options(options) if BaseConfig.headless == &#39;true&#39;<br>  end</pre><p>You created a method named <strong>add_default_values</strong> that takes an `options object` as a parameter and adds arguments to it with the <strong>add_argument</strong> method.</p><p>You have another method named <strong>add_headless_options(options) </strong>which only gets activated and adds another set of arguments to your options object if the <strong>@headless</strong> variable in our <strong>base_config.rb</strong> file is <strong>‘true’</strong>.</p><pre>def self.add_headless_options(options)<br>    options.add_argument(&#39;--no-sandbox&#39;)<br>    options.add_argument(&#39;--headless&#39;)<br>    options.add_argument(&#39;--window-size=1280,720&#39;)<br>    options.add_argument(&#39;--disable-dev-shm-usage&#39;)<br>    options.add_argument(&#39;--disable-gpu&#39;)<br>    options.add_argument(&#39;--test-type=browse&#39;)<br>  end</pre><p>Let’s inspect these arguments:</p><ul><li><strong>‘--no-sandbox’</strong> lets you run the web driver outside of a sandbox environment, which is a very restricted one with few privileges.</li><li><strong>‘--headless’</strong> opens the web driver without a window, in the background.</li><li><strong>‘--window-size=1280,720’</strong> sets the window size of your web browser.</li><li><strong>‘--disable-dev-shm-usage’</strong> is a Chrome flag that is used to disable the use of /dev/shm , which is a shared memory space where Chrome stores temporary files.</li><li><strong>‘--disable-gpu’ </strong>disables hardware acceleration.</li><li><strong>‘--test-type=browse’ </strong>allows the test code to run more smoothly with the benefits listed <a href="https://github.com/GoogleChrome/chrome-launcher/issues/24">here</a></li></ul><p><strong>Note:</strong> You can find the other browser options <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc"><strong>here</strong></a>.</p><p>Finally, register your driver.</p><pre>Capybara.register_driver :selenium do |app|<br> Capybara::Selenium::Driver.new(app,<br>                                browser: :chrome,<br>                                options: options)<br>end</pre><p><strong>Capybara.register_driver</strong> lets you register your web driver type. You will use Selenium web driver in the background. Inside of the do block, you state your <strong>browser type</strong> and <strong>options</strong>, which you created earlier. When you look at case blocks for firefox and chrome, you will realize that the only thing that changes is the browser type.</p><p>So, in this file, you used the <strong>@browser</strong> and <strong>@headless</strong> variables but you did not initialize the <strong>get_driver</strong> method anywhere yet. Then let’s get into it!</p><h3>Support Folder and env.rb</h3><p>In the previous section, you created a basic Cucumber folder structure with <strong>cucumber --init </strong>command. Before you get down to doing <strong>hooks.rb</strong>, create another important file just beside it. The <strong>env.rb</strong>!</p><pre>require &#39;capybara&#39;<br>require &#39;capybara/dsl&#39;<br>require &#39;selenium-webdriver&#39;<br>require &#39;rspec&#39;<br>require &#39;webdrivers&#39;<br><br>require_relative &#39;../../utils/driver.rb&#39;<br>require_relative &#39;../../config/base_config.rb&#39;<br><br><br>include Capybara::DSL<br>include RSpec::Matchers<br><br>Capybara.configure do |config|<br> config.default_driver = :selenium<br> config.default_selector = :css<br> config.app_host = &#39;https://www.amazon.com&#39;<br> config.default_max_wait_time = BaseConfig.wait_time<br>end</pre><ul><li><strong>require</strong> loads gems and executes them. With it, you import all class and method definitions in the file.</li><li><strong>require_relative</strong> does the same thing but by specifying the relative paths of the files.</li><li><strong>include </strong>brings in the methods of these two packages into your file.</li><li>In the <strong>Capybara.configure</strong> block, you configure Capybara with attributes.</li></ul><h3>Configuring hooks.rb!</h3><p>And last but not least, let’s configure your hooks.rb file!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*G0TyV5oLDhbzHJNhCL1bTw.png" /></figure><p>Hooks are tools that <strong>Cucumber </strong>provides to execute custom codes <strong>before </strong>and <strong>after </strong>a scenario is run. This is where you initiate your driver.</p><pre>Before do<br> Driver.get_driver<br> page.driver.browser.manage.window.maximize<br>end<br><br>After do |scenario|<br> begin<br>   if scenario.failed?<br>     puts &quot;FAILED ==&gt; #{scenario.name}\n#{scenario.exception}:#{scenario.exception.message}&quot;<br>   else<br>     puts &quot;PASSED ==&gt; #{scenario.name}&quot;<br>   end<br>   Capybara.current_session.driver.quit<br> rescue Exception =&gt; exception<br>   puts &quot;FAILED ==&gt; #{exception}&quot;<br>   Capybara.current_session.driver.quit<br> end<br>end</pre><p>In the <strong>Before</strong> block, you run the <strong>get_driver </strong>method which we defined in <strong>driver.rb</strong>. So before every scenario, a new driver instance gets created.</p><p>The additional <strong>page.driver.browser.manage.window.maximize </strong>makes your web browsers’ windows maximized.</p><p>In the <strong>After</strong> block, you have a scenario object which Cucumber provides. It has attributes such as name and exception. You use this information to increase readability by logging them or printing them to the console in the <strong>begin-rescue </strong>block. In the after block, taking screenshots of failed scenarios can be useful to pinpoint the reasons for failure.</p><p>Additional hook keywords can be found in the <a href="https://cucumber.io/docs/cucumber/api/?lang=java#hooks"><strong>Cucumber Documentation</strong></a>.</p><p><strong>Capybara.current_session.driver.quit </strong>terminates the current driver instance. So before every scenario, you start with a fresh driver instance, and after your scenario execution, you terminate it.</p><p>With this, I conclude the first chapter of this blogpost series. In the next chapter, you are going to write your test scripts with <strong>Page Object Model (POM)</strong> and <strong>Cucumber</strong>! If you have any questions, don’t hesitate to write a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5eba05a3d71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/creating-end-to-end-web-test-automation-project-from-scratch-part-1-d5eba05a3d71">Creating End-to-End Web Test Automation Project from Scratch — Part 1</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My first year at kloia]]></title>
            <link>https://medium.com/kloia/my-first-year-at-kloia-fde8e2a5a592?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/fde8e2a5a592</guid>
            <category><![CDATA[work-experience]]></category>
            <category><![CDATA[kloia]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[work-life-balance]]></category>
            <category><![CDATA[it]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Mon, 15 May 2023 07:57:15 GMT</pubDate>
            <atom:updated>2023-12-11T04:07:54.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhQnixkmR8xdbY6cNOTfwQ.png" /></figure><p>I started working at <strong>kloia </strong>about a year ago. You might remember <a href="https://medium.com/kloia/my-first-month-at-kloia-6670ffa9d5e7">my blog post about my first month</a>. Many things have changed since then. First of all, I learned a new language. I don’t mean a programming language. No, I learned the language of a programmer. Now I know the difference between dockers and docker for instance! :D</p><p>I moved to Software Test Automation Engineering from Energy System Engineering. This move was full of mysteries for someone like me who does not have a programming background. All I saw was a wall of mist on my first days, and I was trying to find my way in it. My mentors were my beacons that shed light on my path. With their help, I filled the gaps between what I think I know and what I actually know. The knowledge that I obtained along helped me dissipate the fog.</p><p>But the more I learn, the more I realize my ignorance. And oh my, it never ceases to amaze me!</p><p>Now, let’s take a look at what I have been doing throughout the last year. But beware: <em>When you gaze into the code, the code also gazes into you.</em></p><h3>Step One: Learn how to use computer</h3><p>I am not kidding. I have been using computers for a long time, but I needed to learn the basics again. Why? Because I used macOS for the first time in my life! If you are 25 years old and you have been using Windows for 17 years, life is pretty hard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ABVKm1UKW56VY16c.jpg" /></figure><p>Are you just like me? Here is a test of mine creatively called, “Are you a Windows user?”</p><ul><li>Do you force quit applications relentlessly when trying to type @ sign?</li><li>Do you try to find “create new file” option in the right click menu?</li><li>Do you expect clicking the red X button would close an application?</li></ul><p>If you said yes to at least two questions, or you don’t know what this is about, then we are probably the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ViVA7_z7rWEfhGA3.png" /></figure><h3>My first client, a new horizon</h3><p>Kloia is a consultancy company. My department, Quality Assurance, gives consultancy regarding application test procedures such as manual testing, API testing, performance testing, and integration of test automation infrastructure.</p><p>After the onboarding period, I was eager to be a part of a project. Until kloia placed me on a client project, I was working with my mentors one-on-one with small tasks, acting as tutorials and keeping me ready for the project to come.</p><p>Aaand I got assigned to a big test automation project along with five teammates! The Istegelsin project was my first project, and I was very eager to learn anything I can. That might be the reason that I got involved in 4 different sub-projects at once including Web, Mobile, API test automation and data management projects.</p><p>It was an intense project, but I got a chance to get hands-on experience on test creation, test automation, documentation, agile development, API testing and more.. Towards the end of my involvement in the project, I was able to onboard new team members and to contribute new ideas.</p><h3>Gain it, no matter what it is</h3><p>If you are working at kloia, you do not gain just knowledge or income, you gain <strong>weight</strong> as well.</p><p>Almost everyone loves eating at kloia and social meetings usually revolve around a meal or magically ends up with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/0*sIvo4byZ9_WE3m5a.gif" /></figure><p>We also have a Google sheet named “<strong>kiloia”</strong>, where the entire company logs in their weight every six months. I still do not know what the goal of this sheet is: gaining weight or losing it? :D One thing is certain though, everyone in kloia is worth their weight in gold. That’s how the company makes us feel.</p><h3>Be curious. Ask everything, but not twice.</h3><p>Not everyone has a memory like an elephant. For someone like me who could only compete with a goldfish in terms of memory, it was difficult to memorize every work-related term that I don’t know. At some point, my brain got to the point that it would burst out with all the unknown words. That is when I realized that I needed a note-taking app to remember all these terms.</p><p>By using versatile note-taking apps such as Notion or Obsidian, I started creating files for every keyword related to programming, business or science that I have no idea about. In my spare time, I populated each file by searching through the Internet.</p><p>I did this usually after work and it is a tiresome business. Pushing myself to learn after work required all the glucose in my brain cells, and it is not sustainable doing this every day and night. Yet, I tried it. I exhausted my brain by trying to learn and do everything at once, and as you would guess, I burned out… It took four days of break to cool myself out.</p><p>Since then, I have developed a more sane personal development routine. Now I try to stay below my mental exhaustion limits. If you are coming from a different industry like me, to catch up with your peers, a higher pace is needed. But you shouldn’t rush things as I did, or you burn your circuits as well. :D Finding out your limits and proceeding with safe speeds below those limits is key to creating a fruitful and sustainable career.</p><p>Learning by yourself is also a crucial skill. But if figuring out something by yourself takes too much time, you should consider taking advice from others. There is a fine line between self-study and wasting time. Here is how I balance my inquisitive efforts: I do not hesitate asking any questions, but I don’t ask the same question twice.</p><h3>A new achievement unlocked!</h3><p>Another thing kloia provides is a space for self-improvement. Many companies regard their employees as discardable or replaceable parts, and they do not want to allocate any self-development resources. But in kloia, I can assure you that if you need anything, they would do anything to satisfy your needs.</p><p>Kloia encourages its employees to get professional certificates. And these certificates do not need to be related to your field at all, so long as it is related to the software industry! I got my <strong>ISTQB CTFL </strong>certificate recently and everything was covered by the company — even tough I failed the first test. Now I am preparing for<strong> AWS Developer Associate</strong> certification, which is encouraged by the company as well. Any material you need to be prepared for certification is also provided, should it be online courses or written materials. I needed a book to prepare AWS-DA certificate, and it was delivered to me in three days!</p><p>If you need to improve your English, kloia offers support as well. The company guarantees to cover your expenses on English learning platforms such as Cambly after you advance to a certain level.</p><h3>What I feel lucky about working at kloia</h3><p><strong>Having great mentors: </strong>I can ask anything, whether it is related to my department or not.</p><p><strong>Utilizing my skills: </strong>I can utilize my diverse skills such as story writing, English, and translation to come up with creative marketing outputs and to contribute to kloia in different ways.</p><p><strong>Ever-growing learning curve</strong>: To be able to learn new things in every working hour is just a paradise for me. This is amplified with internal informative sessions.</p><p><strong>Internal Events:</strong> Especially food related ones. Period.</p><p><strong>Feeling at home:</strong> Every kloian is someone that I can trust and someone who is ready to help. Literally working at home helps as well. ^^</p><p>With this, I conclude my first year at kloia. It was a great year with tons of information and important milestones for my career. See you next year… in a blog post or in our company! :)</p><p><em>Originally published at </em><a href="https://www.kloia.com/blog/my-first-year-at-kloia"><em>https://www.kloia.com</em></a><em> on May 15, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fde8e2a5a592" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/my-first-year-at-kloia-fde8e2a5a592">My first year at kloia</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Slice 1: Gherkin Keywords and Cucumber Expression]]></title>
            <link>https://medium.com/kloia/slice-1-gherkin-keywords-and-cucumber-expression-72ae660a8936?source=rss-f60deb85e587------2</link>
            <guid isPermaLink="false">https://medium.com/p/72ae660a8936</guid>
            <category><![CDATA[gherkin]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[cucumber]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[bdd]]></category>
            <dc:creator><![CDATA[Muhammet Topcu]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 13:51:13 GMT</pubDate>
            <atom:updated>2024-05-22T14:05:39.185Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZepApAu3VBvcdod91mIlA.jpeg" /></figure><p>Cucumber is a framework that uses Gherkin Syntax to drive Behavior Driven Development in your test infrastructure. (Need a quick primer on BDD? <a href="https://www.kloia.com/blog/behavior-driven-development-bdd-cucumber">Check out this blogpost</a>) In this blog post, I will take a glance at Gherkin keywords and demonstrate the power of Cucumber Expression — the alternative to regex step definitions.</p><h3>Gherkin Keywords</h3><p>Gherkin keywords have specific functionalities, such as defining features. Every feature consists of scenarios having a certain scope, and every scenario consists of steps defined by regex or Cucumber Expression in step definitions.</p><h3>Feature/Ability/Business Need</h3><ul><li>Name of the .feature file.</li><li>There can be only one feature keyword per .feature file.</li><li>It can get description words below itself.</li></ul><pre>Feature: User Features<br><br>  Application should be tested against possible behaviors of registered users.<br><br>  Scenario: Logging in with registered user</pre><p><strong>Note:</strong> The description line shown above can also be used with <strong>Background</strong>, <strong>Rule</strong>, <strong>Scenario,</strong> or <strong>Scenario Outline </strong>(and with their aliases) unless a keyword is used beforehand.</p><p>Also note that some keywords such as <strong>Feature</strong> get semicolons as a suffix and do not work without it.</p><h3>Rule</h3><ul><li>A keyword level between feature and scenario.</li><li>It can be used to group certain scenarios having the same rule.</li><li>Each rule can have its own background block.</li></ul><p><strong>Note: </strong>Rule keyword is pretty new, and certain test case management tool integrations may support it. Also, Cucumber Extensions on some IDEs do not group scenarios by Rule keyword, so they can not be executed separately.</p><pre>Background:<br>  Given go to home page<br><br><br>Rule: User must be logged in<br>  Background:<br>    Given sign in with &#39;username&#39; and &#39;password&#39;<br><br>  Scenario: Logging out<br>    When click logout button on home page<br>    Then verify user is logged out on home page<br><br>Rule: User must be non-logged in<br>  Scenario: Verify non-logged in on refreshed page<br>    When go to home page<br>    Then verify user is not logged in</pre><h3>Scenario/Example</h3><ul><li>Name of the Test Case.</li><li>It contains <strong>Given, When, Then, And,</strong> and <strong>But </strong>keywords.</li></ul><h3>Given</h3><ul><li>First scenario step.</li><li>It is usually used to describe the initial context.</li></ul><h3>When</h3><ul><li>It is used to declare events or actions specific to the aforementioned scenario.</li></ul><h3>Then</h3><ul><li>This keyword is used to declare an expected result or outcome after the <em>when</em> step.</li></ul><h3>And and But</h3><ul><li>The purpose of these two keywords is to replace <strong>Given</strong>, <strong>When</strong>, or <strong>Then</strong> keywords when they are used more than once to increase readability.</li></ul><pre>Scenario: Signing in<br>  Given home page is open<br>  When click on sign in button<br>  And fill areas with &#39;username&#39; and &#39;password&#39;<br>  Then &#39;username&#39; is displayed on top right corner<br>  But sign in button shouldn&#39;t be displayed</pre><h3>* (Asterix)</h3><ul><li>All Cucumber steps can be written with * keyword.</li><li>It is best suited for listing similar steps.</li></ul><pre>Scenario: Making halva<br>  Given I am hungry<br>  * I have oil<br>  * I have flour<br>  * I have sugar<br>  When I make halva and eat it<br>  Then I am not hungry</pre><h3>Scenario Outline/Scenario Template</h3><ul><li>Name of the Test Case.</li><li>This keyword is used to run a scenario with different values consecutively. Thus, enables us to do <strong>data-driven testing</strong>.</li><li>It contains Given, When, Then, And, and But keywords.</li></ul><p><strong>Note</strong>: The placeholders are written inside of &lt;&gt; characters.</p><h3>Examples/Scenarios</h3><ul><li>This keyword is used along with Scenario Outline to specify the values to be replaced with placeholders.</li></ul><pre>Scenario Outline: Shop cart item removal<br>  Given there are  items in the cart<br>  When I remove  items from the cart<br>  Then verify  items left in the cart<br><br>  Examples:<br>    | start | remove | left |<br>    |    12 |   5    |    7 |<br>    |    20 |   5    |   15 |</pre><h3>Background</h3><ul><li>Background is used for the general steps that should be executed for every scenario.</li><li>It can be used with the Rule keyword, affecting only the scenarios nested inside that specific Rule.</li></ul><pre>Background:<br>  Given go to home page<br>  And sign in with &#39;username&#39; and &#39;password&#39;<br><br>Scenario: Logging out<br>  When click logout button on home page<br>  Then verify user is logged out on home page<br><br>Scenario: Verify login on refreshed page<br>  When go to home page<br>  Then verify user is logged in</pre><h3>Cucumber Expressions</h3><p>To understand Cucumber Expressions, we need to understand what a step definition is.</p><p>Scenario steps are high-level statements, and they actually don’t have any meaning as far as a programming language is concerned. To give them a purpose, we need to define what they do in the background. That is called the “step definition”.</p><p>IDEs like RubyMine usually create step definitions with regex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/0*TKUrVtttxEFXBqSz.gif" /></figure><p>Cucumber Expression provides us with a different way to create a step definition. Let’s compare them with each other.</p><pre>#RegEx step definition<br>And(/^create a user named &quot;([^&quot;]*)&quot;$/) do |arg|<br> pending<br>end<br><br><br>#Cucumber Expression step definition<br>And(&quot;create a user named {string}&quot;) do |arg|<br> pending<br>end</pre><p>As you can see from the example above, Cucumber Expression does not directly use a regex inside the step definition. It handles it differently.</p><h3>Parameter Types</h3><p>The text between curly braces in the example above is called <strong>parameters</strong>. There are some built-in parameters that Cucumber provides us. These are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPY9yoO5bnsDVFqspxIEbQ.png" /></figure><p>If the parameters above do not meet your needs and you want to create a custom parameter using your own regex, that is also possible.</p><p>There are four main fields to create a custom parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jGnQ_dfQIrGOfjERWmXog.png" /></figure><p>Let’s say that we want to give a person’s name in the step and create a Person object with it. Here is the ParameterType configuration and step definition:</p><pre>ParameterType(<br> name: &#39;name&#39;,<br> regexp: /&quot;([^&quot;]*)&quot;/,<br> type: Person,<br> transformer: -&gt; (arg) {Person.new(name: arg)}<br>)<br><br>And(&quot;create a user named {name}&quot;) do |person|<br> puts person<br> puts &quot;id: &quot; + person.id<br> puts &quot;name: &quot; + person.name<br> puts &quot;age: &quot; + person.age<br>end</pre><p>The person class used inside the transformer:</p><pre>class Person<br> attr_accessor :id, :name, :age<br><br> def initialize(options = {})<br>   self.id = options[:id] || &quot;unknown&quot;<br>   self.name = options[:name] || &quot;unknown&quot;<br>   self.age = options[:age] || &quot;unknown&quot;<br> end<br>end</pre><p>The feature file:</p><pre>Feature: Step definition examples<br><br> Scenario: creating step definitions<br>   And create a user named &quot;kloia&quot;</pre><p>Output of the code:</p><pre>#&lt;Person:0x000000014b5c6100&gt;<br>id: unknown<br>name: kloia<br>age: unknown</pre><p>You might realize the example given above might not be the best way to handle objects, but it is a good example to demonstrate the power of Cucumber Expressions.</p><p>You may want to refer <a href="https://github.com/cucumber/cucumber-expressions#readme">Cucumber Expression page</a> on GitHub.</p><p>As a finishing line, let me share an idiom I love</p><p>“To run with salt to anyone who says I have a cucumber.” — <em>Turkish Idiom</em></p><p><strong>Meaning</strong>: Trying to help everyone without thinking afterwards and ending up in a bad situation.</p><p>But hey, we are going to <strong>run test cases with cucumber</strong>. There is a difference! :D</p><p><em>Originally published at </em><a href="https://www.kloia.com/blog/mastering-cucumber-framework-slice-1-gherkin-keywords-and-cucumber-expression"><em>https://www.kloia.com</em></a><em> on January 12, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72ae660a8936" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/slice-1-gherkin-keywords-and-cucumber-expression-72ae660a8936">Slice 1: Gherkin Keywords and Cucumber Expression</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>