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

Pre-included Step Definitions Not Found #261

Open adam-clevyr opened 2 years ago

adam-clevyr commented 2 years ago

When I run a feature using step definitions from _wellKnownStepDefinitions the tests fail due to not finding step definitions.

Expected:

Actual:

I/flutter (13785):    √ Given I wait until the "loginForm_usernameInput_textField" is present # :0 took 2634ms
I/flutter (13785):    × When I fill the “loginForm_usernameInput_textField“ field with “john@example.com“ # :0 took 0ms  
I/flutter (13785): GherkinStepNotDefinedException: Step definition not found for text: `When I fill the “loginForm_usernameInput_textField“ field with “john@example.com“`
I/flutter (13785): #0      GherkinIntegrationTestRunner.runStep (package:flutter_gherkin/src/flutter/runners/gherkin_integration_test_runner.dart:337:9)
I/flutter (13785): #1      _CustomGherkinIntegrationTestRunner.testFeature0.<anonymous closure>.<anonymous closure>
(file:///Users/myname/Documents/Projects/projname/flutter-application/integration_test/gherkin_suite_test.g.dart:57:28)
I/flutter (13785): #2      _CustomGherkinIntegrationTestRunner.testFeature0.<anonymous closure>.<anonymous closure>
(file:///Users/myname/Documents/Projects/projname/flutter-application/integration_test/gherkin_suite_test.g.dart:53:13)
I/flutter (13785): #3      GherkinIntegrationTestRunner.runScenario.<anonymous closure> (package:flutter_gherkin/src/flutter/runners/gherkin_integration_test_runner.dart:224:46)
I/flutter (13785): <asynchronous 
I/flutter (13785): FAILED: Scenario Fill out email field # ./integration_test/features/simple_login.feature:0

NOTE: This is using the following pre-included step definitions

My files:

Feature File

path: integration_test/features/simple_login.feature

Feature: Enter Email on Login Form
  The user should be able to enter an email address on the login form

  Scenario: Fill out email field
    Given I wait until the "loginForm_usernameInput_textField" is present
    When I fill the “loginForm_usernameInput_textField“ field with “john@example.com“

Configuration File

path: integration_test/gherkin/configuration.dart

import 'package:flutter/widgets.dart';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my-package-name/main_dev.dart' as mainApp;
import 'world/custom_world.dart';

FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
  features: ['simple_login.feature'],
  reporters: [
    StdoutReporter(MessageLevel.error)
      ..setWriteLineFn(print)
      ..setWriteFn(print),
    ProgressReporter()
      ..setWriteLineFn(print)
      ..setWriteFn(print),
    TestRunSummaryReporter()
      ..setWriteLineFn(print)
      ..setWriteFn(print),
    JsonReporter(
      writeReport: (_, __) => Future<void>.value(),
    ),
  ], // Reporters
  createWorld: (config) => Future.value(CustomWorld()),
);

Future<void> Function(World) appInitializationFn = (World world) async {
  // runApp
  mainApp.main();
};

The GENERATED test suite file

path: integration_test/gherkin_suite_test.g.dart

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'gherkin_suite_test.dart';

// **************************************************************************
// GherkinSuiteTestGenerator
// **************************************************************************

class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
  _CustomGherkinIntegrationTestRunner({
    required FlutterTestConfiguration configuration,
    required StartAppFn appMainFunction,
    required Timeout scenarioExecutionTimeout,
    AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
    LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
  }) : super(
          configuration: configuration,
          appMainFunction: appMainFunction,
          scenarioExecutionTimeout: scenarioExecutionTimeout,
          appLifecyclePumpHandler: appLifecyclePumpHandler,
          framePolicy: framePolicy,
        );

  @override
  void onRun() {
    testFeature0();
  }

  void testFeature0() {
    runFeature(
      name: 'Enter Email on Login Form:',
      tags: <String>[],
      run: () {
        runScenario(
          name: 'Fill out email field',
          description: null,
          path: './integration_test/features/simple_login.feature',
          tags: <String>[],
          steps: [
            (
              TestDependencies dependencies,
              bool skip,
            ) async {
              return await runStep(
                name:
                    'Given I wait until the "loginForm_usernameInput_textField" is present',
                multiLineStrings: <String>[],
                table: null,
                dependencies: dependencies,
                skip: skip,
              );
            },
            (
              TestDependencies dependencies,
              bool skip,
            ) async {
              return await runStep(
                name:
                    'When I fill the “loginForm_usernameInput_textField“ field with “john@example.com“',
                multiLineStrings: <String>[],
                table: null,
                dependencies: dependencies,
                skip: skip,
              );
            },
          ],
          onBefore: () async => onBeforeRunFeature(
            name: 'Simple Login',
            path: './integration_test/features/simple_login.feature',
            description:
                """The user should be able to login with email and password""",
            tags: <String>[],
          ),
          onAfter: () async => onAfterRunFeature(
            name: 'Simple Login',
            path: './integration_test/features/simple_login.feature',
            description:
                """The user should be able to login with email and password""",
            tags: <String>[],
          ),
        );
      },
    );
  }
}

void executeTestSuite({
  required FlutterTestConfiguration configuration,
  required StartAppFn appMainFunction,
  Timeout scenarioExecutionTimeout = const Timeout(const Duration(minutes: 10)),
  AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
  LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
}) {
  _CustomGherkinIntegrationTestRunner(
    configuration: configuration,
    appMainFunction: appMainFunction,
    appLifecyclePumpHandler: appLifecyclePumpHandler,
    scenarioExecutionTimeout: scenarioExecutionTimeout,
    framePolicy: framePolicy,
  ).run();
}

General info:

flutter doctor -v

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale en-US)
    • Flutter version 3.0.5 at /Users/myname/Documents/Projects/flutterInstall/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (5 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/myname/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] Connected device (1 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)

Parts of my pubspec.yaml


dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl: ^0.17.0

  path_provider: ^2.0.11
  freerasp: ^3.0.1
  local_auth: ^2.1.1
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.5
  flutter_bloc: ^8.0.1
  equatable: ^2.0.3
  device_info_plus: ^4.0.1
  go_router: ^4.2.7
  yaml: ^3.1.1
  flutter_flavorizr: ^2.1.3
  dio: ^4.0.6
  freezed_annotation: ^2.1.0
  json_annotation: ^4.6.0
  formz: ^0.4.1
  hydrated_bloc: ^9.0.0-dev.3

dev_dependencies:
  flutter_gherkin: ^3.0.0-rc.17
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter
  build_runner: ^2.2.0
jonsamwell commented 2 years ago

Sorry for the delay. Thanks for the code I will try and reproduce this and fix as required.

adam-clevyr commented 2 years ago

Sorry for the delay. Thanks for the code I will try and reproduce this and fix as required.

No worries! Let me know if I need to provide further information!