Created
August 27, 2012 17:21
-
-
Save pamelafox-coursera/3490535 to your computer and use it in GitHub Desktop.
wd-async tests for Coursera
This file contains hidden or 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
// Run with ./node_modules/mocha/bin/mocha app/www/test/web/wd.js --timeout 5000 | |
var assert = require('assert'); | |
var wd = require('wd-sync').wd | |
var Wd = require('wd-sync').Wd; | |
browser = wd.remote(); | |
/** test data **/ | |
var testData = { | |
genUserEmail: function() { | |
return 'pamela.fox+' + (new Date()).getTime() + '@gmail.com'; | |
} | |
}; | |
testData.user = { | |
name: 'Testy McTesterPants', | |
password: 'test', | |
email: testData.genUserEmail() | |
}; | |
var bt = { | |
BASE_PATH: 'http://site/', | |
init: function() { | |
browser.init( { browserName: 'firefox'} ); | |
}, | |
waitForEl: function(selector) { | |
browser.waitForConditionInBrowser('document.querySelectorAll("' + selector + '").length > 0'); | |
}, | |
getPath: function(path) { | |
var url = bt.BASE_PATH + path; | |
try { | |
browser.get(url); | |
} catch (e) { | |
throw new Error('Could not load ' + url); | |
} | |
}, | |
/** Assert specific **/ | |
assertTitle: function(title) { | |
assert.equal(browser.title(), title); | |
}, | |
/** Coursera specific **/ | |
waitForLoad: function(path) { | |
bt.getPath(path); | |
bt.waitForEl('.coursera-body'); | |
}, | |
fillOutSignUp: function(options) { | |
options = options || {}; | |
var name = options.name || testData.user.name; | |
var email = options.email || testData.genUserEmail(); | |
var password = options.password || testData.user.password; | |
var agree = options.agree || true; | |
browser.type(browser.elementByName('full_name'), name); | |
browser.type(browser.elementByName('email_address'), email) | |
browser.type(browser.elementByName('password'), password) | |
if (agree) browser.clickElement(browser.elementByName('agree')) | |
browser.clickElement(browser.elementByCss('.coursera-signup-button')); | |
} | |
}; | |
describe('web - landing', function() { | |
xit('should load the title and logo', function(done) { | |
Wd(function() { | |
browser.init( { browserName: 'firefox'} ); | |
bt.waitForLoad('/'); | |
bt.assertTitle('Coursera.org') | |
bt.quit(); | |
done(); | |
}); | |
}); | |
}); | |
describe('web - signup', function() { | |
it('should do a successful signup', function(done) { | |
Wd(function() { | |
bt.init(); | |
bt.waitForLoad('/account/signup'); | |
bt.assertTitle('Sign Up | Coursera'); | |
bt.fillOutSignUp(); | |
browser.quit(); | |
done(); | |
}); | |
}); | |
it('should error on no name', function(done) { | |
Wd(function() { | |
bt.init(); | |
bt.waitForLoad('/account/signup'); | |
bt.fillOutSignUp({name: ''}); | |
assert(browser.text(browser.elementByCss('.coursera-signup .form-errors')), 'Please provide your name.'); | |
browser.quit(); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment