Created
February 29, 2012 06:27
-
-
Save calvinchengx/1938529 to your computer and use it in GitHub Desktop.
Example of how selenium is used in my unit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urlparse | |
from selenium import webdriver | |
from django.test import TestCase | |
from django.conf import settings | |
from django.core.urlresolvers import reverse | |
class BackendsTest(TestCase): | |
def setUp(self): | |
self.driver = webdriver.Firefox() | |
def tearDown(self): | |
#self.driver.quit() | |
pass | |
def url(self, backend_name): | |
SE_TEST_DOMAIN = getattr(settings, 'SE_TEST_DOMAIN', None) | |
return urlparse.urljoin(settings.SE_TEST_DOMAIN, | |
reverse('socialauth_begin', args=[backend_name])) | |
def test_facebook_backend(self): | |
SE_TEST_FACEBOOK_USER = getattr(settings, 'SE_TEST_FACEBOOK_USER', None) | |
SE_TEST_FACEBOOK_PASSWORD = getattr(settings, 'SE_TEST_FACEBOOK_PASSWORD', None) | |
self.assertTrue(SE_TEST_FACEBOOK_USER) | |
self.assertTrue(SE_TEST_FACEBOOK_PASSWORD) | |
self.driver.get(self.url('facebook')) | |
# Logging into facebook | |
username_field = self.driver.find_element_by_id('email') | |
username_field.send_keys(SE_TEST_FACEBOOK_USER) | |
password_field = self.driver.find_element_by_id('pass') | |
password_field.send_keys(SE_TEST_FACEBOOK_PASSWORD) | |
password_field.submit() | |
try: | |
self.driver.find_element_by_name('grant_clicked').click() | |
except: | |
pass | |
# We check the user logged in | |
loggedin = self.driver.find_element_by_id('loggedin') | |
if not loggedin: | |
raise Exception('The user didn\'t log in') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment