Created
January 7, 2013 18:06
-
-
Save cgoldberg/4477053 to your computer and use it in GitHub Desktop.
Python unit test using PhantomJS and Selenium WebDriver. Headless web acceptance testing.
This file contains hidden or 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
#!/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