Skip to content

Instantly share code, notes, and snippets.

View nsbingham's full-sized avatar

Nathan Bingham nsbingham

  • optional
  • United States
View GitHub Profile
@nsbingham
nsbingham / A-Pen-by-Nathan-Bingham.markdown
Created October 22, 2013 00:21
A Pen by Nathan Bingham.
@nsbingham
nsbingham / promises-vs-callbacks-example.js
Created September 3, 2013 13:36
A comparison of using wd.js with callbacks versus the promises API
// Example of nesting wd.js callbacks
browser.get("http://admc.io/wd/test-pages/guinea-pig.html", function() {
browser.title(function(err, title) {
assert.ok(~title.indexOf('I am a page title - Sauce Labs'), 'Wrong title!');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
browser.eval("window.location.href", function(err, href) {
assert.ok(~href.indexOf('guinea-pig2'));
browser.quit();
});
@nsbingham
nsbingham / anatomy-of-a-brewie-test.js
Last active December 22, 2015 05:28
This example show the structure of a base brewie test.
// Anatomy of a brewie test
// The test below will check whether the form on the bottom of modern.IE's homepage
// triggers a test when the URL www.microsoft.com is entered and the 'Scan' button
// is clicked.
// Import chai.js's should module
var should = require('chai').should();
// Tests follow mocha's BDD-style syntax
var should = require('chai').should(),
config = require('config'),
http = require('http');
module.exports = function(){
var pageUrl = "http://www.cnn.com/testing";
console.log('loaded?');
Should we do ...
it("should do", function(done){
return class.hasTitle(browser, "home", done);
});
-- or --
it("should do", function(done){
Uncaught Error: Error response status: 13.
at webdriver._newError (/usr/local/lib/node_modules/brewie/node_modules/wd/lib/webdriver.js:74:13)
at webdriver._callbackWithDataBase (/usr/local/lib/node_modules/brewie/node_modules/wd/lib/webdriver.js:150:25)
at Request.webdriver._jsonWireCall [as _callback] (/usr/local/lib/node_modules/brewie/node_modules/wd/lib/webdriver.js:345:5)
at Request.init.self.callback (/usr/local/lib/node_modules/brewie/node_modules/wd/node_modules/request/index.js:148:22)
at Request.EventEmitter.emit (events.js:99:17)
at Request.onResponse (/usr/local/lib/node_modules/brewie/node_modules/wd/node_modules/request/index.js:876:14)
at Request.EventEmitter.emit (events.js:126:20)
at IncomingMessage.Request.onResponse.buffer (/usr/local/lib/node_modules/brewie/node_modules/wd/node_modules/request/index.js:827:12)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
browser
.get(pageUrl)
.then(function(){
return browser.elementById("url");
})
.then(function(scaninput){
return browser.type(scaninput,'microsoft');
})
.then(function(){
return browser.elementById("check_site");
@nsbingham
nsbingham / gist:6284049
Created August 20, 2013 16:50
Example module with singletons
module ConfigManager {
export class Browser {}
export class Config {
name:String;
}
// Sniffing for IE
var isIE = navigator.userAgent.match( /MSIE\s(\d)/ );
if ( isIE && parseInt( isIE[ 1 ], 10 ) >= 9 ) {
executeAwesome();
} else {
alert( "This feature is not supported!" );
}
@nsbingham
nsbingham / tidy-config.txt
Created March 31, 2013 15:56
Clean up a HTML generated by Word with HTML Tidy on OSX
# Install tidy
brew install tidy
# Export the Word doc as HTML
# Create a config file named tidy-config.txt like below
# Find more at http://tidy.sourceforge.net/
tidy -config tidy-config.txt -o cleaned.html -i dirty.htm