Jasmine

Jasmine is a popular behavior-driven development (BDD) testing framework. Using Jasmine with Perfecto is as easy as setting up a regular Selenium test script.

There are different libs you can use to interact with Perfecto via Jasmine:

Learn how to set up the integration.

Important: This document includes references to a third-party product, Jasmine. The user interface and usage of third-party products are subject to change without notice. For the latest published information about Jasmine, see https://jasmine.github.io/pages/docs_home.html.

Prerequisites

To create a Jasmine project, you need to have node.js and npm installed.

1 | Initialize a Jasmine project from scratch 

  1. Create a project folder.
  2. Create a spec folder in the project folder by running the following commands in the project folder, in this order:

    Copy
    npm init
    npm install --save-dev jasmine selenium-webdriver protractor perfecto-reporting
    ./node_modules/.bin/jasmine init
  3. In the spec folder, write test scripts with extension .spec.js so it will be picked up by Jasmine as test scripts by default.
  4. (Optional) To change the Jasmine settings, edit spec/support/jasmine.json.

2 | Set up Jasmine to connect to Perfecto

Now that you have set up the empty Jasmine project, you can configure your framework to connect to Perfecto. There are different ways to achieve this. This section focuses on Selenium-Webdriver and Protractor.

3 | Set up Perfecto Smart Reporting for Jasmine

Jasmine has a reporter interface. You can register a customized Reporter by using the following statement:

Copy
jasmine.getEnv().addReporter(perfectoReporter);

The following code block is an example for a customized perfectoReporter:

Copy

Customized perfectoReporter

var perfectoReporter =
{
jasmineStarted: function(suiteInfo) {
// put insome info on jasmine started
},

suiteStarted: (result) => {
// here you can add some custom code to execute when each suite is started
},
specStarted: (result) => {
// each spec will be a test in Perfecto Reporting
reportingClient.testStart(result.fullName);
},
specDone: (result) => {
// ending the test
// here we report about test end event


if (result.status === 'failed') {
// on a failure we report the failure message and stack trace

console.log('Test status is: ' + result.status);
const failure = result.failedExpectations[result.failedExpectations.length - 1];

reportingClient.testStop({
status: perfectoReporting.Constants.results.failed,
message: `${failure.message} ${failure.stack}`
});

} else {
// on success we report that the test has passed
console.log('Test status is: ' + result.status);
reportingClient.testStop({
status: perfectoReporting.Constants.results.passed
});
}
},
suiteDone: (result) => {
// when the suite is done we print in the console its description and status
console.log('Suite done: ' + result.description + ' was ' + result.status);
}

};

The reportingClient is initialized as follows:

Copy
var perfectoExecutionContext = await new perfectoReporting.Perfecto.PerfectoExecutionContext({
webdriver: browser,
job: {jobName: "<yourCI job name>",buildNumber:<your CI build number>},
tags: [<your tags>']
});
reportingClient = await new perfectoReporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);