Skip to content

Instantly share code, notes, and snippets.

@higs4281
Created April 15, 2015 15:22
Show Gist options
  • Save higs4281/0e025f3f3e04703f955c to your computer and use it in GitHub Desktop.
Save higs4281/0e025f3f3e04703f955c to your computer and use it in GitHub Desktop.
selenium test to check all possibilities in hmda explorer charts
"""
this tests a local instance of hmda explorer running at localhost:8000"
"""
import re
import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
# url = 'http://www.consumerfinance.gov/hmda/'
url = 'http://localhost:8000/'
driver.get(url)
def slugify(value):
"""
borrowed from django
"""
value = re.sub('[^\w\s-]', '', value).strip().lower()
return re.sub('[-\s]+', '-', value)
def check_match(num, chartnum):
"""
checks a selection choice against what shows up in the related chart
there were 393 metro choices in 2013 data (loaded in 2014)
"""
inputbox = driver.find_element_by_id('hmda_chart_%s_msa_chzn' % chartnum).find_element_by_tag_name('a')
inputbox.click()
choice = driver.find_element_by_id('hmda_chart_%s_msa_chzn_o_%s' % (chartnum, num))
clean1 = slugify(choice.text)[:20]
choice.click()
if chartnum == 1:
result = driver.find_element_by_id("highcharts-0").find_element_by_tag_name("svg").find_element_by_tag_name("tspan")
else:
result = driver.find_element_by_id("highcharts-%s" % chartnum).find_element_by_tag_name("svg").find_element_by_tag_name("tspan")
clean2 = slugify(result.text)[:20]
if clean1 == clean2:
print "passed for %s" % clean1
else:
print "FAIL for %s/%s" % (clean1, clean2)
def run(rangenum):#393 for full test of metro areas
starter = datetime.datetime.now()
for num in range(rangenum):
check_match(num, 1)
check_match(num, 2)
print "script took %s" % (datetime.datetime.now()-starter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment