简体   繁体   English

Flutter 集成测试- go 屏幕上没有后退按钮时如何返回上一屏幕

[英]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.

相关问题 刷新页面浏览量颤动中的屏幕时如何返回上一页 - how to go back to previous page when refresh the screen in pageview flutter Flutter - 如何对 go 执行“草率”返回手势返回上一屏幕? - Flutter - How to implement a 'sloppy' back gesture to go back to previous screen? 颤动小部件测试 - 如何执行测试以“返回上一个屏幕” - flutter widget testing - how to execute test to "Go Back to Prevoius Screen" 在 Flutter 中按下设备后退按钮时如何转到上一个选项卡? - How to go to the previous Tab when the Device Back Button is pressed in Flutter? 如何返回上一个屏幕并重新加载第一个屏幕的所有功能? - How to go back to the previous screen and reload all function of the first screen? 返回上一个屏幕时如何获取价值? - How to catch value when back to previous screen? 如何通过单击 Flutter 中的底部导航栏项 go 返回上一屏幕 - How to go back to previous screen by clicking on bottom navigation bar item in Flutter 在颤动中,按下后退按钮时如何返回上一个 URL? - In flutter how can I go back to previous URL when the back button is pressed? 如何使用 Navigator 将数据传递到 Flutter 中的上一个屏幕? (需要处理所有情况:滑动返回,按下返回等) - How to pass data to previous screen in Flutter using Navigator? (need to handle all cases: swipe to go back, press back, etc) Flutter:当我将 go 转到新屏幕并返回 go 时,如何保持我选择的导航器 - Flutter: How can I keep to my selected navigator when I'll go to a new screen and go back
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM