Class: execFct

hobs.actions.core. execFct

Executes sync/async javascript code


new execFct(fct [, options])

Parameters:
Name Type Argument Description
fct Object

The function that will be executed

options TestStepOptions <optional>

Test method options (Accepts: "delay", "timeout")

Examples

Execute synchronous code

new hobs.TestCase("tc")
     // will always be marked as PASSED
     .execFct(function() {
         // Synchronous Javascript code
         var i = 0;
     })

Execute asynchronous code

new hobs.TestCase("tc")
     // will always be marked as PASSED
     .execFct(function(opts, done) {
         // Asynchronous Javascript code
         setTimeout(function() {
             var i = 0;

             // Call done function to finish execFct action and continue testCase execution
             done();
         }, 5000);
     })

     // will wait 5s. before being executed
     .click("button")

Control .execFct result (pass/fail)

//By default, .execFct is always marked as passed. Though .execFct will be marked failed in following cases:

// The passed function returned false:
new hobs.TestCase("tc")
     .execFct(function() {
             return false;
     })

// The passed function throws an exception
new hobs.TestCase("tc")
     .execFct(function() {
             var i = {};
             // i.a.prop do not exist, function will throw an exception
             i.a.prop = "blah";
     })

// The passed asynchronous function fails to call done() within the timeout specified in the options:
new hobs.TestCase("tc")
     .execFct(function(opts, done) {
         // Asynchronous Javascript code
         setTimeout(function() {
             done();
         }, 5000);
     }, { timeout: 1000 })

// The passed asynchronous function fails by calling done(false,message) as arguments:
new hobs.TestCase("tc")
     .execFct(function(opts, done) {
         // Asynchronous Javascript code
         setTimeout(function() {
             done(false, "some error message");
         }, 500);
     }, { timeout: 1000 })

Extends

Methods


cancel()

Cancels step execution

Inherited From:

clone()

Returns a clone of the teststep

Inherited From:
Returns:
Type
hobs.TestStep

done(state, result)

Completes step execution

Parameters:
Name Type Description
state string

The final state of the step

result object

The result of the step execution

Inherited From:

duration( [format])

Get the duration of the test step execution

Parameters:
Name Type Argument Default Description
format string <optional>
'ms'

Specific format to convert the duration to. By default, milliseconds

Inherited From:
Returns:

The duration of execution in a specific format. Returns -1 if the test step has not been completely executed.

Type
number

exec( [options])

Executes the step. It consists of executing the function passed to the constructor.

Parameters:
Name Type Argument Description
options Object <optional>

Extra properties, extending the ones set at the instantiation of the step and passed, as first argument, to the step function.

Inherited From:
Returns:

A promise

Type
Object

execData(key, value)

Get/set execution metadata of the test step

Parameters:
Name Type Description
key string

The name of the option property

value *

The value to set the option property to

Inherited From:
Example
// Init TestStep
var step = new hobs.TestStep('ts1', 'Test Step #1');
// Execution metadata is set to an empty object by default

// Get all the options as an Object
step.execData(); // => {}

// Get the value of a specific option property
step.execData('prop1'); // => 'string'
step.execData('prop2'); // => 12

// Set the value of a specific option property
step.execData('prop1', true);
step.execData('prop2', 123);
step.execData(); // => {prop1: true, prop2: 123}

options(name, value)

Get/set options of the step

Parameters:
Name Type Description
name string

The name of the option property

value *

The value to set the option property to

Inherited From:
Example
// Init Step with options
var step = new hobs.Chaining.Step(null, {prop1: 'string', prop2: 12});

// Get all the options as an Object
step.options(); // => {prop1: 'string', prop2: 12}

// Get the value of a specific option property
step.options('prop1'); // => 'string'
step.options('prop2'); // => 12

// Set the value of a specific option property
step.options('prop1', true);
step.options('prop2', 123);
step.options(); // => {prop1: true, prop2: 123}

pause()

Pauses step execution

Inherited From:

result( [format] [, withDetails])

Returns a represention of the result of the test step execution.

Parameters:
Name Type Argument Default Description
format string <optional>

Use a specific hobs.reporters to render the result.

withDetails boolean <optional>
false

By default, hobs.reporters do not process children of successful test steps. Force this parameter to true to also get them.

Inherited From:
Returns:

An object representing the result of the execution.

Type
object

resume()

Resumes execution of a paused step

Inherited From:
Throws:

Will throw an error if the step is not paused


state()

Returns the current state of the step

Inherited From:
Returns:
Type
String