Created
November 20, 2012 14:07
-
-
Save cgoldberg/4118143 to your computer and use it in GitHub Desktop.
headless Selenium WebDriver tests. Python unittest launching browser inside Xvfb.
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
#!/usr/bin/env python | |
# | |
# Corey Goldberg - 2012 | |
# | |
# requires: | |
# * Xvfb | |
# * X Windows | |
# * xvfbwrapper (pip install xvfbwrapper) | |
# | |
from selenium import webdriver | |
from xvfbwrapper import Xvfb | |
import unittest | |
class TestHomepages(unittest.TestCase): | |
def setUp(self): | |
self.vdisplay = Xvfb(width=1280, height=720) | |
self.vdisplay.start() | |
self.browser = webdriver.Firefox() | |
def testUbuntuHomepage(self): | |
self.browser.get('http://www.ubuntu.com') | |
self.assertIn('Ubuntu', self.browser.title) | |
def testGoogleHomepage(self): | |
self.browser.get('http://www.google.com') | |
self.assertIn('Google', self.browser.title) | |
def tearDown(self): | |
self.browser.quit() | |
self.vdisplay.stop() | |
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