Created
January 16, 2015 19:15
-
-
Save lukecampbell/aec1218c7f444cc1f2b0 to your computer and use it in GitHub Desktop.
Integration testing with Selenium
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 | |
import requests | |
from zipfile import ZipFile | |
import os | |
import stat | |
def main(path): | |
chrome_fo_mac = 'http://chromedriver.storage.googleapis.com/2.13/chromedriver_mac32.zip' | |
print "Downloading Chrome Driver to", path | |
zip_file = download_file(chrome_fo_mac, path) | |
with ZipFile(zip_file) as zf: | |
zf.extractall(path) | |
driver_path = os.path.join(path, "chromedriver") | |
if os.path.exists(driver_path): | |
os.chmod(driver_path, 0755) | |
def download_file(url, path): | |
local_filename = url.split('/')[-1] | |
local_filename = os.path.join(path, local_filename) | |
# NOTE the stream=True parameter | |
r = requests.get(url, stream=True) | |
if r.status_code != 200: | |
raise IOError("Failed to GET URL %s because %s" % (url, r.text)) | |
with open(local_filename, 'wb') as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
f.flush() | |
return local_filename | |
if __name__ == '__main__': | |
main() |
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 | |
''' | |
test.test_selenium | |
''' | |
from unittest import TestCase | |
from selenium import webdriver | |
import os | |
class TestSelenium(TestCase): | |
def setUp(self): | |
if not os.path.exists('drivers/chromedriver'): | |
from drivers.install_drivers import main | |
main('drivers') | |
self.webdriver = webdriver.Chrome('drivers/chromedriver') | |
def tearDown(self): | |
self.webdriver.quit() | |
class TestOOI(TestSelenium): | |
def test_ooi(self): | |
self.webdriver.get('http://data.ooi.rutgers.edu/') | |
assert 'OOI' in self.webdriver.title | |
class MyTest(TestSelenium): | |
def test_yahoo(self): | |
self.webdriver.get('http://www.yahoo.com/') | |
assert 'Yahoo' in self.webdriver.title | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment