[英]Flutter Integration Testing- How to go back to previous screen when no back button available on screen
How to go back to previous screen when no back button available on screen?当屏幕上没有后退按钮时,如何 go 返回上一屏幕? Additional Information: I am trying to automate integration testing for flutter app.附加信息:我正在尝试对 flutter 应用程序进行自动化集成测试。 There is no back button on screen which I can use to go back screen.屏幕上没有可用于 go 后退屏幕的后退按钮。 Additional information: I am writing integration tests, for same I need to go back to previous screen.附加信息:我正在编写集成测试,同样我需要 go 返回上一个屏幕。 And due to design there is no back button on screen, I need to do by scripts only.由于设计原因,屏幕上没有后退按钮,我只需要通过脚本来完成。
If the purpose of the test is to stress and verify the WillPopScope
callbacks as well, the following approach can be used:如果测试的目的也是强调和验证WillPopScope
回调,则可以使用以下方法:
final dynamic widgetsAppState = _._tester.state(find.byType(WidgetsApp));
await widgetsAppState.didPopRoute();
This is used in the Flutter official repository for testing: https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/will_pop_test.dart这个在Flutter官方仓库中用于测试: https ://github.com/flutter/flutter/blob/master/packages/flutter/test/material/will_pop_test.dart
Note that this approach also works to simulate a back button pressed on Android.请注意,此方法也适用于模拟在 Android 上按下的后退按钮。
This is what worked for me for OpenContainers from the animations package:这就是动画包中 OpenContainers 对我有用的东西:
final NavigatorState navigator = tester.state(find.byType(Navigator));
navigator.pop();
await tester.pump();
It's used in the flutter package's tests:它用于 flutter 包的测试:
https://github.com/flutter/packages/blob/63040337424f345452a5e07632774e6585329ac0/packages/animations/test/open_container_test.dart#L234 https://github.com/flutter/packages/blob/63040337424f345452a5e07632774e6585329ac0/packages/animations/test/open_container_test.dart#L234
Well, it's maybe a little bit late, however there are two possible ways to achieve this:好吧,这可能有点晚了,但是有两种可能的方法可以实现这一目标:
final backButton = find.byTooltip('Back');
await driver.tap(backButton);
or:要么:
await driver.tap(find.pageBack());
you can use like this as ios provided你可以像这样使用 ios 提供的
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}
)
),
My emulador defaulf locale is "en_US" so I use the word "Back" as tooltip and it is working.我的 emulador 默认语言环境是“en_US”,所以我使用“返回”这个词作为工具提示,它正在工作。
final backButton = find.byTooltip("Back");
await tester.tap(backButton);
await tester.pumpAndSettle();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.