Last active
August 29, 2015 14:01
-
-
Save pc-rgundlapalli/028b92d84ce4650bdfd5 to your computer and use it in GitHub Desktop.
phantom tests
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
(function () { | |
var config = { | |
/* define locations of mandatory javascript files */ | |
files: { | |
JQUERY: 'jquery.min.js', | |
UNDERSCORE: 'underscore.js', | |
RAPHAEL: 'raphael.min.js', | |
PERSPECTIVE: 'perspective.js' | |
} | |
}, | |
mapCLArguments, | |
render, | |
args = {}, | |
system = require('system'); | |
mapCLArguments = function () { | |
var map = {}, | |
i, | |
key; | |
for (i = 0; i < system.args.length; i += 1) { | |
if (system.args[i].charAt(0) === '-') { | |
key = system.args[i].substr(1, i.length); | |
map[key] = system.args[i + 1]; | |
} | |
} | |
if(typeof map['chd'] == 'undefined'){ | |
console.log('Commandline Usage: -chd data-points'); | |
phantom.exit(1); | |
} | |
return map; | |
}; | |
render = function(params){ | |
var page = require('webpage').create(), | |
createChart, | |
renderSVG; | |
page.onConsoleMessage = function (msg) { | |
console.log(msg); | |
}; | |
page.onAlert = function (msg) { | |
console.log(msg); | |
}; | |
page.onError = function(msg, trace) { | |
var msgStack = ['PHANTOM ERROR: ' + msg]; | |
if (trace && trace.length) { | |
msgStack.push('TRACE:'); | |
trace.forEach(function(t) { | |
msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : '')); | |
}); | |
} | |
console.error(msgStack.join('\n')); | |
phantom.exit(1); | |
}; | |
createChart = function(series){ | |
var $container = $('<div>').appendTo(document.body); | |
$container.attr('id', 'chart-container'); | |
Raphael('chart-container').drawGrid({ | |
max : _.max(series), | |
min : _.min(series), | |
topPadding : .1, | |
bottomPadding : .1, | |
hideLabels : true | |
}) | |
.drawLineSeries({ | |
series : series, | |
type : 'noisyArea', | |
fill: '#0088cc', | |
stroke: '#0088cc', | |
strokeWidth: 2 | |
}) | |
.drawBaseline() | |
.drawZeroline(); | |
} | |
renderSVG = function(){ | |
page.render('_screenshot.png'); | |
} | |
page.open('about:blank', function (status) { | |
var svg, | |
jsfile; | |
// load necessary libraries | |
for (jsfile in config.files) { | |
page.injectJs(config.files[jsfile]); | |
} | |
var series = [], chd = params.chd.split(','); | |
for(var i = 0; i < chd.length; i++){ | |
series.push(Number(chd[i])); | |
} | |
page.evaluate(createChart, series); | |
renderSVG(); | |
phantom.exit(); | |
}); | |
} | |
args = mapCLArguments(); | |
render(args); | |
}()); |
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
console.log('Hello, world!'); | |
phantom.exit(); |
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 url = 'http://www.google.com' ; | |
//url = 'https://www-devtrunk.awspcap.com/'; | |
//url = 'https://www-devtrunk.awspcap.com/renderChart?chd=t:100,200,150,400'; | |
var page = require('webpage').create(); | |
page.open(url, function() { | |
page.render('_screenshot.png'); | |
phantom.exit(); | |
}); |
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 page = require('webpage').create(), | |
system = require('system'), | |
url = system.args[1], | |
outputFile = system.args[2]; | |
page.open(url, function (status) { | |
if (status !== 'success') { | |
console.log('Unable to load the address!'); | |
phantom.exit(); | |
} else { | |
window.setTimeout(function () { | |
page.render(outputFile); | |
phantom.exit(); | |
}, 200); | |
} | |
}); |
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 text1 = 'Two'; | |
jQuery("select option").filter(function() { | |
//may want to use $.trim in here | |
return $(this).text().match(/text1$/); | |
}).attr('selected', true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool stuff