英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论