4

How to handle issue of intermittently appium taps but doesn't work sometimes where no response comes from the tap? - Has anyone encountered this issue and how did you address it? - How can I improve the test so it will always click or tap on the element?

I'm using android tablets and phones. The test is passing sometimes and failing sometimes.

It is not a bug, because manually testing the app it works. But I do notice if my screen is sticky or oily due to many fingerprints sometimes I have to tap twice to open up the screen, but on other times I just tap once to open up the screen.

Any ideas?

    Code before this is to capture screenshots and compare if
    video images are different and changing. 
    Followed by if else statement to report if a loading icon 
    is displayed in case of internet connection lost, which
    I noticed a couple of times at this point when tapping fails.


    private boolean pauseVideo() throws InterruptedException {
    Boolean pausefoundnclicked = false;
    WebElement pause_element = null;

    size = driver.manage().window().getSize();
    int y=size.height/2;
    int x=size.width/2;

            Reporter.log("---Tap screen to bring up pause button.", true);
            //driver.tap(1, x, y, 500); (sometimes failing with this so tried to change to TouchAction
            TouchAction touchAction = new TouchAction(driver);
            touchAction.tap(x, y).perform();

            try
            {
                try {
                    pause_element = wait.until(ExpectedConditions.elementToBeClickable(By.id("player_overlay_widget_play_pause")));
                    pause_element.click();
                    Reporter.log("---Found and clicked pause button by id.", true);
                    pausefoundnclicked = true;
                }
                catch (Exception e1)
                {
                    try
                    {
                        pause_element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//android.widget.ImageView[contains(@resource-id, 'player_overlay_widget_play_pause') and @index='1']")));
                        pause_element.click();
                        Reporter.log("---Found and clicked pause button by xpath.", true);
                        pausefoundnclicked = true;
                    }
                    catch (Exception e)
                    {
                        pause_element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[2]")));
                        pause_element.click();
                        Reporter.log("---Found and clicked pause button by xpath.", true);
                        pausefoundnclicked = true;
                    }
                }
            }
            catch (Exception e)
            {
                Reporter.log("---Did not find a pause button.", true);
            }


    return pausefoundnclicked;

}
4
  • I edited it to be more readable. It is always a good idea to use bullet points and paragraphs. :-P
    – Yu Zhang
    Commented Aug 15, 2018 at 1:58
  • Is appium actually finding the element? What error messages (if any) are you getting? There isn't enough information here for us to help you.
    – Kate Paulk
    Commented Aug 15, 2018 at 11:43
  • Thanks Kate. I think I solved part of the issue. I decided to not use driver.tap and used TouchActions tap and I added 10 secs wait before and after in between my steps. Seemed to work better now. Now tests are failing because of sudden drop of internet and then it connects back to the internet in a span of a few seconds to a few minutes. When this happens there is a loading icon then it can't tap to open up the menu. I went to check on the device manually and it showed the network was connected, but there was no internet connection. Any ideas how to address this in automation? Commented Aug 16, 2018 at 3:28
  • I added the code in there now. Tap doesn't bring up the pause button. I know it works sometimes and it can find the pause button. The problem is tapping doesn't bring it up all the time. Sometimes tapping doesn't respond. Commented Aug 17, 2018 at 11:20

2 Answers 2

0

It will seem to help - but is that a fixed sleep? It looks like it from my investigation.

Long term this will slow your tests down considerably and, even worse, as your grow your test volume and devices and versions, etc you will still get intermittent failures due to factors such as local memory usage, the autonomous nature of browsers, etc. and so you will start increasing your fixed timeouts and your feedback will get slower and slower.

Always looks to use implicit(polling) waits. You can use explicit (fixed) waits for investigative purposes and they will work fairly well. For a dependable repeatable reliable solution you should use implicit waits.

1
  • How would you do implicit wait or explicit wait with tap? Tap is the problematic line. It'll be great if you can show me how. Thanks. Commented Aug 23, 2018 at 13:38
0

This line seems to be useful.

touchAction.tap(x, y).waitAction(500).perform();

Not the answer you're looking for? Browse other questions tagged or ask your own question.