Testing with TestProject Docker Agent
Tags: testing, webdev, devops
Published: 2020-11-28 08:05:56



> ***"Well-run tests will help you avoid serious grief in the long run"***


The above quote is of great significance as I remember my dark days of software development where I feel like I entered a dark alley without my slingshot or leather sandals.

Of course, I'm referring to proper Testing and avoiding fallacious approaches. But now we came forward from those dark days, the contemporary ***Testing*** techniques emerged and it has propelled the need for an efficient, reliable, fast, and powerful automation tool that can fit the diverse skillsets of everyone on an agile team. 

> ***Here I am introducing you to one of the newest entrant "TestProject"*** 

An open-source friendly, community-powered automation testing tools. The most amazing part is it has a ***free forever plan*** which is fully featured and that you can get started within seconds.

Personally, I have tried TestProject for my research projects.  I can strongly argue that it is of high quality and experience so far has been ***top-notch***.  So let's dig into it.

> ## :computer:How to start with TestProject

### Step 1 - ***Signup for free***
All we need to do is sign up to [Testproject](https://testproject.io/).You can check the [documentation](https://docs.testproject.io/getting-started/creating-an-account) if you need help in free signup.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5xh24o9ik06hn55j6xj6.JPG)

Once you have created an account with TestProject you just need to follow a few simple steps to get setup and ready for testing.  ***TestProject works on almost any platform, with the install of a single agent.***

### Step 2 - ***Generate an API key***
Generate an API key which allows access to API for your account. In order to do that, open the TestProject application and go to the Integration tab and select the API option.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/22owyd9r2uqijnpa76pu.JPG)
From there you can create a new API key and set the access you want it to have.Once you've setup that key you can copy it and use it in API call that you make.

> ## :whale: How to setup TestProject Docker Agent


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2qsfca3uk2q4r7ojs5md.JPG)

When it comes to the CICD team they have already get rid of the traditional testing and moved to automation. Nowadays, automated testing is embedded so deeply within our perception of software development, it's hard to imagine one without the other. And since that ultimately enables us to produce software quickly without sacrificing quality.

And Docker is the de-facto standard to build, run, test, and share containerized apps from your desktop to the cloud. So for this world ***TestProject comes with Docker Agent concept***. Moreover, the docker agent is useful because it saves a bunch of resources & provides the ability to run tests with just a simple command.

### Prerequites

- In your machine Docker should be Installed
- In this article, we are installing the agent with docker compose yaml file so Docker Compose also should be installed.

### Step 1 -***Docker-Compose for TestProject Docker Agent*** 

Visit the TestProject [dockerhub](https://hub.docker.com/r/testproject/agent) page, you can see on that page TestProject team explained all the different ways to spin the docker agent.We are using the docker-compose way. The following docker-compose snippet can be used to start a TestProject Agent with headless Chrome & Firefox browsers.

```yaml
# NOTE: Make sure to update the 'testproject-agent' container volume with a valid local path.
# To execute this docker-compose, store it in a file (e.g. testproject-agent.yaml) an run:
# docker-compose -f <file_name> up -d

version: "3.1"
services:
  testproject-agent:
    image: testproject/agent:latest
    container_name: testproject-agent
    depends_on:
      - chrome
      - firefox
    volumes:
      - .:/var/testproject/agent
    environment:
      TP_AGENT_ALIAS: "Docker Agent"
      TP_API_KEY: "REPLACE_WITH_YOUR_KEY"
      TP_JOB_PARAMS: '"jobParameters" : { "browsers": [ "chrome", "firefox" ] }'
      CHROME: "chrome:4444"
      FIREFOX: "firefox:4444"
  chrome:
    image: selenium/standalone-chrome
    volumes:
      - /dev/shm:/dev/shm
  firefox:
    image: selenium/standalone-firefox
    volumes:
      - /dev/shm:/dev/shm
```
We need to update the ***TP_API_KEY & TP_JOB_ID*** environment variables so that we instruct the Agent to automatically point to our TestProject account and run the job on startup.

In our case since we are not ready with job, so I have not mentioned the  TP_JOB_ID environment variable. I have only added the TP_API_KEY that we created.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rvs0tujj2x4fgicsh7xx.JPG)

### Step 2-***Spinning up the TestProject Docker Agent*** 

I have saved my docker compose yaml file with the name TestProject-DockerAgent.yaml.By running the below command the TestProject agent will be up and running.

