secret
Last active

  • Download Gist
config.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# jslint node: true
'use strict'
 
# You can extend default options passing config object in module initialization
#
# var options = {
# foo: 'bar'
# }
#
# var casper = require('./modules/config')(options);
 
extendConfig = (config, options) ->
for key of options
config[key] = options[key]
 
return config
 
module.exports = (options) ->
config = {
verbose: false
logLevel: 'debug'
viewportSize:
width: 1600
height: 900
}
 
if options
config = extendConfig(config, options)
 
casper = require('casper').create(config)
example.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# jslint node: true
'use strict'
 
casper = require('./modules/config')()
responsiveness = require('./modules/responsiveness')
testUrl = 'http://example.com'
 
casper.start(testUrl, ->
data = [{
selector: '.description',
visibility: [{
viewport: '1600|720',
visible: no
}, {
viewport: '1024|720',
visible: no
}, {
viewport: '700|720',
visible: no
}, {
viewport: '500|720',
visible: yes
}, {
viewport: '300|720',
visible: yes
}]
}]
 
responsiveness.call(this, data)
);
 
casper.run ->
@test.renderResults true
responsiveness.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# jslint node: true
'use strict'
 
# Data format of elements argument:
#
# elements = [{
# selector: '#go-up',
# visibility: [{
# viewport: '1600|720',
# visible: no
# }, {
# viewport: '1024|720',
# visible: no
# }]
# }];
#
# Call it with 'this' binded to your casper instance eg.:
#
# var responsiveness = require('./modules/responsiveness');
# casper.start(testUrl, function() {
# var data = (...);
# responsiveness.call(this, data);
# });
 
module.exports = (elements) ->
for element in elements
for breakpoint in element.visibility
width = parseInt(breakpoint.viewport.split('|')[0], 10) || 1600
height = parseInt(breakpoint.viewport.split('|')[1], 10) || 900
message = element.selector + ' at ' + width + 'x' + height + ' should be '
 
@viewport(width, height)
 
if breakpoint.visible
message += 'visible'
@test.assertVisible(element.selector, message)
else
message += 'hidden'
@test.assertNotVisible(element.selector, message)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.