Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Created January 7, 2013 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgoldberg/4477053 to your computer and use it in GitHub Desktop.
Save cgoldberg/4477053 to your computer and use it in GitHub Desktop.
Python unit test using PhantomJS and Selenium WebDriver. Headless web acceptance testing.
#!/usr/bin/env python
"""Python unit test using PhantomJS and Selenium WebDriver."""
# requires: selenium python bindings, phantomjs 1.8+
#
# if you have phantomjs installed and on your PATH,
# you can instantiate a PhantomJS WebDriver like this:
#
# from selenium import webdriver
# driver = webdriver.PhantomJS()
# # do webdriver stuff here
# driver.quit()
#
# for the example below, `phantomjs` binary is located
# in same directory as test script.
import unittest
from selenium import webdriver
class TestUbuntuHomepage(unittest.TestCase):
def setUp(self):
self.driver = webdriver.PhantomJS('./phantomjs')
def testTitle(self):
self.driver.get('http://www.ubuntu.com/')
self.assertIn('Ubuntu', self.driver.title)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main(verbosity=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment