Last active
December 22, 2015 05:28
-
-
Save nsbingham/6423787 to your computer and use it in GitHub Desktop.
This example show the structure of a base brewie test.
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
// 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 | |
module.exports = function(){ | |
var pageUrl = "http://www.modern.ie"; | |
// A group of tests start with mocha's 'describe' statement | |
// Use the title of this statement to easily identify what you're testing | |
describe("the home page", function(){ | |
// The 'it' statement describes what the test is actually testing | |
// when combined with the 'describe' statement about this should read like | |
// a sentence that describes who and what you're testing | |
// Notice the 'done' callback. This is a mocha convention that allows you | |
// to tell mocha when the test has completed. | |
it("should navigate to the scan page when we click the scan button", function(done){ | |
// The 'browser' object below is a global wd.js browser object provided by brewie and | |
// represents the current browser being tested. Brewie takes advantage of wd.js's promises API. | |
// Promises help streamline asynchronous functions into an easy to read syntax. | |
browser | |
// 'get' is a wd.js method that navigates the browser to specific page | |
.get(pageUrl) | |
// 'then' is part of the wd.js's promises API | |
// Each function inside 'then' method is called upon completion of the previous statement | |
.then(function(){ | |
// Methods like 'elementById' are part of wd.js's JSONWireProtocol API. | |
// For a full list of the available methods, see https://github.com/admc/wd#supported-methods | |
return browser.elementById("url"); | |
}) | |
.then(function(scaninput){ | |
return browser.type(scaninput,'www.microsoft.com'); | |
}) | |
.then(function(){ | |
return browser.elementById("check_site"); | |
}) | |
.then(function(button){ | |
return browser.clickElement(button); | |
}) | |
.then(function(){ | |
return browser.waitForVisibleByClassName('report-results',10000); | |
}) | |
// 'done' is part of the wd.js's promises API | |
// It should be called at the end of a string of promises (thens) | |
// 'done' will fire after all promises are complete or if an error | |
// occurs during the execution of any promises in the chain | |
.done(function(){ | |
// After all the components of our test have ran, we call the 'done' method to let | |
// mocha know that the test has completed. | |
done(); | |
}); | |
}); | |
}); | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment