我有一些自定义的TextFiels,它们用于输入图钉,我称它们为HookWidget
。当我使用颤振驱动器运行集成测试时,除最后一个输入字段外,所有输入字段都会收到给定的文本,并停止运行测试。
这是代码:
附言:我正在使用 final focusNodes = List.generate(6, (_) => new FocusNode());
final values = List.generate(6, (_) => useState<String>(''));
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
for (int i = 0; i < values.length; i++)
PinInputField(
key: ValueKey('$i'),
width: MediaQuery.of(context).size.width / 11.71,
height: 80,
fontSize: 50,
marginRight: 16,
input: values[i],
focusNode: focusNodes[i],
nextFocusNode: i == 5 ? null : focusNodes[i + 1],
)
],
)
test('test main card settings items', () async {
final cardSettingsItem = find.byValueKey('settings.cardSettings');
final mainSettingsList = find.byValueKey('mainSettingsList');
final profileButton = find.byValueKey('Profile');
final changePinButton = find.byValueKey('Cambiar pin');
final changePinInputField0 = find.byValueKey('0');
final changePinInputField1 = find.byValueKey('1');
final changePinInputField2 = find.byValueKey('2');
final changePinInputField3 = find.byValueKey('3');
final changePinInputField4 = find.byValueKey('4');
final changePinInputField5 = find.byValueKey('5');
final changePinScreenButton = find.byValueKey('changePinScreenButton');
sleep(Duration(seconds: 3));
await driver.tap(profileButton);
sleep(Duration(seconds: 2));
await driver.scrollIntoView(mainSettingsList);
sleep(Duration(seconds: 3));
await driver.tap(cardSettingsItem);
sleep(Duration(seconds: 3));
await driver.tap(changePinButton);
sleep(Duration(seconds: 4));
await driver.tap(changePinInputField0);
sleep(Duration(seconds: 2));
await driver.enterText("0");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField1);
sleep(Duration(seconds: 2));
await driver.enterText("1");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField2);
sleep(Duration(seconds: 2));
await driver.enterText("2");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField3);
sleep(Duration(seconds: 2));
await driver.enterText("3");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField4);
sleep(Duration(seconds: 2));
await driver.enterText("4");
sleep(Duration(seconds: 4));
await driver.tap(changePinInputField5);
sleep(Duration(seconds: 1));
await driver.enterText("5");
sleep(Duration(seconds: 5));
await driver.tap(changePinScreenButton);
sleep(Duration(seconds: 4));
});
这是测试:
DriverError: Failed to fulfill Tap due to remote error
Original error: Bad state: The client closed with pending request "ext.flutter.driver".
Original stack trace:
#0 new Client.withoutJson.<anonymous closure> (package:json_rpc_2/src/client.dart:70:24)
#1 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:209:15)
#2 StackZoneSpecification._registerCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:119:48)
#3 _rootRun (dart:async/zone.dart:1120:38)
#4 _CustomZone.run (dart:async/zone.dart:1021:19)
#5 _FutureListener.handleWhenComplete (dart:async/future_impl.dart:150:18)
#6 Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:609:39)
#7 Future._propagateToListeners (dart:async/future_impl.dart:665:37)
#8 Future._propagateToListeners (dart:async/future_impl.dart:566:9)
#9 Future._completeWithValue (dart:async/future_impl.dart:483:5)
#10 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:513:7)
#11 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:209:15)
#12 StackZoneSpecification._registerCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:119:48)
#13 _rootRun (dart:async/zone.dart:1124:13)
#14 _CustomZone.run (dart:async/zone.dart:1021:19)
#15 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#16 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#17 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#18 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#19 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:391:30)
#20 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
#21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
,这是日志:
string.punctuation
答案 0 :(得分:2)
当测试在实际完成之前超时时,通常会发生此问题。用于运行测试的默认超时为30秒,此处您的睡眠时间总计超过30秒,因此连接由于未决请求而关闭。
我不明白为什么每次动作后都要睡一定时间,可能是因为您可以减少/减少睡眠。如果您的情况是必须睡觉,请尝试将适当的timeout
通过测试。
示例:
test(
'test main card settings items',
() async {
final cardSettingsItem = find.byValueKey('settings.cardSettings');
final mainSettingsList = find.byValueKey('mainSettingsList');
final profileButton = find.byValueKey('Profile');
final changePinButton = find.byValueKey('Cambiar pin');
final changePinInputField0 = find.byValueKey('0');
final changePinInputField1 = find.byValueKey('1');
final changePinInputField2 = find.byValueKey('2');
final changePinInputField3 = find.byValueKey('3');
final changePinInputField4 = find.byValueKey('4');
final changePinInputField5 = find.byValueKey('5');
final changePinScreenButton = find.byValueKey('changePinScreenButton');
sleep(Duration(seconds: 3));
await driver.tap(profileButton);
sleep(Duration(seconds: 2));
await driver.scrollIntoView(mainSettingsList);
sleep(Duration(seconds: 3));
await driver.tap(cardSettingsItem);
sleep(Duration(seconds: 3));
await driver.tap(changePinButton);
sleep(Duration(seconds: 4));
await driver.tap(changePinInputField0);
sleep(Duration(seconds: 2));
await driver.enterText("0");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField1);
sleep(Duration(seconds: 2));
await driver.enterText("1");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField2);
sleep(Duration(seconds: 2));
await driver.enterText("2");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField3);
sleep(Duration(seconds: 2));
await driver.enterText("3");
sleep(Duration(seconds: 1));
await driver.tap(changePinInputField4);
sleep(Duration(seconds: 2));
await driver.enterText("4");
sleep(Duration(seconds: 4));
await driver.tap(changePinInputField5);
sleep(Duration(seconds: 1));
await driver.enterText("5");
sleep(Duration(seconds: 5));
await driver.tap(changePinScreenButton);
sleep(Duration(seconds: 4));
},
timeout: Timeout(
Duration(minutes: 2),
),
);
希望有帮助!
答案 1 :(得分:1)
我也一直在尝试默认的30秒超时。当Flutter Driver测试在远程CI / CD上运行时,这只是一个问题。本地测试运行良好。我做了两件事似乎适用于远程CI / CD:
timeout
@Hemanth。谢谢@Hemanth??!clearTimeline()
。 test('Home page should properly work', () async {
await driver.clearTimeline();
await HomePage(driver).appears()
.then((a) => a.exploreHomePage());
},
timeout: Timeout(
Duration(minutes: 2),
),
);
注意:
实现timeout
和clearTimeline()
可以完成运行时间更长的测试。但是我建议无论大小如何都添加到每个测试中。我也最初尝试过sleeps
,最终在使用timeout
和clearTimeline()
之后将它们全部删除。
希望这会有所帮助。
答案 2 :(得分:0)
我希望我的发现能够帮助某人。
我收到错误消息“ DriverError:由于远程错误而无法执行Tap”和“ VMServiceFlutterDriver:tap消息需要很长时间才能完成。”
就我而言,由于我使用的是'find.byType',因此Flutter Driver无法找到要测试的小部件。一次,我为所有窗口小部件提供了密钥,并传递给使用“ find.byValueKey”,这些窗口小部件已本地化,并且一切正常。
那是我的代码:
void main() {
group('reversor app integration test', () {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() {
if (driver != null) {
driver.close();
}
});
// find.byType was the cause for the error 'DriverError: Failed to fulfill Tap due to remote error'
// Given key for the three below widgets, and after hat using 'find.byValueKey', solved the problem
var field = find.byValueKey("TextField");
var btn = find.byValueKey("button");
var reverse = find.byValueKey("response");
test('Reversing the string', () async {
await driver.clearTimeline();
await driver.tap(field);
await driver.enterText("Hello222");
await driver.waitForAbsent(reverse);
await driver.tap(btn);
await driver.waitFor(reverse);
await driver.waitUntilNoTransientCallbacks();
assert(reverse != null);
});
});
}
答案 3 :(得分:-1)
请检查app_test.dart和UI dart文件两侧的密钥。我通过更正两侧的键来解决此问题。谢谢