Site icon Vinsguru

JMeter / Selenium WebDriver – How To Trigger Automated Test Execution From Slack

Overview:

We use Slack in our organization. You might also be using Slack for communicating information among the team members in your org. Slack is a great tool and it keeps everyone up to date and reduces unnecessary emails. Particularly automated status, build notifications etc which might flood your inbox. I have already shared an article on posting automated test results in Slack on a specific channel here.

Lets see how we could trigger an automated test suite execution in your Jenkins/CI tool.

Jenkins/CI:

The very first assumption is you have been using some CI tool like Jenkins. I also assume that the tool exposes some kind of API to trigger/schedule a build/job. Here I use Jenkins. You can get the high level idea and implement something similar if you use other tools.

The second assumption is you have a job in Jenkins configured properly which runs just fine when you trigger it manually.

Creating New User:

Lets start with creating a new user in Jenkins for slack to use. Make a note of the API token.

The assumption is this slack user has enough access to trigger the job.

Execute the below CURL command to verify if the user is able to invoke the job.

This is the format of the url. Replace the content within [ ] with appropriate information

curl -X POST http://[user:token]@[jenkins-host-with-port]/job/[job-name]/build

In my case, I tried as shown here.

curl -X POST http://slack:c1c54d626f6a11fbc98ed795ec8862bc@10.11.12.13:8080/job/TEST_ATOMATION_GURU_SLACK_JOB_DEMO/build

Slack – Slash Command:

To invoke the above Jenkins job, we would be using Slack’s slash commands. So whenever you type something after a slash – for ex: ‘/weather‘ – Slack will treat it as a command and can respond to the command. So, for that example, Slack can be configured to provide a weather report for your city.

curl -X POST http://[username:token]@[jenkins-host-with-port]/job/[job-name]/buildWithParameters
curl -X POST http://[username:token]@[jenkins-host-with-port]/job/[job-name]/buildWithParameters?ENVIRONMENT=PROD

Note:

Summary:

Slack commands are very useful and come in handy to get information or to trigger something which you might do frequently. By doing this, any non-technical user in the team could make you use of your automated test scripts by directly calling the slash command.

Happy Testing & Subscribe 🙂

 

Share This:

Exit mobile version