Created
April 30, 2014 12:59
-
-
Save JGrubb/fd946d0117a0d912e54a to your computer and use it in GitHub Desktop.
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
var casper, states, toTitleCase, url; | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
}; | |
toTitleCase = function(str) { | |
return str.replace(/\w\S*/g, function(txt) { | |
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | |
}); | |
}; | |
url = "http://example.com"; | |
states = ["alabama", "alaska", "arizona", "arkansas", "district of columbia", "idaho", "illinois", "indiana", "iowa", "kentucky", "louisiana", "missouri", "montana", "nebraska", "nevada", "new mexico", "north dakota", "oklahoma", "oregon", "south dakota", "tennessee", "texas", "washington", "west virginia", "wisconsin"]; | |
casper = require('casper').create(); | |
casper.start().each(states, function(self, state) { | |
return self.thenOpen("" + url + "/quotes/" + (state.replace(/\s+/g, '-')) + "_medical-malpractice-insurance", function() { | |
var descrip; | |
this.echo("Testing " + (toTitleCase(state)) + " - " + (this.getCurrentUrl())); | |
this.test.assertTitle("" + (toTitleCase(state)) + " Medical Malpractice Insurance | Capson Physicians Insurance Company", "title for " + state + " is correct"); | |
this.test.assertTextExists("Save on " + (toTitleCase(state)) + " Medical Malpractice Insurance!", "Page header is correct for " + state); | |
this.test.assertTextExists("Capson can help physicians save 20% or more on their medical malpractice insurance in " + (toTitleCase(state)) + ".", "Subhead blurb is correct for " + state); | |
this.test.assertEval(function() { | |
return document.querySelector('ul#bullets').querySelectorAll('li').length === 3; | |
}, "Correct number of bullet points."); | |
this.test.assertEval(function() { | |
return document.querySelector('#phone-number .larger').innerHTML === document.querySelector('form#ipad-form input[name="callCenterPhoneNumber"]').value; | |
}, "The hidden phone number and the one at the top are the same."); | |
this.evaluate(function() { | |
var e, el; | |
el = document.querySelector('select[name="practiceState"] option[value="AL"]'); | |
el.setAttribute('selected', 'selected'); | |
e = document.createEvent('HTMLEvents'); | |
e.initEvent('change', false, true); | |
return el.dispatchEvent(e); | |
}); | |
this.wait(500); | |
this.test.assertEval(function() { | |
return document.querySelectorAll('select[name="practiceCounty"] option').length > 1; | |
}, "There is more than one county in the select box"); | |
descrip = this.evaluate(function() { | |
return document.querySelector('meta[name="description"]').content; | |
}); | |
return this.test.assertEquals("Save over 20% on medical malpractice insurance in " + (toTitleCase(state)) + ". Better coverage and lower medical malpractice insurance rates for physicians and doctors working in " + (toTitleCase(state)) + ".", descrip, "Meta description checks out."); | |
}); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment