ziwo-logo

Published the Nov 22, 2019

UI Automation Test reporting: Protractor/BDD

Automation Tes insights about QA for Startups using UI Automation Test report using Protractor, BDD and cucumber-html-reporter

customer support
call center solution
callcenterapi
API library
JSON file
Reporting
UI Automation

Reporting & UI Automation Test

In the feature-oriented test script development, the Test Reporting solution is feasible for the Protractor framework with cucumber integration. Let’s start the Automation Test with the framework structure.

Test script designed based on the test cases order by test scenario provided for UI Automation Test reporting. On this framework, Cucumber feature file does the control of the execution order. Just like TestNG or JUnit do. But unlike those frameworks in this solution.=

The component we are using here is an Open source tool from npm. Inc These guys are providing amazing openSource tools. Will be helpful for you in the future.

Essential JavaScript development tools that help you go to market faster and build powerful applications using modern open-source code. We are only considering this tool for Automation Test in this article.

cucumber-html-reporter

5.0.0 •    Public What does this component does, is basically creating a JSON file with the cucumber result API? To enable this you need to install

npm install cucumber-html-reporter --save-dev

The latest version of this support cucumber 3 🙂

Install cucumber-html-reporter@2.0.3 for cucumber version < Cucumber@3
Install cucumber-html-reporter@0.5.0 for cucumber version < Cucumber@2
Install cucumber-html-reporter@0.4.0 for node version <0.12

Let’s get you started. If you have already installed this component (Keep the focus on cucumber version).

Steps to the solution

1.Install package

2.Add code to the Runner class (this will create json file for you)

3.Create index.js file (to convert your json to HTML)

4.Run index.js (this will create html report in the mentioned location)

For CucumberJS

This module converts Cucumber’s JSON format to HTML reports.

In order to generate JSON formats, run the Cucumber to create the JSON format and pass the file name to the formatter as shown below,

$ cucumberjs test/features/ -f json:test/report/cucumber_report.json

Multiple formatter are also supported,----->

$ cucumberjs test/features/ -f summary -f json:test/report/cucumber_report.json

Are you using cucumber with other frameworks or running cucumber-parallel? Pass relative path of JSON file to the options as shown here

Now modify your runner class

cucumberOpts: {
        require: ['src/spec/*.spec.ts'],
        format: 'json:src/report/cucumber_report.json'
    },

Note :Applicable if storeScreenshots=true. Relative path for directory where screenshots should be saved. E.g. the below options should store the screenshots to the <parentDirectory>/screenshots/ whereas the report would be at <parentDirectory>/report/cucumber_report.html

Run your script, You can get the JSON file in the mentioned location.

    'keyword': 'Feature',
    'name': 'Test Login in the System ',
    'line': 1,
    'id': 'test-login-in-the System',
    'tags': [],
    'uri': 'features/login.feature',
    'elements': [
      {
        'id': 'test-login-in-the;admin-login-function-positive',
        'keyword': 'Scenario',
        'line': 2,
        'name': 'Admin Login function Positive',
        'tags': [],
        'type': 'scenario',
        'steps': [
          {
            'arguments': [],
            'keyword': 'Given ',
            'line': 3,
            'name': 'Navigate to home',
            'match': {
              'location': 'src/spec/login.spec.ts:13'
            },
            'result': {
              'status': 'passed',
              'duration': 2000000
            }
          },
          {
            'arguments': [],
            'keyword': 'Then ',
            'line': 4,
            'name': 'Admin positive Login',
            'match': {
              'location': 'src/spec/login.spec.ts:19'
            },
            'result': {
              'status': 'passed',
              'duration': 15156000000
            }
          },
          {
            'arguments': [],
            'keyword': 'Then ',
            'line': 5,
            'name': 'Admin Logout',
            'match': {
              'location': 'src/spec/login.spec.ts:24'
            },
            'result': {
              'status': 'passed',
              'duration': 8876000000
            }
          },
          {
            'arguments': [],
            'keyword': 'Then ',
            'line': 6,
            'name': 'Admin Negative Login',
            'match': {
              'location': 'src/spec/login.spec.ts:30'
            },
            'result': {
              'status': 'passed',
              'duration': 13136000000
            }
          },
          {
            'arguments': [],
            'keyword': 'Then ',
            'line': 7,
            'name': 'Validate Error Message',
            'match': {
              'location': 'src/spec/login.spec.ts:35'
            },
            'result': {
              'status': 'failed',
              'duration': 1704000000,
              'error_message': 'AssertionError: Error message not Validated !!\n    at Login.<anonymous> (/home/aux-120/Desktop/Automation/dev2/UIAutmoation/src/pages/LoginPage.ts:53:9)\n    at step (/home/aux-120/Desktop/Automation/dev2/UIAutmoation/src/pages/LoginPage.ts:32:23)\n    at Object.next (/home/aux-120/Desktop/Automation/dev2/UIAutmoation/src/pages/LoginPage.ts:13:53)\n    at fulfilled (/home/aux-120/Desktop/Automation/dev2/UIAutmoation/src/pages/LoginPage.ts:4:58)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)'
            }
         
          {
            'keyword': 'After',
            'hidden': true,
            'match': {
              'location': 'node_modules/protractor-cucumber-framework/lib/resultsCapturer.js:25'
            },
            'result': {
              'status': 'passed',
              'duration': 1000000
            }
          }
        ]
      }
    ]
  }
]

Then you can create index.js file to convert this to a nice HTML report.

var reporter = require('cucumber-html-reporter');
 
var options = {
        theme: 'bootstrap',
        jsonFile: 'src/report/cucumber_report.json',
        output: 'src/report/cucumber_report.html',
        screenshotsDirectory: 'src/screenshots/',
        storeScreenshots: false,
        reportSuiteAsScenarios: true,
        launchReport: true,
        metadata: {
            'App Version':'0.0.0',
            'Test Environment': '[server]',
            'Browser': 'Version 74.0.3729.169 (Official Build) (64-bit)',
            'Platform': 'Ubuntu 18.04',
            'Parallel': 'Scenarios',
            'Executed': 'Remote'
        }
    };
    reporter.generate(options);

Now you can run this via node

$ node index.js

It will generate HTML in

output: 'src/report/cucumber_report.html',

IT will look like this :

Reference: https://www.npmjs.com/package/cucumber-html-reporter#storescreenshots

For More Related Subjects: ZIWO API

UI Automation Test

Readings

Latest News

Interviews, tips, guides, industry best practices, and news.

left arrowright arrow

Stay up to date


Ziwo logo

Simply talk to your clients!

© 2023 Ziwo. All rights reserved.