1

How can I send message to specific Slack channel through Selenium script

Working on slack notification from last few days. I'm trying to receive a message on slack which I have entered in my selenium java script.

Story: Whenever a script runs then at particular line I have a text (Hey! Server is down.) which I want to receive it in one of the slack channel.

Please let me know how can I do it.

Thank you!


Editing and adding an update. Also here is next level question
Above problem is solved and from local its working as I installed lombok!! But will it work if my script is running on BrowserStack through Jenkins at certain interval of time?

Please let me know. Thank You!

Dhanesh
  • 63
  • 1
  • 13

1 Answers1

1

You can send a slack notification from java program by creating a web hook. Take a look at the below link.

https://www.woolha.com/tutorials/java-sending-message-to-slack-webhook

Updating the answer with for lombok query

Lombok is only involved in the compilation phase. Refer

So if your project properly compiles without any error then it will run everywhere. You just need to have Lombok jar file on class path / maven dependency added.

Justin Mathew
  • 950
  • 8
  • 34
  • I went through it and did the same but now in Example.java at line SlackMessage slackMessage = SlackMessage.builder() its throwing an error for builder() – Dhanesh Apr 08 '21 at 11:28
  • They are using lombok that's why you are getting error for builder(), You can either include lombok in your project and configure it in the eclipse, Or You can remove them and add constructors , getters and setters manually . Refer https://projectlombok.org/features/all for installing lombok – Justin Mathew Apr 08 '21 at 12:02
  • Ok I will check with getter and setter. Thanks! – Dhanesh Apr 08 '21 at 12:40
  • 1
    In the other class SlackMessage I can see "@Getter" "@Setter" and "@Builder" is used – Dhanesh Apr 08 '21 at 12:43
  • 1
    A quick question: From local its working as I installed lombok!! But will it work if my script is running on BrowserStack through Jenkins at certain interval of time? – Dhanesh Apr 08 '21 at 14:21
  • Yes it will work as long as you include the lombok maven dependency/lombok jar file in the project's class path. If you face any issues instead of @Getter/@Setter you can write Getter and Setter method in the classes, and instead of builder you can write a constructor, which will essentially do the same thing. You can accept my answer if it helps you. Thanks ! – Justin Mathew Apr 08 '21 at 15:49
  • Unfortunately, through Jenkins its not running. I have asked new question here https://stackoverflow.com/questions/67022445/ci-jenkins-git-simple-java-project-want-to-send-message-on-slack-thought-sele – Dhanesh Apr 09 '21 at 14:12
  • 1
    Hi Dhanesh i updated to answer your query on Lombok. Thanks – Justin Mathew Apr 15 '21 at 19:48