jonsamwell / flutter_gherkin

A Gherkin parsers and runner for Dart and Flutter which is very similar to cucumber
MIT License
206 stars 113 forks source link

HTML Report Generation #14

Closed ajilo297 closed 5 years ago

ajilo297 commented 5 years ago

Is there any way we can generate an HTML report at the end?

jonsamwell commented 5 years ago

Currently not at the moment. I would think we could create a reporter that produces an intermediate output that a HTML reporter could then interpret. PR's are always welcome

ajilo297 commented 5 years ago

@jonsamwell Is there anyway this can be done...? Maybe there could be something I can build...?

jonsamwell commented 5 years ago

@ajilo297 see https://github.com/jonsamwell/flutter_gherkin/pull/17

Once the PR is merged in with the new Gherkin engine you will be able to generate HTML reports

jonsamwell commented 5 years ago

@ajilo297 this can now be achieved by using the JsonReporter then passing that json file to https://www.npmjs.com/package/cucumber-html-reporter see https://github.com/jonsamwell/flutter_gherkin#reporting

import 'dart:async';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
import 'package:glob/glob.dart';
import 'hooks/hook_example.dart';
import 'steps/given_I_pick_a_colour_step.dart';
import 'steps/tap_button_n_times_step.dart';

Future<void> main() {
  final config = FlutterTestConfiguration()
    ..features = [Glob(r"test_driver/features/**.feature")]
    ..reporters = [
      ProgressReporter(),
      TestRunSummaryReporter(),
      JsonReporter(path: './report.json')
    ] // you can include the "StdoutReporter()" without the message level parameter for verbose log information
    ..stepDefinitions = [TapButtonNTimesStep(), GivenIPickAColour()]
    ..restartAppBetweenScenarios = true
    ..targetAppPath = "test_driver/app.dart"
    ..exitAfterTestRun = true;
  return GherkinRunner().execute(config);
}
maheshj01 commented 5 years ago

@ajilo297 this can now be achieved by using the JsonReporter then passing that json file to https://www.npmjs.com/package/cucumber-html-reporter see https://github.com/jonsamwell/flutter_gherkin#reporting

import 'dart:async';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
import 'package:glob/glob.dart';
import 'hooks/hook_example.dart';
import 'steps/given_I_pick_a_colour_step.dart';
import 'steps/tap_button_n_times_step.dart';

Future<void> main() {
  final config = FlutterTestConfiguration()
    ..features = [Glob(r"test_driver/features/**.feature")]
    ..reporters = [
      ProgressReporter(),
      TestRunSummaryReporter(),
      JsonReporter(path: './report.json')
    ] // you can include the "StdoutReporter()" without the message level parameter for verbose log information
    ..stepDefinitions = [TapButtonNTimesStep(), GivenIPickAColour()]
    ..restartAppBetweenScenarios = true
    ..targetAppPath = "test_driver/app.dart"
    ..exitAfterTestRun = true;
  return GherkinRunner().execute(config);
}

thanks it really hepled I was able to generate a beautiful bootstrap html report

jonsamwell commented 5 years ago

Awesome!

vpkhachane commented 2 years ago

@jonsamwell I am trying to generate html report but facing issue. Please help me

import 'dart:async'; import 'package:flutter_gherkin/flutter_gherkin.dart'; import 'package:gherkin/gherkin.dart'; import 'package:glob/glob.dart'; import '../stepDefinitions/login_stepDef.dart';

Future main() { final config = FlutterTestConfiguration() ..features = [Glob(r"test_driver/features/**.feature")] ..reporters = [ TestRunSummaryReporter(), StdoutReporter(), JsonReporter(path: './report.json') ] ..hooks = [AttachScreenshotOnFailedStepHook()] ..stepDefinitions = [Login(), EmailID(), Password(), Submit()] ..restartAppBetweenScenarios = false ..targetAppPath = "test_driver/initApp/bdd.dart";

return GherkinRunner().execute(config); }

Index.js

var reporter = require('cucumber-html-reporter');

var options = { theme: 'bootstrap', jsonFile: './report.json', output: './cucumber_report.html', reportSuiteAsScenarios: true, scenarioTimestamp: true, launchReport: true, metadata: { "App Version":"0.3.2" } };

reporter.generate(options);

Getting following error

apple@apples-MacBook-Pro test_driver % node index.js node:internal/fs/utils:345 throw err; ^

Error: ENOENT: no such file or directory, scandir './report.json' at Object.readdirSync (node:fs:1401:3) at isValidJsonFile (/Users/apple/node_modules/cucumber-html-reporter/lib/reporter.js:511:48) at Object.generate (/Users/apple/node_modules/cucumber-html-reporter/lib/reporter.js:540:9) at Object.generateReport [as generate] (/Users/apple/node_modules/cucumber-html-reporter/index.js:30:21) at Object. (/Users/apple/Desktop/Xendit/XenditAppSourceCode/mobilestoreautomationbddframework/test_driver/index.js:15:14) at Module._compile (node:internal/modules/cjs/loader:1097:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) { errno: -2, syscall: 'scandir', code: 'ENOENT', path: './report.json' }

jonsamwell commented 2 years ago

Looks like you just have the wrong path your check where the report.json is being saved to and error the js script is pointing to the right place