```shell
docker-compose -f .\TestProject-DockerAgent.yaml up
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1596ernl763sken8auou.JPG)


Within minutes the docker agent is ready with headless Chrome & Firefox browsers. You can see in the below logs saying "Agent initialization is complete"

```
testproject-agent    | 2020-11-28 14:42:04.491 [INFO ] i.t.a.Program                            *** AGENT - START ***
testproject-agent    | 2020-11-28 14:42:04.742 [INFO ] i.t.a.a                                  TestProject Agent 0.65.10 (64dbf6a7cad45d6e980553444ef4ff002008b3f6) on Linux
testproject-agent    | 2020-11-28 14:42:04.777 [INFO ] i.t.a.a                                  Running as user /home/agent of type Unknown with non-Administrator privileges
testproject-agent    | 2020-11-28 14:42:04.780 [INFO ] i.t.a.a                                  Running inside docker 6a805a004559
testproject-agent    | 2020-11-28 14:42:04.790 [INFO ] i.t.a.a                                  No X11 available - headless mode.
testproject-agent    | 2020-11-28 14:42:04.800 [INFO ] i.t.a.s.IdentityManager                  No identity file was found - Agent is not registered
testproject-agent    | 2020-11-28 14:42:04.804 [INFO ] i.t.a.a                                  Working folder: /opt/testproject/agent
testproject-agent    | 2020-11-28 14:42:04.807 [INFO ] i.t.a.a                                  Data folder: /var/testproject/agent
testproject-agent    | 2020-11-28 14:42:04.816 [INFO ] i.t.a.a                                  Agent IP addresses: 1.1.1.1
testproject-agent    | 2020-11-28 14:42:04.823 [INFO ] i.t.a.m.H                                Checking connectivity with https://testproject.io:443 (Using proxy: No)
testproject-agent    | 2020-11-28 14:42:07.557 [INFO ] i.t.a.m.H                                Connection established successfully.
testproject-agent    | 2020-11-28 14:42:07.560 [INFO ] i.t.a.a                                  Direct connection (no proxy) to TP is possible.
testproject-agent    | 2020-11-28 14:42:08.023 [INFO ] i.t.a.a                                  Agent initialization is complete.
```
Now we can go back to our TestProject account and check the agent is showing up there. For that, we need to navigate to the Agents Tab. The new docker agent is showing on the page as shown below. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/eraftrodsirhs5a54jbl.JPG)

> ## :running: Running the Test Jobs against the Docker Agent

Under the Projects Tab, I have created a sample test project. You can follow the instruction in the [documentation](https://docs.testproject.io/using-the-smart-test-recorder/web-testing/creating-a-web-test-using-the-testproject-recorder) to set up your test.

Let's run ***My First Test*** test case against our newly created docker agent by clicking  on the play button as shown below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/unhdekmchw3dwxbs0lkb.JPG)

Once you press the play button you will receive a popup and it will ask for which agent to select , in our case we will select the ***Docker Agent***

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7yjcz1jfbxu1jwdp9f8d.JPG)

Once you press the Run button the job will run in the Docker Agent and you can see the logs below 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/now0apzt3gj1qpfyft04.JPG)
```
testproject-agent    | 2020-11-28 17:35:13.207 [INFO ] i.t.a.m.c.p                              Successfully handled report for execution KXfcPG0yzUCFyP2Sf24CpQ
testproject-agent    | 2020-11-28 17:35:13.214 [INFO ] i.t.a.m.c.p                              Uploading attachments for execution KXfcPG0yzUCFyP2Sf24CpQ
testproject-agent    | 2020-11-28 17:35:13.217 [INFO ] i.t.a.m.c.p                              Successfully handled attachments for execution KXfcPG0yzUCFyP2Sf24CpQ
testproject-agent    | 2020-11-28 17:35:13.264 [INFO ] i.t.a.m.c.p                              Successfully finished execution KXfcPG0yzUCFyP2Sf24CpQ reporting.
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/78m54a101c2l2lfo2rox.JPG)

> ## :bookmark_tabs: Checking Test Reports

***TestProject one of the premium feature that they give us for free
is the report dashboard.*** To explore Reports we need to navigate to the tab Reports, here we can see the report of our last few runs in the docker agent.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/u77sow0dutl8isp1yegp.JPG)

>## :books: Summary

***If you’re looking out for a $0 cloud-based, SaaS test automation development framework designed for your agile team, TestProject is the right choice for you.***

![Alt Text](https://media.giphy.com/media/klZBxHoFLN44M/giphy.gif)

"It is manageable, quick and reliable !!!"
 
As it is built on top of industry-standard open-source tools (Selenium & Appium), supports all major operating systems, and ensures quality with speed using advanced built-in recording capabilities, addons, reports and analytics dashboards, or develop coded tests using TestProject’s powerful SDK for Python/Java/C#!.So in this modern era TestProject suites well!!

Below are few usefull links about TestProject, ***Check it out !!***
[Official YouTube Channel](https://www.youtube.com/testproject)

***Open Source TestProject's SDK:***
[Open-source Java SDK](https://github.com/testproject-io/) | [Python SDK](https://github.com/testproject-io/python-sdk) | [TestProject SDK for Addons](https://github.com/testproject-io/addons)

[Addons library](https://addons.testproject.io/) | [Forum](https://forum.testproject.io/)