Automated testing with reCaptcha 3

1,752 views
Skip to first unread message

Cristhiam Gabriel Fernández

unread,
Jun 7, 2019, 2:13:01 PM6/7/19
to reCAPTCHA
Hi everyone
I am using reCaptcha 3 in a simple web application (Django Python). I'm trying write a test case for my captcha validation method, but I don't know how to get a token for testing purposes.
Documentation says "For reCAPTCHA v3, create a separate key for testing environments. Scores may not be accurate as reCAPTCHA v3 relies on seeing real traffic." but how??

Cristhiam Gabriel Fernández

unread,
Jun 12, 2019, 5:39:07 PM6/12/19
to reCAPTCHA
OP here,
the only way I found was to use Selenium. 
Here my example

class ReCaptchaTest(StaticLiveServerTestCase):
 
@classmethod
 
def setUpClass(cls):
 
super().setUpClass()
 cls
.selenium = WebDriver()
 cls
.selenium.implicitly_wait(10)

 
@classmethod
 
def tearDownClass(cls):
 cls
.selenium.quit()
 
super().tearDownClass()

 
def test_verify_captcha(self):
 
self.selenium.get('%s%s' % (self.live_server_url, 'VIEW_URL_TO_TEST'))
 recaptcha_input
= self.selenium.find_element_by_name('g-recaptcha-response')
 recaptcha_token
= recaptcha_input.get_attribute('value')
 result_recaptcha_verify
= verify_captcha(recaptcha_token) # my verify method
 
self.assertTrue(result_recaptcha_verify['success'])

The recaptcha team should allow easy testing in v3.
Reply all
Reply to author
Forward
0 new messages