Skip to content

Instantly share code, notes, and snippets.

@albburtsev
Created December 24, 2014 21:41
Show Gist options
  • Save albburtsev/72fc3678a1d665e6624b to your computer and use it in GitHub Desktop.
Save albburtsev/72fc3678a1d665e6624b to your computer and use it in GitHub Desktop.
module.exports = (phantomcss, snap) ->
casper.test.begin 'Landing', 5, suite = (test) ->
casper.start PAGE
casper.viewport 1240, 1024
# Full page snap
casper.then ->
snap 'landing_full'
# Click into looker button
casper.thenEvaluate ->
$.mockjax
url: '/api/user/start'
responseText: {}
responseTime: 500
($ '.js-looker-button').click()
# Spinner appears atop looker button
casper.wait 100
casper.then ->
test.assertEval ->
return ($ '.js-looker-button').hasState 'loading'
, 'Spinner found after click on .js-looker-button'
# Login form appears
casper.wait 500
casper.then ->
@click '.enter [data-target=".js-login"]'
snap 'login_form'
# Empty form after submit
casper.then ->
@fill '.js-login-form form',
email: ''
password: ''
, true
casper.then ->
test.assertEval ->
return (($ '.js-login-form [name="email"]').hasState 'invalid') and (($ '.js-login-form [name="password"]').hasState 'invalid')
, 'All fields is invalid'
# Typing incorrect email
casper.thenEvaluate ->
email = ($ '.js-login-form [name="email"]')
email.val 'incorrect'
email.trigger 'keyup'
casper.then ->
test.assertEval ->
return ($ '.js-login-form [name="email"]').hasState 'invalid'
, 'Email is incorrect'
# Typing correct email and password
casper.then ->
phantomcss.compareAll()
casper.run ->
test.done()
global.HOST = (casper.cli.get 'host') or 'rememba.ru'
global.PAGE = "http://#{HOST}/"
phantomcss = require 'phantomcss'
# Shows info block
casper.echo ''
casper.echo 'Specify host with --host option: casperjs test test/test.coffee --host=alfa.rememba.ru', 'INFO'
casper.echo 'Page: ' + PAGE, 'INFO'
casper.echo ''
# Proxy logs from browser console
casper.on 'remote.message', (message) ->
console.log 'BROWSER:', message
# PhantomCSS settings
phantomcss.init({
libraryRoot: 'node_modules/phantomcss'
screenshotRoot: 'test/screenshots'
failedComparisonsRoot: 'test/failures'
addLabelToFailedImage: false
})
# phantomcss.turnOffAnimations()
snap = (name, selector = 'body') ->
phantomcss.screenshot selector, name
# Landing test suite
(require './suite/landing') phantomcss, snap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment