[英]Handling popups with Appium in a native app
I am using Appium to automate a native iOS and Android app using Java. 我正在使用Appium使用Java自动执行本机iOS和Android应用程序。 The app features a Login/Logout proccess, which I execute in the start/end of every test case, and while logged in the app, apart from all the actions that I can do there, there are many random pop-ups for "Rate us" system, enabling Notifications, Locations usage and many more. 该应用程序具有“登录/注销”过程,我在每个测试用例的开始/结束时都执行该过程,并且在登录该应用程序时,除了可以在其中执行的所有操作外,还有许多用于“费率”的随机弹出窗口我们”系统,从而启用“通知”,“位置使用情况”等等。 The problem is that some of those pop-ups are coded to appear in different intervals even at random times, so what I am doing now is waiting to dismiss them in the start of each and every case after Login (This takes a lot of time for all the pop-ups to appear). 问题是,其中一些弹出窗口被编码为即使在随机时间也以不同的间隔出现,所以我现在要做的是等待登录后在每种情况下都将其关闭(这需要很多时间让所有弹出式窗口都显示)。
Is there a way to wait throughout the whole case for the popup(s) to appear and then be dismissed, while executing the other steps, or is the only workaround to dismiss all the popups before executing the rest of the case? 是否有办法在整个案例中等待弹出窗口出现,然后在执行其他步骤时将其关闭,还是在执行其余案例之前消除所有弹出窗口的唯一解决方法?
We've had similar problems and the best solution we have found so far is to implement the pop-ups and the tests so that the behavior of the app is always consistent in testing situation. 我们也遇到过类似的问题,到目前为止,我们发现的最佳解决方案是实施弹出窗口和测试,以使应用程序的行为在测试情况下始终保持一致。 However, even though there is no actual built in support for this, we have used variation of the following successfully. 但是,即使对此没有实际的内置支持,我们也成功地使用了以下内容的变体。 This is in python/pseudocode, but I don't think it should be much different in Java. 这是在python / pseudocode中,但我认为Java中应该没有太大不同。
In this you handle the element you wish, unless it is not found, in which case we assume there are pop-ups over it. 在这种情况下,您可以处理所需的元素,除非找不到该元素,否则在这种情况下,我们会假设它上方有弹出窗口。 We handle the pop-ups first and finally should find the element we need. 我们首先处理弹出窗口,最后应该找到所需的元素。
def handle_element_x(self, timeout):
"""handles element x unless there are popups overlapping it.
"""
while elapsed_time < timeout:
if appium._is_element_present(element_x_locator):
// handle element x and return
return True
if appium._is_element_present(popup1_locator):
// handle popup1
continue
if appium._is_element_present(popup2_locator):
// handle popup2
continue
...
time.sleep(1)
Naturally you need to implement this with all the elements that can be overlapped with some pop-up. 自然,您需要使用可以与某些弹出窗口重叠的所有元素来实现此功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.