Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Latest commit

 

History

History
489 lines (306 loc) · 13.2 KB

Conjure.md

File metadata and controls

489 lines (306 loc) · 13.2 KB

Parallel CasperJS runner, BDD flow, module-based tests, API helpers

Source: lib/conjure/index.js

exports.Conjure()

Reference to Conjure.

Go: TOC | exports

exports.create(requireCasper)

Create a new Conjure.

Parameters:

  • {object} requireCasper Casper-land require()

Return:

{object}

Go: TOC | exports

exports.extendConjure(ext)

Extend Conjure.prototype.

Parameters:

  • {object} ext

Return:

{object} Merge result.

Go: TOC | exports

exports.extendAsyncHelpers(ext)

Extend the object that includes functions like selectorExists().

Parameters:

  • {object} ext

Return:

{object} Merge result.

Go: TOC | exports

exports.extendSyncHelpers(ext)

Extend the object that includes functions like url().

Parameters:

  • {object} ext

Return:

{object} Merge result.

Go: TOC | exports

Conjure(requireCasper)

Add BDD globals and init configuration.

Usage:

var conjure = require('conjure').create();
conjure.set('exitOnError', false);

Configuration:

  • {string} baseUrl Of target test server. [http://localhost:8174]
  • {string} initPath Wait for this relative path to load before starting tests. [/]
  • {string} initSel Wait for this selector (on initPath) before starting tests. [body]
  • {object} test CasperJS test API of the current it()
  • {object} casperConfig Native CasperJS create() settings.

Default casperConfig:

{
  exitOnError: true,
  logLevel: 'debug',
  pageSettings: {
    loadImages: false,
    loadPlugins: false,
    XSSAuditingEnabled: true,
    verbose: true,
    onError: function(self, m) { self.die('CasperJS onError: ' + m, 1); },
    onLoadError: function(self, m) { self.die('CasperJS onLoadError: ' + m, 1); }
  }
}

To modify casperConfig:

  • get() + set() from a test script.
  • Or apply globally using a --bootstrap module.

Properties:

  • {object} conjure All helpers functions bound to this.
  • {object} console LongCon instance
  • {object} flow Bddflow instance
  • {object} utils Native CasperJS utils module
  • {object} colorizer Native CasperJS colorizer module
  • {boolean} running True after Conjure.prototype.run executes

Parameters:

  • {function} requireCasper CasperJS-env require()

See:

Go: TOC

Conjure.createContext(parent, pluck, omit)

Build a context object that includes:

  • All enumerable keys from the parent.
  • Where functions are bound to the parent.

Parameters:

  • {object} parent
  • {string | array} pluck Key(s) from parent to pluck.
  • {string | array} omit Key(s) from parent to omit.

Return:

{object}

Go: TOC | Conjure

Conjure.prototype.isRunning()

Check if run() has been called.

Return:

{boolean}

Go: TOC | Conjure.prototype

Conjure.prototype.test(name, cb)

Run the suite/root describe().

Perform last-minute init based on collected configuration. Silently add an initial describe() to verify initial URL/selector.

Parameters:

  • {string} name
  • {function} cb

Go: TOC | Conjure.prototype

Conjure.prototype.run()

Run collected BBD layers.

Go: TOC | Conjure.prototype

Conjure.prototype.popStatus()

Decrement the current stack depth for trace logs.

Go: TOC | Conjure.prototype

Conjure.prototype.pushStatus()

Increment the current stack depth for trace logs and emit a status event with the name of the depth change source.

All args match Conjure.prototype.status.

Go: TOC | Conjure.prototype

helpers.async.click(sel, [nativeClick=false])

click() alternative that uses jQuery selectors and first waits for a match.

Usage:

this.conjure.click('body'); // jQuery click
this.conjure.click('body', true); // native CasperJS click

Parameters:

  • {string} sel
  • {boolean} [nativeClick=false] Use thenClick() instead of jQuery's click()

Go: TOC | helpers.async

helpers.async.then(cb, [lastStep=true])

then() alternative that with access to the same API as it().

Usage:

this.conjure.then(function() {
  var validate = this.conjure.require('./lib/validation.js');
  this.test.assert(validate.activationCode(this.casper.fetchText('.act-code')));
});

Parameters:

  • {function} cb
  • {boolean} [lastStep=true] Use false to prevent stack trace pop.
    • Ex. Use false in all-but-last-call if a helpers needs to call it multiple time

Go: TOC | helpers.async

helpers.async.thenOpen(args*)

thenOpen() alternative that with access to the same API as it(). Alternative to thenOpen() that resolves relative paths to baseUrl config.

Usage:

// Equivalent:
this.conjure.thenOpen('/login');
this.conjure.thenOpen('login');
this.conjure.thenOpen('http://localhost:8000/login');

Parameters:

  • {mixed} args* Original thenOpen() arguments

See:

Go: TOC | helpers.async

helpers.async.assertSelText(sel, text)

assertTextExists() alternative that uses jQuery selectors.

Usage:

this.conjure.assertSelText('.username', 'user47');

Parameters:

  • {string} sel
  • {string | regexp} text

Go: TOC | helpers.async

helpers.async.each(list, cb)

casper.each() alternative executes the callback inside the custom then(). Callback receives the context of the enclosing then().

Usage:

var memberAreas = ['download', 'stats', 'collection'];
this.conjure.each(memberAreas, function(area, idx, list) {
  this.conjure.thenOpen('/#' + area);
  this.conjure.assertSelText('.promote-acct', /Your free trial expires in/);
});

Parameters:

  • {array} list
  • {function} cb Receives (listItem).

Go: TOC | helpers.async

helpers.async.openHash(hash, [sel])

Append a fragment ID to the current URL.

Usage:

this.conjure.openHash('inbox');
this.conjure.openHash('inbox', '.msg-actions'); // Then wait for a selector match

Parameters:

  • {string} hash Without leading '#'.
  • {string} [sel] Optional selector to wait for after navigation.

Go: TOC | helpers.async

helpers.async.openInitUrl()

Re-open the initial URL.

Go: TOC | helpers.async

helpers.async.selectorExists(sel, [negate], [lastStep=true])

Alternative to waitForSelector() to use jQuery selector support, ex. ':first' syntax.

Usage:

this.conjure.selectorExists('.inbox');

this.conjure.selectorExists('.inbox', true); // Expect selector absence
this.conjure.selectorExists('.inbox', false); // Default

this.conjure.selectorExists('.inbox', false, false); // Skip stack trace pop
this.conjure.selectorExists('.inbox', false, true); // Default

Parameters:

  • {string} sel
  • {boolean} [negate] Use true if selector is not expected to match.
  • {boolean} [lastStep=true] Use false to prevent stack trace pop.
    • Ex. Use false in all-but-last-call if a helpers needs to call it multiple time

Go: TOC | helpers.async

helpers.async.selectorMissing(sel, [lastStep=true])

Negated selectorExists().

Usage:

this.conjure.selectorMissing('.inbox');

this.conjure.selectorMissing('.inbox', false); // Skip stack trace pop
this.conjure.selectorMissing('.inbox', true); // Default

Parameters:

  • {string} sel
  • {boolean} [lastStep=true] Use false to prevent stack trace pop.
    • Ex. Use false in all-but-last-call if a helpers needs to call it multiple time

Go: TOC | helpers.async

helpers.async.sendKeys(sel, keys)

sendKeys() alternative that first waits for a selector to exist.

Usage:

this.conjure.sendKeys('.username', 'user47');

Parameters:

  • {string} sel
  • {string} keys

Go: TOC | helpers.async

helpers.sync.assertType(val, expected, [subject=none])

assertType() alternative that outputs the actual type on mismatch.

Usage:

// assertion error message: 'username should be a string'
this.conjure.assertType(val, 'string', 'username');

// assertion error message: 'subject should be a string'
this.conjure.assertType(val, 'string');

Parameters:

  • {mixed} val
  • {string} expected Ex. 'number'
  • {string} [subject=none] Ex. 'user ID'

Go: TOC | helpers.sync

helpers.sync.require(name)

require() a CasperJS module or any file relative to --root-dir.

Usage:

// Equivalent:
this.conjure.require('lib/validation');
this.conjure.require('lib/validation.js');
this.conjure.require('./lib/validation');
this.conjure.require('./lib/validation.js');

Parameters:

  • {string} name Ex. 'casper' or ./relative/path/module.js
    • For local file: prefix with leading ./
    • Ex. './foo' with --root-dir is /path/to/proj loads /path/to/proj/foo.js')

Return:

{mixed}

Go: TOC | helpers.sync

helpers.sync.url(relUrl)

Resolve a relative URL to the baseUrl config.

Usage:

// Equivalent:
this.conjure.url('/login');
this.conjure.url('login');

Parameters:

  • {string} relUrl

Return:

{string}

Go: TOC | helpers.sync

—generated by apidox