Skip to content

Instantly share code, notes, and snippets.

@moofish32
Last active August 29, 2015 14:08
Show Gist options
  • Save moofish32/f3262801515611e58025 to your computer and use it in GitHub Desktop.
Save moofish32/f3262801515611e58025 to your computer and use it in GitHub Desktop.
casper.incTestNumber = () =>
@count ?= 0
++@count
casper.setOddzContext = (ctx) =>
@oddzCtx = ctx
casper.getOddzContext = () =>
@oddzCtx
casper.screenshotName = () =>
@screenshotCount ?= 0
console.log "taking screen shot #{@screenshotCount}"
'screenshot-' + "#{@screenshotCount++}.jpg"
# Capture screens from all fails
casper.test.on "fail", (failure) ->
casper.capture "fail-#{casper.screenshotName()}"
casper.exit 1
# Capture screens from timeouts from e.g. @waitUntilVisible
# Requires RC3 or higher.
casper.options.onWaitTimeout = ->
@capture("timeout-#{@screenshotName()}")
@exit 1
casper.confirmResponse = (boolean) =>
@confirm = boolean
casper.confirmMsgs = () =>
@confirmMsgs ?= []
casper.setFilter "page.confirm", (msg) ->
@confirm ?= false
if @confirm == true
@confirmClick(msg)
else
console.log 'You did not confirm: ' + msg
return @confirm
casper.confirmClick = (msg) ->
@confirmMsgs().push msg
casper.confirmClickCount = () ->
@confirmMsgs().length
casper.clickWithConfirm = (selector, assertMsg) ->
@confirm = true
initial = @confirmClickCount()
@click selector
@test.assertEquals initial + 1, @confirmClickCount(), "#{casper.incTestNumber()}. " + assertMsg + " and confirmed msg: #{@confirmMsgs().pop()}"
@confirm = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment