Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created April 7, 2013 17:17
Show Gist options
  • Save EdwardIII/5331385 to your computer and use it in GitHub Desktop.
Save EdwardIII/5331385 to your computer and use it in GitHub Desktop.
class SeleniumTestCase(LiveServerTestCase):
"""
A base test case for Selenium, providing hepler methods for generating
clients and logging in profiles.
"""
def open(self, url):
self.wd.get("%s%s" % (self.live_server_url, url))
class FinderTest(SeleniumTestCase):
@classmethod
def setUpClass(cls):
cls.selenium = webdriver.Firefox()
#profile = webdriver.FirefoxProfile('/home/edward/.mozilla/firefox/2rl7im2z.default/')
#cls.selenium = webdriver.Firefox(profile)
cls.selenium.implicitly_wait(3)
cls.user = User.objects.create_user(
username = 'difficult-hipster',
password = hashlib.md5('i-dont-like-radiohead').hexdigest(),
)
cls.category = Category.objects.create(name='Sheffield University')
cls.organiser = Organiser.objects.create(name='ArchiSoc', category=cls.category, user=cls.user, top_organiser=True)
cls.event = Event.objects.create(
name='Bakewell Walk',
start_date = datetime.date(2014, 11, 30),
organiser = cls.organiser
)
cls.tickets = [
Ticket.objects.create(name="Early Bird", quantity=10, price=9.50, event=cls.event),
Ticket.objects.create(name="Standard", quantity=50, price=11.50, event=cls.event),
]
cls.buyer = Buyer.objects.create(name='Andrew WK', email='[email protected]')
super(FinderTest, cls).setUpClass()
@classmethod
def wait_for(cls, css_selector):
return WebDriverWait(cls.selenium, 10).until(
expected_conditions.presence_of_element_located(
cls.selenium.find_element_by_css_selector(css_selector)
)
)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(FinderTest, cls).tearDownClass()
def test_order_process(self):
self.selenium.get('%s%s' % (self.live_server_url, '/'))
self.selenium.find_element_by_css_selector('#category li:first-child').click()
self.selenium.find_element_by_css_selector('#organiser li:first-child').click()
self.selenium.find_element_by_css_selector('#event li:first-child').click()
buy_now_button = self.wait_for('#event .buy-now')
self.selenium.find_element_by_css_selector('#event .buy-now').click()
#self.selenium.find_element_by_css_selector('#event .buy-now').click()
self.selenium.find_element_by_css_selector('.ticket-qty').send_keys(2)
next_button = self.wait_for('.modal-footer button')
next_button.click()
#name_field = WebDriverWait(self.selenium, 10).until(
# expected_conditions.presence_of_element_located(
# self.selenium.find_element_by_name('person-name')
# )
#)
#name_field.send_keys('David Bowie')
#self.selenium.find_element_by_name('person-email').send_keys('[email protected]')
@EdwardIII
Copy link
Author

]$ ./manage.py test app
Creating test database for alias 'default'...
/home/edward/python/lib/python2.7/site-packages/mptt/admin.py:180: DeprecationWarning: Accessing the item and tree editor through `feincms.admin.editor` has been deprecated. Please use `feincms.admin.item_editor` and `feincms.admin.tree_editor` instead. `feincms.admin.editor` will be removed in FeinCMS v1.8.
  from feincms.admin import editor

/usr/lib/python2.7/site-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
  DeprecationWarning)

/usr/lib/python2.7/site-packages/django/utils/copycompat.py:10: DeprecationWarning: django.utils.copycompat is deprecated; use the native copy module instead
  DeprecationWarning)

WARNING:py.warnings:/usr/lib/python2.7/site-packages/django/utils/copycompat.py:10: DeprecationWarning: django.utils.copycompat is deprecated; use the native copy module instead
  DeprecationWarning)

.E
======================================================================
ERROR: test_order_process (app.tests.FinderTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/edward/Projects/MyProject/app/tests.py", line 145, in test_order_process
    buy_now_button = self.wait_for('#event .buy-now')
  File "/home/edward/Projects/MyProject/app/tests.py", line 128, in wait_for
    cls.selenium.find_element_by_css_selector(css_selector)
  File "/home/edward/python/lib/python2.7/site-packages/selenium/webdriver/support/wait.py", line 63, in until
    value = method(self._driver)
  File "/home/edward/python/lib/python2.7/site-packages/selenium/webdriver/support/expected_conditions.py", line 58, in __call__
    return _find_element(driver, self.locator)
  File "/home/edward/python/lib/python2.7/site-packages/selenium/webdriver/support/expected_conditions.py", line 271, in _find_element
    return driver.find_element(*by)
TypeError: find_element() argument after * must be a sequence, not WebElement

----------------------------------------------------------------------
Ran 2 tests in 5.456s

FAILED (errors=1)
Destroying test database for alias 'default'...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment