1👍
You can reproduce all the steps needed for user registration and activation. Accessing registration page, sending filled form, checking emails with activation code etc. With this approach (which is much more reliable in comparison to your current code) you can get the confirmation code in the same way as real user gets it (for example, from profile activation email).
Source:stackexchange.com