简体   繁体   中英

Handling popups with Appium in a native app

I am using Appium to automate a native iOS and Android app using Java. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM