<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Benson Michael</title>
    <description>The latest articles on Forem by Benson Michael (@bensonmichael92).</description>
    <link>https://forem.com/bensonmichael92</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F163465%2F6bda82a5-d170-44f7-94e6-08eede4d65f1.jpg</url>
      <title>Forem: Benson Michael</title>
      <link>https://forem.com/bensonmichael92</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bensonmichael92"/>
    <language>en</language>
    <item>
      <title>Load Testing using K6 in AWS and Terraform</title>
      <dc:creator>Benson Michael</dc:creator>
      <pubDate>Fri, 14 Jul 2023 03:21:40 +0000</pubDate>
      <link>https://forem.com/bensonmichael92/load-testing-using-k6-in-aws-and-terraform-2gki</link>
      <guid>https://forem.com/bensonmichael92/load-testing-using-k6-in-aws-and-terraform-2gki</guid>
      <description>&lt;h2&gt;
  
  
  Summary:
&lt;/h2&gt;

&lt;p&gt;This article talks about how you can deploy your K6 tests in AWS using Terraform and execute them from Gitlab pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;K6 load testing framework.&lt;/li&gt;
&lt;li&gt;Grafana.&lt;/li&gt;
&lt;li&gt;InfluxDB.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Steps:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Build an EC2 instance to run k6 using the following code:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;provider "aws" {
  region  = "us-west-2"
  version = "~&amp;gt; 2.8"
}

data "template_file" "user_data" {
  template = file("${path.module}/_templates/k6_data.sh")
}

# The EC2 instance
resource "aws_instance" "k6_instance" {

  ami           = var.ami
  instance_type = var.instance_type
  key_name      = var.key_pair
  user_data     = data.template_file.user_data.rendered
  vpc_security_group_ids = ["${aws_security_group.default.id}"]
  subnet_id = var.key_pair

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

&lt;/div&gt;



&lt;p&gt;In the parent folder create a file named k6_data.sh under templates folder and add the script to install k6. This will run after the instance is started.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://bintray.com/loadimpact/rpm/rpm -O bintray-loadimpact-rpm.repo
sudo mv bintray-loadimpact-rpm.repo /etc/yum.repos.d/
sudo yum install -y k6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the similar way we need to create instances for Grafana and influx DB to run and add user data configs which will be initiated once the EC2 instances are up.&lt;/p&gt;

&lt;p&gt;For Grafana:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://dl.grafana.com/oss/release/grafana-7.1.0-1.x86_64.rpm
sudo yum install -y grafana-7.1.0-1.x86_64.rpm
sudo service grafana-server start
sudo /sbin/chkconfig --add grafana-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Influx DB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.6.x86_64.rpm
sudo yum localinstall -y influxdb-1.7.6.x86_64.rpm
sudo systemctl enable influxdb.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Influx DB after installing the service we need to create data directories, Users and a database.&lt;/p&gt;

&lt;p&gt;This should be done after starting the service using systemctl&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;influx -execute "create user admin with password 'mongoose123' with all privileges"
influx -execute "create user itguy with password 'itguy123' "
influx -execute "create database k6LoadTestDB"
influx -execute "grant ALL on k6LoadTestDB to grafana"

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

&lt;/div&gt;



&lt;p&gt;In order for Grafana to run generate reports from the data in Influx DB during test execution we need to configure Grafana to listen to the port in the Load Balancer. &lt;/p&gt;

&lt;p&gt;Hope this article helps !!!!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>aws</category>
      <category>grafana</category>
      <category>k6</category>
    </item>
    <item>
      <title>Mobile App Automation with AWS Device Farm, Gitlab and Appium</title>
      <dc:creator>Benson Michael</dc:creator>
      <pubDate>Tue, 04 Jul 2023 03:38:01 +0000</pubDate>
      <link>https://forem.com/bensonmichael92/mobile-app-automation-with-aws-device-farm-gitlab-and-appium-1g51</link>
      <guid>https://forem.com/bensonmichael92/mobile-app-automation-with-aws-device-farm-gitlab-and-appium-1g51</guid>
      <description>&lt;p&gt;Summary:&lt;br&gt;
This post talks about how you can deploy and run your Appium Automation code into AWS Device Farm from Gitlab and your Release Platform eg. Visual Studio App Center. &lt;/p&gt;

&lt;p&gt;WorkFlow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Developer merges code to Gitlab Repo.&lt;/li&gt;
&lt;li&gt;Repo will trigger Webhook to Release Platform to download code and build app for multiple platforms. (Android / iOS)&lt;/li&gt;
&lt;li&gt;Once App file (.apk or .ipa) file is built Release Platform will send a Webhook notification to Gitlab to trigger Automation pipeline.&lt;/li&gt;
&lt;li&gt;This pipeline will have 3 jobs: 

&lt;ul&gt;
&lt;li&gt;Download and upload the installable build files (.apk or .ipa) to AWS Device farm.&lt;/li&gt;
&lt;li&gt;Upload Latest Test Scripts to AWS Device Farm.&lt;/li&gt;
&lt;li&gt;Execute Automation Run in Android and iOS, download test reports.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;h2&gt;
  
  
  Stages
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Setup Webhook in Release Platform to trigger Pipeline on Successful App Build.&lt;/li&gt;
&lt;li&gt;Setup Job in Pipeline to download generated build and upload to AWS Device Farm.&lt;/li&gt;
&lt;li&gt;Setup Job in pipeline to upload latest version of Appium test scripts to AWS Device Farm.&lt;/li&gt;
&lt;li&gt;Trigger Automation Run in AWS Device Farm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setup Webhook in Release Platform.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a trigger token in from your Gitlab account&lt;br&gt;
&lt;a href="https://docs.gitlab.com/ee/ci/triggers/" rel="noopener noreferrer"&gt;https://docs.gitlab.com/ee/ci/triggers/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Construct the Webhook URL&lt;br&gt;
&lt;code&gt;https://gitlab.example.com/api/v4/projects/&amp;lt;project_id&amp;gt;/ref/&amp;lt;ref_name&amp;gt;/trigger/pipeline?token=&amp;lt;token&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In App Center if you go to Settings -&amp;gt; Webhooks, you can create your webhook with the above generated Gitlab pipeline trigger URL.&lt;br&gt;
&lt;code&gt;https://appcenter.ms/orgs/&amp;lt;your organization&amp;gt;/apps/&amp;lt;your app&amp;gt;/settings/webhooks/create&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure when the webhook should be triggered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure webhooks for Android and iOS apps separately so that it does not conflict with each other.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Upload latest build to AWS Device Farm
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a Automation Test Project from AWS console in the Device Farm Service. Note down the Project ARN, Test Spec ARN etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While setting up make sure the Test spec is as per your requirements. Make edits if needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the Pipeline is trigger is configured, create a Gitlab Job, that executes a bash script.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the bash script, use App Center API via curl to get the  the buildID for the latest build generated.&lt;br&gt;
&lt;code&gt;$(curl -X GET "https://api.appcenter.ms/v0.1/apps/&amp;lt;your-organization&amp;gt;/&amp;lt;APP_NAME&amp;gt;/branches/develop/builds" -H  "accept: application/json" -H  "X-API-Token: &amp;lt;APIToken&amp;gt;")&lt;/code&gt;&lt;br&gt;
Here APIToken is App Center API Token. You can add this to Gitlab Environment Variables and consume it in the pipeline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the buildID is fetched you can download the build using&lt;br&gt;
&lt;code&gt;$(curl -X GET "https://api.appcenter.ms/v0.1/apps/&amp;lt;your-organization&amp;gt;/&amp;lt;APP_NAME&amp;gt;/builds/&amp;lt;build_id&amp;gt;/downloads/build" -H  "accept: application/json" -H  "X-API-Token: &amp;lt;APIToken&amp;gt;")&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After downloading, you can use the aws cli command to upload it to the AWS Device farm.&lt;br&gt;
&lt;code&gt;aws devicefarm create-upload --project-arn &amp;lt;device-farm-arn&amp;gt; --name &amp;lt;build-file-name&amp;gt; --type &amp;lt;extension&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Upload Test Scripts to Appium.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a job in Gitlab pipeline that executes a bash script.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the bash script, navigate to the test folder and using npm-bundle plugin generate a zip file off the tests folder.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g npm-bundle
npm i
npm-bundle
zip -r appium-test.zip *.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Once the zip file is generated use aws cli command to upload it to the device farm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;aws devicefarm create-upload --project-arn &amp;lt;device-farm-arn&amp;gt; --name "appium-test.zip" --type APPIUM_NODE_TEST_PACKAGE&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Trigger Automation Run in AWS Device Farm
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Once both the latest build (.apk or .ipa) file is successfully upload to the device farm. Create a python script with reference to this document.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/api-ref.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You might have to pass the Device Farm Project ARN, Test Spec ARN, Device Pool ARN , App Name and Test Package Name as arguments to the python script. These ARN values are obtained from Device Farm Dashboard in AWS Console.&lt;br&gt;
Under Device Farm -&amp;gt; Mobile Device: Projects -&amp;gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When this script is executed, it will trigger the automation run and once done, the report will be saved in Gitlab artifacts.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example screenshot:&lt;/p&gt;

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

&lt;p&gt;Hope this document helps it setting up Mobile Automation in AWS Device Farm from Gitlab. Let me know if you have any questions in the comments.  &lt;/p&gt;

</description>
      <category>automation</category>
      <category>aws</category>
      <category>mobile</category>
      <category>gitlab</category>
    </item>
  </channel>
</rss>
