Workaround for captcha being hidden.

Updated to a few new changes
This commit is contained in:
Tom Price
2015-05-31 23:43:11 +01:00
parent 463f421fd2
commit e3a4244674

View File

@@ -17,9 +17,9 @@ class UserRegistrationTest(LiveServerTestCase):
def test_registration(self): def test_registration(self):
# Navigate to the registration page # Navigate to the registration page
self.browser.get(self.live_server_url + '/user/register/') self.browser.get(self.live_server_url + '/user/register/')
self.browser.implicitly_wait(3) #self.browser.implicitly_wait(3)
title_text = self.browser.find_element_by_tag_name('h3').text title_text = self.browser.find_element_by_tag_name('h3').text
self.assertIn("User Registration", tilte_text) self.assertIn("User Registration", title_text)
# Check the form invites correctly # Check the form invites correctly
username = self.browser.find_element_by_id('id_username') username = self.browser.find_element_by_id('id_username')
@@ -31,7 +31,7 @@ class UserRegistrationTest(LiveServerTestCase):
self.assertEqual(password1.get_attribute('placeholder'), 'Password') self.assertEqual(password1.get_attribute('placeholder'), 'Password')
self.assertEqual(password1.get_attribute('type'), 'password') self.assertEqual(password1.get_attribute('type'), 'password')
password2 = self.browser.find_element_by_id('id_password2') password2 = self.browser.find_element_by_id('id_password2')
self.assertEqual(password2.get_attribute('placeholder'), 'Password (again)') self.assertEqual(password2.get_attribute('placeholder'), 'Password confirmation')
self.assertEqual(password2.get_attribute('type'), 'password') self.assertEqual(password2.get_attribute('type'), 'password')
first_name = self.browser.find_element_by_id('id_first_name') first_name = self.browser.find_element_by_id('id_first_name')
self.assertEqual(first_name.get_attribute('placeholder'), 'First name') self.assertEqual(first_name.get_attribute('placeholder'), 'First name')
@@ -41,7 +41,6 @@ class UserRegistrationTest(LiveServerTestCase):
self.assertEqual(initials.get_attribute('placeholder'), 'Initials') self.assertEqual(initials.get_attribute('placeholder'), 'Initials')
phone = self.browser.find_element_by_id('id_phone') phone = self.browser.find_element_by_id('id_phone')
self.assertEqual(phone.get_attribute('placeholder'), 'Phone') self.assertEqual(phone.get_attribute('placeholder'), 'Phone')
captcha = self.browser.find_element_by_id('g-recaptcha-response')
# Fill the form out incorrectly # Fill the form out incorrectly
username.send_keys('TestUsername') username.send_keys('TestUsername')
@@ -52,7 +51,7 @@ class UserRegistrationTest(LiveServerTestCase):
last_name.send_keys('Smith') last_name.send_keys('Smith')
initials.send_keys('JS') initials.send_keys('JS')
phone.send_keys('0123456789') phone.send_keys('0123456789')
captcha.send_keys('PASSED') self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
# Submit incorrect form # Submit incorrect form
submit = self.browser.find_element_by_xpath("//input[@type='submit']") submit = self.browser.find_element_by_xpath("//input[@type='submit']")
@@ -60,7 +59,6 @@ class UserRegistrationTest(LiveServerTestCase):
# Restablish error fields # Restablish error fields
password1 = self.browser.find_element_by_id('id_password1') password1 = self.browser.find_element_by_id('id_password1')
password2 = self.browser.find_element_by_id('id_password2') password2 = self.browser.find_element_by_id('id_password2')
captcha = self.browser.find_element_by_id('g-recaptcha-response')
# Read what the error is # Read what the error is
alert = self.browser.find_element_by_css_selector('div.alert-danger').text alert = self.browser.find_element_by_css_selector('div.alert-danger').text
@@ -73,7 +71,7 @@ class UserRegistrationTest(LiveServerTestCase):
# Correct error # Correct error
password1.send_keys('correcthorsebatterystaple') password1.send_keys('correcthorsebatterystaple')
password2.send_keys('correcthorsebatterystaple') password2.send_keys('correcthorsebatterystaple')
captcha.send_keys('PASSED') self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
# Submit again # Submit again
password2.send_keys(Keys.ENTER) password2.send_keys(Keys.ENTER)
@@ -86,7 +84,7 @@ class UserRegistrationTest(LiveServerTestCase):
# Check Email # Check Email
self.assertEqual(len(mail.outbox), 1) self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0] email = mail.outbox[0]
self.assertIn(email.subject, 'TestUsername activation required') self.assertIn('activation required', email.subject)
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email.message) urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email.message)
self.assertEqual(len(urls), 2) self.assertEqual(len(urls), 2)
@@ -106,12 +104,11 @@ class UserRegistrationTest(LiveServerTestCase):
password = self.browser.find_element_by_id('id_password') password = self.browser.find_element_by_id('id_password')
self.assertEqual(password.get_attribute('placeholder'), 'Password') self.assertEqual(password.get_attribute('placeholder'), 'Password')
self.assertEqual(password.get_attribute('type'), 'password') self.assertEqual(password.get_attribute('type'), 'password')
captcha = self.browser.find_element_by_id('g-recaptcha-response')
username.send_keys('TestUsername') username.send_keys('TestUsername')
password.send_keys('correcthorsebatterystaple') password.send_keys('correcthorsebatterystaple')
password.send_keys(Keys.ENTER) password.send_keys(Keys.ENTER)
captcha.send_keys('PASSED') self.browser.execute_script("return jQuery('#g-recaptcha-response').val('PASSED')")
# Check we are logged in # Check we are logged in
udd = self.browser.find_element_by_id('userdropdown') udd = self.browser.find_element_by_id('userdropdown')