Skip to content

Commit

Permalink
remove all usages of integration_test's members
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia authored and jBorkowska committed Nov 10, 2023
1 parent a4cd451 commit 3de5c84
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
36 changes: 35 additions & 1 deletion packages/patrol/lib/src/binding.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/common.dart';
import 'package:patrol/patrol.dart';
import 'package:patrol/src/devtools_service_extensions/devtools_service_extensions.dart';
// ignore: implementation_imports, depend_on_referenced_packages
Expand Down Expand Up @@ -237,3 +238,36 @@ class PatrolBinding extends LiveTestWidgetsFlutterBinding {
// See: https://github.com/flutter/flutter/issues/81534
}
}

/// Representing a failure includes the method name and the failure details.
class Failure {
/// Constructor requiring all fields during initialization.
Failure(this.methodName, this.details);

/// The name of the test method which failed.
final String methodName;

/// The details of the failure such as stack trace.
final String? details;

/// Serializes the object to JSON.
String toJson() {
return json.encode(<String, String?>{
'methodName': methodName,
'details': details,
});
}

@override
String toString() => toJson();

/// Decode a JSON string to create a Failure object.
// ignore: prefer_constructors_over_static_methods
static Failure fromJsonString(String jsonString) {
final failure = json.decode(jsonString) as Map<String, dynamic>;
return Failure(
failure['methodName'] as String,
failure['details'] as String?,
);
}
}
23 changes: 3 additions & 20 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io' as io;

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:meta/meta.dart';
import 'package:patrol/src/binding.dart';
import 'package:patrol/src/global_state.dart' as global_state;
Expand Down Expand Up @@ -37,9 +36,6 @@ typedef PatrolTesterCallback = Future<void> Function(PatrolIntegrationTester $);
/// },
/// );
/// ```
///
/// [bindingType] specifies the binding to use. [bindingType] is ignored if
/// [nativeAutomation] is false.
@isTest
void patrolTest(
String description,
Expand All @@ -52,7 +48,6 @@ void patrolTest(
finders.PatrolTesterConfig config = const finders.PatrolTesterConfig(),
NativeAutomatorConfig nativeAutomatorConfig = const NativeAutomatorConfig(),
bool nativeAutomation = false,
BindingType bindingType = BindingType.patrol,
LiveTestWidgetsFlutterBindingFramePolicy framePolicy =
LiveTestWidgetsFlutterBindingFramePolicy.fadePointers,
}) {
Expand All @@ -72,21 +67,9 @@ void patrolTest(
}

if (nativeAutomation) {
switch (bindingType) {
case BindingType.patrol:
automator = NativeAutomator(config: nativeAutomatorConfig);

patrolBinding = PatrolBinding.ensureInitialized(nativeAutomatorConfig);
patrolBinding.framePolicy = framePolicy;
break;
case BindingType.integrationTest:
IntegrationTestWidgetsFlutterBinding.ensureInitialized().framePolicy =
framePolicy;

break;
case BindingType.none:
break;
}
automator = NativeAutomator(config: nativeAutomatorConfig);
patrolBinding = PatrolBinding.ensureInitialized(nativeAutomatorConfig)
..framePolicy = framePolicy;
}

testWidgets(
Expand Down
16 changes: 1 addition & 15 deletions packages/patrol/lib/src/native/native_automator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:io' as io;

import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:integration_test/integration_test.dart';
import 'package:meta/meta.dart';
import 'package:patrol/src/binding.dart';
import 'package:patrol/src/native/contracts/contracts.dart';
import 'package:patrol/src/native/contracts/contracts.dart' as contracts;
import 'package:patrol/src/native/contracts/contracts.dart';
import 'package:patrol/src/native/contracts/native_automator_client.dart';

/// Thrown when a native action fails.
Expand All @@ -21,18 +19,6 @@ class PatrolActionException implements Exception {
String toString() => 'Patrol action failed: $message';
}

/// Bindings available to use with [NativeAutomator].
enum BindingType {
/// Initialize [PatrolBinding].
patrol,

/// Initializes [IntegrationTestWidgetsFlutterBinding]
integrationTest,

/// Doesn't initialize any binding.
none,
}

/// Specifies how the OS keyboard should behave when using
/// [NativeAutomator.enterText] and [NativeAutomator.enterTextByIndex].
enum KeyboardBehavior {
Expand Down

0 comments on commit 3de5c84

Please sign in to comment.