Using Selenium to Roll Out Changes to Gihub Settings

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.

Setup

  1. Install Selenium IDE. (Firefox, Chrome)
  2. If on Firefox, you need to disable security.csp.enable. To do that:
    1. In the URI bar, type “about:config”.
    2. Accept the risk and go on.
    3. Type “security.csp.enable” in the search bar.
    4. Toggle the option “security.csp.enable” to false. (It is important to turn it back on at the end, so don’t forget!)

Recording

  1. Reach one on the pages where you want to perform the repetitive task.
  2. Start Selenium. (From the browser add-on icon or from the menus.)
  3. Select “Create a new project.”
  4. Give it a name.
  5. Top right, click the “Record” icon.
  6. Enter a base URL. So something along “https://github.com” is enough. It has to be shorter than your target destination.
  7. 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.
  8. Perform the repetitive task.
  9. On the Selenium window, top right corner, click “stop.”

Playing Back

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.

Re-enabling CSP

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.

Closing Words

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.