Android Espresso UI 测试中的 if else 情况
在应用程序中,我正在为应用程序中的登录流量编写浓缩咖啡UI测试。我编写了测试,效果很好,但是我有一个有问题的情况。
在此应用程序中,用户有时在打开应用程序时会获得奖金(通常不会,但这是1:100场景) 在这些情况下,弹出窗口出现在屏幕上,我的测试失败了,因为我的代码试图触发不可见的按钮(它在弹出窗口下)。
我想在测试中写入if-else,例如我可以在其中检查弹出式关闭按钮的可见性。因此,如果可见,请单击它,如果不是,请正常继续。
但是我在UI测试中没有找到任何IF-ELSE语法。在UI浓缩咖啡测试方面拥有更多经验的人可以在这里帮助我吗?谢谢
In the application, I am writing Espresso UI test for login flow in the app. I wrote the test and it works fine, but I have one case where I have problem.
In this application, users sometimes get bonuses when opening app (usually they don't but this is let's say 1:100 scenario)
In these situations, the pop up appears on the screen and my test fails because my code tries to trigger the button that is not visible (it is under the pop up).
I would like to write if-else in a test where I can for example check the visibility of the pop up close button. So if this is visible click on it and if it's not, then continue normally.
But I didn't find any if-else syntax in UI testing. Can someone with more experience in UI espresso testing help me with some advice here? THanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建两个测试。一个无法出现奖励弹出窗口的地方,一个总是出现奖励弹出窗口的地方。这样,可以测试这两种行为。
您不应该留下任何机会,而您的问题正是为什么不这样做的例子。
Create two tests. One where bonus popup cannot appear and one where bonus popup always appears. This way so can test both behaviours.
You should not leave anything to a chance, and your issue is exactly the example of why not.
我同意Primož,您不应该进行不确定的测试。但是,如果不可能,您总是可以使用特定例外的尝试/捕获,以尝试在测试前关闭弹出窗口。
这样的事情可能会起作用(如果您没有弹出视图时,可能需要根据确切的例外投掷进行调整。
I agree with Primož that you should not have an indeterminate test. But, if that is not possible, you could always use a try/catch with a specific exception to attempt to close the popup before the test.
Something like this might work (may need to tweak the catch depending on the exact exception throw when you do not have the popup view.