Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import importlib
- import time
- from django.core.urlresolvers import reverse
- from django.test import LiveServerTestCase
- from selenium.webdriver.firefox.webdriver import WebDriver
- from selenium.webdriver.support.wait import WebDriverWait
- from apps.shop.catalogue.models import Product
- class BaseTestCase(LiveServerTestCase):
- @classmethod
- def setUpClass(cls):
- settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
- engine = importlib.import_module('django.contrib.sessions.backends.file')
- store = engine.SessionStore()
- store.save()
- cls.session = store
- cls.driver = WebDriver()
- super(BaseTestCase, cls).setUpClass()
- @classmethod
- def tearDownClass(cls):
- super(BaseTestCase, cls).tearDownClass()
- cls.driver.quit()
- def wait_until(self, callback, timeout=10):
- """ Helper function which blocks test execution until
- specified callback returns a non falsy value.
- Can be called after clicking a link or submitting a form
- """
- WebDriverWait(self.driver, timeout).until(callback)
- def wait_loaded_tag(self, tag_name, timeout=10):
- """ Block test execution until element with given tag name is found on page """
- self.wait_until(
- lambda driver : driver.find_element_by_tag_name(tag_name),
- timeout
- )
- class CheckoutFormTestCase(BaseTestCase):
- """ Selenium test for checkout procedure """
- def test_checkout(self):
- """ Test the checkout form """
- # self.driver.get(self.live_server_url + '/cart/checkout/')
- self.driver.get('http://127.0.0.1:8001/cart/checkout/')
- print 'starting test'
- f = self.driver.find_element_by_id
- f('id_firstname').send_keys('Michail')
- f('id_lastname').send_keys('Bakunin')
- f('id_address').send_keys('Prjamuchino')
- f('id_address_extra').send_keys('Tver Province')
- f('id_post_code').send_keys('12345')
- f('id_city').send_keys('Tver')
- f('id_phone_primary').send_keys('+46123456')
- f('id_phone_secondary').send_keys('+46123456')
- # accept terms of agreement
- accept = self.driver.find_elements_by_name('accept')[0]
- accept.click()
- # submit the form
- accept.submit()
- ##f('id_submit').click()
- print "form submitted, time to sleep for a bit!"
- time.sleep(2)
- windows = self.driver.window_handles
- print 'window_handles'
- print windows
- # switch
- self.driver.switch_to_window(windows[0])
- print 'switching to window', windows[0], 'and sleeping'
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement