Last active
August 29, 2015 14:21
-
-
Save michaelhasan/fc5d9f00e3543baa44ce to your computer and use it in GitHub Desktop.
FOIA Project casperjs test
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
| /** | |
| * First attempt at automatically testing foiaproject.org | |
| * | |
| */ | |
| casper.on('remote.message', function(msg) { | |
| /* this.echo('remote message caught: ' + msg); */ | |
| }); | |
| casper.options.verbose=false; | |
| casper.options.logLevel="none"; | |
| casper.options.viewportSize = {width: 1680, height: 1050 }; | |
| casper.test.begin('FOIA Project Test Suite', 12, function suite(test) { | |
| casper | |
| .start('http://test.foiaproject.org/', function() { | |
| test.assertExists('ul#nav.wrapper', "FOIA Home menu exists"); | |
| test.assertExists('ul#nav.wrapper li:nth-child(4) a', 'FOIA Home menu has a link on fourth child'); | |
| this.click('ul#nav.wrapper li:nth-child(4) a'); | |
| }); | |
| casper | |
| .then(function() { | |
| test.assertExists('h1.pagetitle', 'FOIA Requests Page title exists'); | |
| test.assertSelectorHasText('h1.pagetitle', 'About FOIA Request Data', | |
| "FOIA Requests Page title text matches"); | |
| this.clickLabel("Agency Processing Times") | |
| }); | |
| casper | |
| .waitForSelector('div#prenoms_list_container ul li', function () { | |
| test.assertSelectorHasText('#chart-title h1', 'Agency Processing of FOIA Requests', | |
| 'FOIA Agencies Chart page title matches'); | |
| var getAgencyNum = (function() { | |
| return this.evaluate(function() { | |
| var selector = 'div#prenoms_list_container ul li'; | |
| var text = '', count = 0, elements = __utils__.findAll(selector); | |
| count=elements.length; | |
| return count; | |
| }); | |
| }).bind(this); | |
| var getClsLines = (function() { | |
| return this.evaluate(function() { | |
| var selector = '#right_side svg #prenoms #lines_cls g.line'; | |
| var text = '', count = 0, elements = __utils__.findAll(selector); | |
| count=elements.length; | |
| return count; | |
| }); | |
| }).bind(this); | |
| test.assertEqual(getAgencyNum(), 5, 'FOIA Agencies Found expected 5 agencies'); | |
| test.assertEqual(getClsLines(), 0, 'FOIA Agencies Initial chart has no closing lines'); | |
| this.click('div#prenoms_list_container ul li:nth-child(1)'); | |
| var flushAllD3Transitions = (function() { | |
| return this.evaluate(function() { | |
| var now = Date.now; | |
| Date.now = function() { return Infinity; }; | |
| d3.timer.flush(); | |
| Date.now = now; | |
| }); | |
| }).bind(this); | |
| this.waitForSelector('div#prenoms_list_container ul li.selected', | |
| function pass () { | |
| flushAllD3Transitions(); | |
| var rect = this.getElementBounds('#playground_bg'); | |
| var _mouse_x=(rect.left + rect.width/2); | |
| var _mouse_y=(rect.top + rect.height/2); | |
| this.mouse.move(_mouse_x, _mouse_y); | |
| flushAllD3Transitions(); | |
| this.capture('svg.png'); | |
| test.assertExists('#popupwin #popupsvg #popup'); | |
| test.assertEqual(this.getElementAttribute('g#popup', 'opacity'), "", | |
| 'FOIA Agencies Popup has no opacity'); | |
| /*( test.assertEqual(this.getElementInfo('g#popup').visible, true, | |
| 'FOIA Agencies Popup is visible after mouse move');*/ | |
| test.assertEqual(getClsLines(), 1, | |
| 'FOIA Agencies Chart has 1 closing line after clicking first agency'); | |
| this.click('div#prenoms_list_container ul li:nth-child(1)'); | |
| }, | |
| function fail () { | |
| test.fail('FOIA Agencies First Agency did not get selected'); | |
| }); | |
| }); | |
| casper | |
| .waitWhileSelector('div#prenoms_list_container ul li.selected', function () { | |
| var getClsLines = (function() { | |
| return this.evaluate(function() { | |
| var selector = '#right_side svg #prenoms #lines_cls g.line'; | |
| var text = '', count = 0, elements = __utils__.findAll(selector); | |
| count=elements.length; | |
| return count; | |
| }); | |
| }).bind(this); | |
| var flushAllD3Transitions = (function() { | |
| return this.evaluate(function() { | |
| var now = Date.now; | |
| Date.now = function() { return Infinity; }; | |
| d3.timer.flush(); | |
| Date.now = now; | |
| }); | |
| }).bind(this); | |
| flushAllD3Transitions(); | |
| test.assertEqual(getClsLines(), 0, | |
| 'FOIA Agencies Initial chart has no closing lines after unselecting agency'); | |
| this.click('div#prenoms_list_container ul li:nth-child(1)'); | |
| }); | |
| casper | |
| .waitForSelector('div#prenoms_list_container ul li.selected', function () { | |
| var flushAllD3Transitions = (function() { | |
| return this.evaluate(function() { | |
| var now = Date.now; | |
| Date.now = function() { return Infinity; }; | |
| d3.timer.flush(); | |
| Date.now = now; | |
| }); | |
| }).bind(this); | |
| flushAllD3Transitions(); | |
| var rect = this.getElementBounds('#playground_bg'); | |
| var _mouse_x=(rect.left + rect.width/2); | |
| var _mouse_y=(rect.top + rect.height/2); | |
| this.mouse.move(_mouse_x, _mouse_y); | |
| flushAllD3Transitions(); | |
| this.capture('svg2.png'); | |
| test.assertEqual(this.getElementAttribute('g#popup', 'opacity'), "", | |
| 'FOIA Agencies Popup has no opacity'); | |
| }); | |
| casper | |
| .run(function() { | |
| test.done(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment