Skip to content

Commit

Permalink
updated docs, added missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Nov 24, 2015
1 parent 216d547 commit 91280c6
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
102 changes: 102 additions & 0 deletions lib/interfaces/codeceptjs.js
Original file line number Diff line number Diff line change
@@ -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);
};
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 91280c6

Please sign in to comment.