Skip to content

fix: Action creation issue #417

Description

@alejandro-rios

Description

I'm trying to implement a new action based in this issue, I'm following the expect_environment_text example on the examples project, but, when I run this new action I'm getting

Steps To Reproduce

  1. Clone example project from Fluttium repo
  2. Copy and paste expect_environment_text in order to create a new action with alt_write_text as name.
  3. Rename files according to the action.
  4. Replace writeText with altWriteText
  5. Run fluttium test flows/text_flow.yaml --flavor development --target lib/main_development.dart
  6. See error.

Expected Behavior

The fluttium action should work.

Screenshots

Screenshot 2024-08-16 at 15 45 08

Additional Context

Here's the version of AltWriteText that I'm using:

import 'package:flutter/services.dart';
import 'package:fluttium/fluttium.dart';
import 'package:fluttium/src/text_input_controller.dart';

/// {@template alt_write_text}
/// workaround for typing in a textField.
///
/// This action can be invoked using the short-hand version:
///
/// ```yaml
/// - altWriteText:
/// ```
/// {@endtemplate}
class AltWriteText extends Action {
  /// {@macro alt_write_text}
  AltWriteText({
    required this.text,
  });

  final _textInputController = TextInputController();
  final String text;

  Future<void> _enterText(Tester tester, String text) async {
    _textInputController.value = _textInputController.value.copyWith(
      text: text,
      selection: TextSelection.collapsed(offset: text.length),
    );

    tester.emitPlatformMessage(
      SystemChannels.textInput.name,
      SystemChannels.textInput.codec.encodeMethodCall(
        MethodCall(
          'TextInputClient.updateEditingState',
          [-1, _textInputController.value.toJSON()],
        ),
      ),
    );
  }

  /// Called when it executes the action in a flow file.
  @override
  Future<bool> execute(Tester tester) async {
    TextInput.setInputControl(_textInputController);
    tester.emitPlatformMessage(
      SystemChannels.textInput.name,
      SystemChannels.textInput.codec.encodeMethodCall(
        const MethodCall('TextInputClient.requestExistingInputState'),
      ),
    );
    TextInput.restorePlatformInputControl();

    // Temporary workaround, enter whole text instead of character by character
    await _enterText(tester, text);
    await tester.pumpAndSettle();

    return true;
  }

  @override
  String description() => 'Some text to write "$text"';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions