我是一个非常新的颤振和Gherkin,我试图遵循本教程,以实现测试与Gherkin在颤振为一个简单的反测试。
问题是,当我尝试在我的macOS终端上运行测试时,我使用:
dart test_driver/app_test.dart --feature="counter_button.feature"我不断地发现错误:
Error: The argument type 'FlutterDriver?' can't be assigned to the parameter type 'FlutterDriver' because 'FlutterDriver?' is nullable and 'FlutterDriver' isn't.
- 'FlutterDriver' is from 'package:flutter_driver/src/driver/driver.dart' ('../../Downloads/flutter/packages/flutter_driver/lib/src/driver/driver.dart').
var counterVal = await FlutterDriverUtils.getText(world.driver, locator);这是我的counter_button.feature文件:
Feature: Counter Button
As a user
I want to tap the plus button
So that I can see the counter increment
Scenario: User taps on counter button
Given the user is at the counter dashboard
And the counter value is at 0
When the user taps on the plus button
Then the counter value is at 1这是我的counter_button_steps.dart代码:
import 'package:flutter_driver/flutter_driver.dart';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
class UserIsInDashboardStep extends GivenWithWorld<FlutterWorld> {
@override
Future<void> executeStep() async {
final locator = find.text('You have pushed the button this many times:');
var locatorExists = await FlutterDriverUtils.isPresent(world.driver, locator);
expectMatch(true, locatorExists);
}
@override
RegExp get pattern => RegExp(r"the user is at the counter dashboard");
}
class CounterValueStep extends And1WithWorld<int, FlutterWorld> {
@override
Future<void> executeStep(int expectedVal) async {
final locator = find.byValueKey('counter-val-key');
var counterVal = await FlutterDriverUtils.getText(world.driver, locator);
expectMatch(expectedVal, int.parse(counterVal));
}
@override
RegExp get pattern => RegExp(r"the counter value is at {int}");
}
class UserTapsIncrementButton extends WhenWithWorld<FlutterWorld> {
@override
Future<void> executeStep() async {
final locator = find.byTooltip('Increment');
await FlutterDriverUtils.tap(world.driver, locator);
}
@override
RegExp get pattern => RegExp(r"the user taps on the plus button");
}我在我的main.dart文件中有一个小部件的密钥:
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
key: Key('counter-val-key'),
style: Theme.of(context).textTheme.displaySmall,
),
],我有flutter_gherkin:^2.0.0依赖项。最后,这是我的app_test.dart代码:
import 'dart:async';
import 'dart:io';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
import 'package:glob/glob.dart';
import 'steps/counter_button_steps.dart';
Future<void> main() {
final config = FlutterTestConfiguration()
..features = [Glob(r"test_driver/features/**.feature")]
..reporters = [
ProgressReporter(),
TestRunSummaryReporter(),
JsonReporter(path: './report.json')
]
..hooks = []
..stepDefinitions = [
UserIsInDashboardStep(),
CounterValueStep(),
UserTapsIncrementButton()
]
..customStepParameterDefinitions = [
]
..restartAppBetweenScenarios = true
..targetAppPath = "test_driver/app.dart"
..targetDeviceId = 'macos'
..keepAppRunningAfterTests = false;
return GherkinRunner().execute(config);
}这个问题似乎只发生在getText方法中。我没有遇到isPresent(world.driver,定位器)或tap(world.driver,定位器)的任何问题。
发布于 2022-11-28 01:36:23
试着改变
world.driver使用
world.driver!只需在其末尾添加!即可。
https://stackoverflow.com/questions/74595058
复制相似问题