I need to automate interaction with a website that is initially protected with ReCaptcha. Can I initially manually log in to the website and solve 2FA, then hand-over the existing manually initiated session to the testing application to automatically run through the website tests with my manually authenticated session?
I think it should be the other way around, letting the test hand it over to a manual users for a while:
- Start the Selenium test to open browser and goto CAPTCHA page
- Write a wait that waits for an element that would be shown after the CAPTCHA is completed. (Make sure this wait has a large timeout, maybe also enlarge the default timeouts. Be sure to reset default timeouts after your wait, if you change implicit wait your tests could wait for minutes when something is broken.)
- Fill in the CAPTCHA manually
- The test will see the element found and continue the test instantly, as it will poll for the element every 500ms by default.
Aslong the test is waiting for something you can just use the browser as normal.
- Working with timeouts: http://toolsqa.com/selenium-webdriver/wait-commands/ (Guess the fluent-wait example is good to change from 30 seconds to 15 minutes, making sure you have the time to finish the CAPTCHA)
- Official documentation on timeouts: http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Firstly, this is maybe be a smell that your application is not built with a testability mindset.
In the Automation environment:
1 - This feature should be removed;
2 - The user should be automatically log by sending a token generated uniquely by the application, identifying therefore the user.
There are ways of working around the issue, but this way you would still have an application difficult to test and probably your tests would take longer to run.
Attack the disease, not the symptoms.