Getting Started with Artillery
Tags: tutorial, performance, testing, javascript
Published: 2022-07-28 14:15:38

<!-- wp:paragraph -->
<p>There are over <a href="https://github.com/QAInsights/Performance-Testing-Tools" target="_blank" rel="noreferrer noopener">50+ performance testing tools</a> available in the market. It is not possible to learn all the tools, but instead, learning the general performance concepts helps you to master any tool irrespective of programming language. I usually cherry-pick when I write blog or create <a href="https://youtube.com/qainsights" target="_blank" rel="noreferrer noopener">video tutorials</a>. In this blog article, we are going to see about Artillery.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"4d440fd8"} -->
<h2 class="gb-headline gb-headline-4d440fd8 gb-headline-text">Artillery</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p><a href="https://github.com/artilleryio/artillery" target="_blank" rel="noreferrer noopener">Artillery</a> is a modern open-source performance testing tool for performance test engineers, DevOps, SREs, and more.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It is built on top of JavaScript, and we can declare the tests in yaml format.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Following are the Artillery features which I picked from their repo:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Supports various protocols</li><li>Cloud-native and highly scalable</li><li>Supports correlation, data parameterization, transactions, conditional logic, quick load testing and more</li><li>Supports synthetic and functional tests</li><li>O11Y and CI/CD integrations</li><li>and more</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Artillery comes with two flavors: Artillery Core and Artillery Pro. Artillery Pro is a premium offering with cloud features.  </p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"80a7087b"} -->
<h2 class="gb-headline gb-headline-80a7087b gb-headline-text">Installing Artillery</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>You can leverage npm to install the Artillery library using either of the below commands.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>npm install -g artillery@latest</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p> To validate, enter the below command:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery version</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9600,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/07/image-20.png"><img src="https://qainsights.com/wp-content/uploads/2022/07/image-20.png" alt="Getting Started with Artillery" class="wp-image-9600"/></a><figcaption>Getting Started with Artillery</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"f37da0fe"} -->
<h2 class="gb-headline gb-headline-f37da0fe gb-headline-text">Hello Dino</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>To verify the artillery installation, enter the below command, which will display a Dino in rainbow colors.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery dino -m "QAInsights" -r</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9601,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/07/image-21.png"><img src="https://qainsights.com/wp-content/uploads/2022/07/image-21.png" alt="Artillery Dino" class="wp-image-9601"/></a><figcaption>Artillery Dino</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"7bbe5128"} -->
<h2 class="gb-headline gb-headline-7bbe5128 gb-headline-text">Hello Quick Load Testing</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Let us run a quick load test without writing any tests in yaml. Enter the below command which will execute 10 virtual users each sending 10 requests, and stores the performance stats in the JSON file.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery quick --count 10 --num 10 --output quicktest.json http://localhost:9966/petclinic/api/pets</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9605,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/07/image-23.png"><img src="https://qainsights.com/wp-content/uploads/2022/07/image-23-1024x594.png" alt="Artillery Quick Test" class="wp-image-9605"/></a><figcaption>Artillery Quick Test</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"ab01ba72"} -->
<h2 class="gb-headline gb-headline-ab01ba72 gb-headline-text">Hello Web Service</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Now it is time to write our simple test in YAML format.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below is the simple hello world test in Artillery. Copy and paste into <code>hello-web-service.yml </code>file.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>config:
  target: http://localhost:9966/petclinic/api

scenarios:
- name: petclinic
  flow:
  - get:
      url: /pets
  - get:
      url: /pettypes</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The inception JSON object is <code>config</code> which defines the <code>target</code> app. We create <code>scenarios</code> to define our flow. Each scenario has a <code>name</code> and <code>flow</code>. <code>flow</code> can be an array where we can define our steps sequentially as shown above.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Feel free to edit the target to a valid URL and execute the below command to start a smoke test.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery run hello-web-service.yml</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The above command will execute the yaml with 1 virtual user for 1 second duration. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The stats will be displayed in the terminal by default.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"46328d59"} -->
<h2 class="gb-headline gb-headline-46328d59 gb-headline-text">Data Parameterization</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Here is a demo of how data parameterization works in Artillery.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/cHvwnviYv0c","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/cHvwnviYv0c
</div></figure>
<!-- /wp:embed -->

<!-- wp:generateblocks/headline {"uniqueId":"9cf5a79a"} -->
<h2 class="gb-headline gb-headline-9cf5a79a gb-headline-text">Correlation</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Here is a demo of how correlation works in Artillery.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/6-cx1yINi2M","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/6-cx1yINi2M
</div></figure>
<!-- /wp:embed -->

<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"backgroundColor":"global-color-8","align":"center"} -->
<div class="wp-block-button aligncenter"><a class="wp-block-button__link has-global-color-8-background-color has-background" href="https://github.com/QAInsights/Learn-Artillery-Series" target="_blank" rel="noreferrer noopener">Learn Artillery Series - GitHub Repo</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->

<!-- wp:generateblocks/headline {"uniqueId":"3d41af06"} -->
<h2 class="gb-headline gb-headline-3d41af06 gb-headline-text">HTML Report</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Artillery generates a basic HTML report from the output JSON. Generating a report involves a two-step process. First, we need to pass the <code>output</code> tag during the execution. The second step is to generate a report using the <code>report</code> command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery run hello-web-service.yml --output hello-web-service.json</code></pre>
<!-- /wp:code -->

<!-- wp:code -->
<pre class="wp-block-code"><code>artillery report hello-web-service.json</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9609,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/07/image-24.png"><img src="https://qainsights.com/wp-content/uploads/2022/07/image-24-1024x742.png" alt="HTML Report" class="wp-image-9609"/></a><figcaption>HTML Report</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"e416e7c3"} -->
<h2 class="gb-headline gb-headline-e416e7c3 gb-headline-text">Phases</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>To design the workload model, we can leverage <code>Phases</code> object in yaml. Here is a quick demo of <code>phases</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/8WZvzH8P2OA","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/8WZvzH8P2OA
</div></figure>
<!-- /wp:embed -->

<!-- wp:generateblocks/headline {"uniqueId":"c66a4f68"} -->
<h2 class="gb-headline gb-headline-c66a4f68 gb-headline-text">Final Thoughts</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>We just scratched the surface of Artillery by seeing various fundamental concepts. Artillery also supports conditional logic, custom JS code, Docker, Kubernetes, Debugging, UI mode, O11Y integrations and more. If you already know JavaScript, then you do not need to learn a new language to work with Artillery. JavaScript expertise is required only if you are writing complex scripts. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Since Artillery wraps the core concepts, most of the time you will be good with the core features. You may need to opt in to Artillery Pro if you are planning to use highly scalable and distributed load testing in your AWS infrastructure. If you are into JMeter world and maintaining the scripts for a long time, I do not see any solid reason to switch it to another framework. </p>
<!-- /wp:paragraph -->