Created
February 2, 2016 20:19
-
-
Save sethkrasnianski/214693e8b9919f97d4e3 to your computer and use it in GitHub Desktop.
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
var SLACK_ROOM_URL = process.env.SLACK_ROOM_URL; | |
var page = require('webpage').create(); | |
var url = 'https://www.mojotech.com/contact-form'; | |
phantom.notifySlack = function(id, text, code) { | |
var settings = { | |
operation: 'POST', | |
encoding: 'utf8', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
data: JSON.stringify({ | |
text: text | |
}) | |
}; | |
page.open('https://hooks.slack.com/services/' + id, settings, function(status) { | |
console.log('Status: ' + status); | |
phantom.exit(code); | |
}); | |
}; | |
function waitFor(testFx, onReady, timeOutMillis) { | |
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 5000; | |
var start = new Date().getTime(); | |
var condition = false; | |
var interval = setInterval(function() { | |
if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) { | |
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); | |
} else { | |
if (!condition) { | |
console.log("Waited until timeout."); | |
phantom.exit(1); | |
} else { | |
console.log("Waited for " + (new Date().getTime() - start) + "ms."); | |
typeof(onReady) === "string" ? eval(onReady): onReady(); | |
clearInterval(interval); | |
} | |
} | |
}, 250); | |
}; | |
page.open(url, function(status) { | |
if (status !== 'success') { | |
phantom.notifySlack(SLACK_ROOM_URL, 'The site appears to be down :sadmac:', 1); | |
} | |
page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js', function() { | |
page.evaluate(function() { | |
$('input[name="name"]').val('Test svt'); | |
$('input[name="email"]').val('[email protected]'); | |
$('textarea[name="message"]').val('Testing the form'); | |
$('#budget1').attr('checked', true); | |
$('#providence').attr('checked', true); | |
$('input[type="submit"]').click(); | |
}); | |
waitFor(function() { | |
return page.evaluate(function() { | |
return $('.thanks-content').is(":visible"); | |
}); | |
}, function() { | |
phantom.notifySlack(SLACK_ROOM_URL, 'The contact form is working properly :yougotitdude:', 0); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment