如何检查我们是否在Flutter集成中的特定页面?

huangapple go评论69阅读模式
英文:

How to check we are in a specific page in Flutter integration or not?

问题

我正在为我的Flutter应用编写集成测试。
在应用程序启动时,根据用户是否已登录,它可以位于HomePage()或OnBoardingPage()之一。

如何在集成测试中确定它位于哪个页面?

testWidgets('测试OnBoarding阶段', (tester) async {
  app.main();
  await tester.pumpAndSettle();
  
  final homePageFinder = find.byKey(
    const Key("homePage"),
  );
  final onBoardingFinder = find.byKey(
    const Key("onBoarding"),
  );
})
英文:

I am writing Integration test for my Flutter app.
at the start of app depends on that the user have logged in it can be on
HomePage() or OnBoardingPage()

how can I find out in which page it is in Integration test

  testWidgets('test onBoarding phase', (tester) async {
app.main();
await tester.pumpAndSettle();

 final homePageFinder = find.byKey(
  const Key("homePage"),
);
final onBoardingFinder = find.byKey(
  const Key("onBoarding"),
);
)}

答案1

得分: 1

你可以使用tester.any()方法,该方法检查树中是否存在查找器,例如使用方法:

bool isHomePage = tester.any(homePageFinder);
bool isOnBoarding = tester.any(onBoardingFinder);
英文:

you can use tester.any() method,which checks if finder exists in the tree,to use it you can for example:

bool isHomePage = tester.any(homePageFinder);
bool isOnBoarding = tester.any(onBoardingFinder);

huangapple
  • 本文由 发表于 2023年5月21日 00:32:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定