Your company is rolling out a new policy and need you to change settings across many repositories? That sounds like a very repetitive task that can be easily automated. I just did it with Selenium. Here is the recipe.
- Install Selenium IDE. (Firefox, Chrome)
- If on Firefox, you need to disable security.csp.enable. To do that:
- In the URI bar, type “about:config”.
- Accept the risk and go on.
- Type “security.csp.enable” in the search bar.
- Toggle the option “security.csp.enable” to false. (It is important to turn it back on at the end, so don’t forget!)
- Reach one on the pages where you want to perform the repetitive task.
- Start Selenium. (From the browser add-on icon or from the menus.)
- Select “Create a new project.”
- Give it a name.
- Top right, click the “Record” icon.
- Enter a base URL. So something along “https://github.com” is enough. It has to be shorter than your target destination.
- In the new browser window, enter the full URL of the target destination. Eg.: If we stick to the github example, it could be /FinchPowers/dotFiles/settings.
- Perform the repetitive task.
- On the Selenium window, top right corner, click “stop.”
The Selenium window now contains all the steps you have recorded. The very first one should be an “open” command associated with the specific URL you entered at step 7. So now, all you have to do, is updating that step with a different “target.” Still sticking to the github example, it could be
/elementai/opset/settings. It has to be the same page but under a different context (in the example it’s the settings page) or else it won’t find the buttons on which you clicked when you recorded.
So now, all you have to do is click “play” and enjoy the show.
If everything works, all the steps will become green. Then you just need to update the open step to a new URL and do it again.
If it fails, a step will become red. You can click on the “Log” pane at the bottom of the Selenium window to see what went wrong. If the pages are slow to load, you may need to manually add some “wait for element visible” commands, which, of course, makes it harder. Note that in my github example I did not have to do it.
If you have a CSP error, go back to the setup part, you likely forgot to disable this check for your browser.
Hey hey! Were you happily leaving without re-enabling the CSP security feature? Not so fast! I do not want you to leave this tutorial with a less secure browser. So, go back to the setup phase, find the CSP setting and turn it back on.
All in all, this worked very well for me. Of course, for this to start to be worth it, you need a fair number of repetitions. In my case, I had to add a web hook to ten repositories, so I think it was worth it. Also, watching the hook being added automatically was also rewarding.
Now, I think Selenium supports for loops so next time I may try to enter all of my target URL in a loop and watch it all happen at once rather than have to edit/play once per repository. See, there is still room for improvements.