英文:
Flutter> Patrol > Mobile automatization test: How to access to "Subscribe" button on system pop-up Google Play Store?
问题
I'm trying to purchase a subscription in my tests. Everything goes well until the native Android purchase popup appears. I'm not able to tap on the green 'Subscribe' button. Is there a way to do it? The following code doesn't work:
See screenshot - which button is the problem
void main() async {
group('App', () {
patrolTest('Buy Subscription', nativeAutomation: true, (PatrolTester tester) async {
await app.main();
await tester.pumpAndSettle();
await tester(ElevatedButton).tap();
await tester.native.tap(Selector(text: 'Subscribe'));
});
});
}
Thank you for your help!
英文:
I'm trying to purchase a subscription in my tests. Everything goes well until the native Android purchase popup appears. I'm not able to tap on the green 'Subscribe' button. Is there a way to do it? The following code doesn't work:
** See screenshot - which button is the problem **
void main() async {
group('App', () {
patrolTest('Buy Subscription', nativeAutomation: true, ( PatrolTester tester) async {
await app.main();
await tester.pumpAndSettle();
await tester(ElevatedButton).tap();
await tester.native.tap(Selector(text: 'Subscribe')); });}); }
Thanks you for your help!
答案1
得分: 1
我建议您在屏幕上看到“Subscribe”按钮时获取视图层次结构转储(在测试运行时不要执行此操作):
adb shell uiautomator dump && adb pull /sdcard/window_dump.xml .
然后在某个代码编辑器中打开window_dump.xml
文件,使用CTRL+F查找“Subscription”,看看按钮是否在那里可见。也许text
属性未设置,但contentDescription
设置了?所以您可以尝试:
await tester.native.tap(Selector(contentDescription: 'Subscribe'));
英文:
I suggest you take a view hierarchy dump while you see the "Subscribe" button on-screen (you mustn't to do it while the test is running):
adb shell uiautomator dump && adb pull /sdcard/window_dump.xml .
Then open the window_dump.xml
file in some code editor, CTRL+F for "Subscription" and see if the button is visible there. Maybe the text
attribute is not set, but contentDescription
is? So you could try doing:
await tester.native.tap(Selector(contentDescription: 'Subscribe'));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论