Last active
August 29, 2015 14:08
-
-
Save moofish32/f3262801515611e58025 to your computer and use it in GitHub Desktop.
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
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