diff --git a/README.md b/README.md index 367144fca..0075fe1ba 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,33 @@ Scenario('test some forms', (I) => { All actions are performed by I object; assertions functions start with `see` function. In this examples all methods of I are taken from WebDriverIO helper, see [reference](https://github.com/Codeception/CodeceptJS/blob/master/docs/API.md#webdriverio) to learn how to use them. +Let's execute this test with `run` command. Additional option `--steps` will show us the running process. We recommend use `--steps` or `--debug` during development. + +``` +codeceptjs run --steps +``` + +This will produce an output: + +``` +CodeceptJS Demonstration -- + test some forms + • I am on page "http://simple-form-bootstrap.plataformatec.com.br/documentation" + • I fill field "Email", "hello@world.com" + • I fill field "Password", "123456" + • I check option "Active" + • I check option "Male" + • I click "Create User" + • I see "User is valid" + • I dont see in current url "/documentation" + ✓ OK in 17752ms +``` + +CodeceptJS has an ultimate feature to help you develop and debug you test. +You can **pause execution of test in any place and use interactive shell** to try different actions and locatots. +Just add `pause()` call at any place in test and run it. + + We filled form with `fillField` methods, which located form elements by their label. The same way you can locate element by name, CSS or XPath locators in tests: diff --git a/lib/interfaces/codeceptjs.js b/lib/interfaces/codeceptjs.js new file mode 100644 index 000000000..aea9bf018 --- /dev/null +++ b/lib/interfaces/codeceptjs.js @@ -0,0 +1,102 @@ +/** + * Module dependencies. + */ + +var Suite = require('mocha/lib/suite'); +var Test = require('mocha/lib/test'); +var event = require('../event'); +var scenario = require('../scenario'); + +/** + * Codecept-style interface: + * + * Feature('login') + * Scenario('login as regular user', (I) { + * I.fillField(); + * I.click() + * I.see('Hello, '+data.login); + * }); + * + * @param {Suite} suite Root suite. + */ +module.exports = function(suite) { + var suites = [suite]; + + suite.on('pre-require', function(context, file, mocha) { + var common = require('mocha/lib/interfaces/common')(suites, context); + + common.before('codeceptjs event', function() { + event.dispatcher.emit(event.suite.before); + }); + + common.after('codeceptjs event', function() { + event.dispatcher.emit(event.suite.after); + }); + + // create dispatcher + + context.BeforeAll = common.before; + context.AfterAll = common.after; + + context.run = mocha.options.delay && common.runWithSuite(suite); + /** + * Describe a "suite" with the given `title` + * and callback `fn` containing nested suites + * and/or tests. + */ + + context.Feature = function(title) { + var suite = Suite.create(suites[0], title); + suite.file = file; + suite.beforeEach('codeceptjs.before', scenario.setup); + suite.afterEach('finialize codeceptjs', scenario.teardown); + suites.unshift(suite); + return suite; + }; + + context.Background = context.Before = function(fn) { + suites[0].beforeEach('Before', scenario.injected(fn)); + } + + context.After = function(fn) { + suites[0].afterEach('After', scenario.injected(fn)); + } + + /** + * Describe a specification or test-case + * with the given `title` and callback `fn` + * acting as a thunk. + */ + + context.Scenario = function(title, fn) { + var suite = suites[0]; + if (suite.pending) { + fn = null; + } + suite.timeout(0); + var test = new Test(title, fn); + test.file = file; + test.async = true; + test.timeout(0); + suite.addTest(scenario.test(test)); + return test; + }; + + /** + * Exclusive test-case. + */ + context.Scenario.only = function(title, fn) { + var test = context.it(title, fn); + var reString = '^' + escapeRe(test.fullTitle()) + '$'; + mocha.grep(new RegExp(reString)); + return test; + }; + + /** + * Pending test case. + */ + context.xScenario = context.Scenario.skip = function(title) { + context.Scenario(title); + }; + }); +}; diff --git a/package.json b/package.json index 6abe88f24..aa899fb73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codeceptjs", - "version": "0.1.3", + "version": "0.1.4", "description": "Modern Era Aceptance Testing Framework for NodeJS", "homepage": "http://codecept.io", "repository": "Codeception/codeceptjs",