0

I'm trying to create automation E2E testing for an SDK we build. We decided to test the SDK with a test app that will call the commands in a table that will test all SDK capabilities.

I was stuck for a while, Not understanding why some click events are working and some are not.

I've figure this out, It is because the ones that are working are visible and the the ones that are not working are not visible (don't really exists until the cell is created when needed to be visible?). In any case this is what I think or Hoping for because if not i really don't understand what is going on.

Example for code that is working:

@Test
public void step2_resetToken() throws InterruptedException {
    int count = 0;
    String s;
    do {
        MobileElement mElement = (MobileElement) iosDriver.findElement(By.name("Reset Token"));
        mElement.click();
        Thread.sleep(500);
        count++;
        assert count < TIMEOUTTIME;
        s = element.getText();
        System.out.println(s);
    } while(!(element.getText().contains("reset token performed:")));
}

Example for code that is not working:

@Test
public void step3_isAuthenticatedByPIN() throws InterruptedException {
    WebElement tableView = (WebElement) iosDriver.findElementByClassName("XCUIElementTypeTable");
    tableView.scrollTo("isAuthenticatedByPIN").click();
    int count = 0;
    String s;
    do {
        ////XCUIElementTypeStaticText[@name="isAuthenticatedByPIN"]
        MobileElement mElement = (MobileElement) iosDriver.findElementByClassName("XCUIElementTypeTable");
        mElement.sendKeys("isAuthenticatedByPIN");
        mElement.findElement(By.name("isAuthenticatedByPIN"));
        mElement.click();

        Thread.sleep(500);
        count++;
        assert count < TIMEOUTTIME;
        s = element.getText();
        System.out.println(s);
    } while(!(element.getText().contains("isAuthenticatedByPIN: YES")));
}

I've tried also calling this method before so there will be a scroll but it seems that it just can't find elements that where not visible when the app started:

 public static void scrolltoXPath(RemoteWebDriver driver, String xPath) {

    RemoteWebElement parent = (RemoteWebElement)driver.findElement(By.className("XCUIElementTypeTable"));
    String parentID = parent.getId();
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    scrollObject.put("element", parentID);
    scrollObject.put("name", "isConnected");
    driver.executeScript("mobile:scroll", scrollObject);
}

This what a tests to try with scrollTo but Java-client does not recognise scrollTo (Is this Java or Javascript method). Also i've tried with all other methods i found in google and couldn't figure this out.

  1. Anyone can tell me if i'm right about the conclusion that i cant click on a cell that is not displayed?
  2. If so, Please help with how to scroll to the cell i need to click on.

Thanks.

Erez
  • 1,933
  • 5
  • 29
  • 56

1 Answers1

2

You cannot click on the element that is not displayed in the screen.

You need to scroll to the element before you are able to click that element. You can scroll in various way. You can scroll using co-ordinates. You can also scroll using text, id, cont-desc etc.

Swipe screen by using coordinates

import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import java.util.concurrent.TimeUnit;
import static java.time.Duration.ofSeconds;

TouchAction action = new TouchAction(driver); 
action.press(PointOption.point(115, 650)).waitAction(WaitOptions.waitOptions(ofSeconds(1)))
                .moveTo(PointOption.point(115, 350)).release().perform();

scroll screen by using cont-desc

public static MobileElement scrollElementByContentDesc(String scrollableList, String uiClassSelector, String contentDesc) {
    return driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"" + scrollableList + "\"))" +
                    ".getChildByDescription(new UiSelector().className(\"" + uiClassSelector + "\"), \"" + contentDesc + "\")"));

}

For more information about appium scroll strategy follow this tutorial

Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
  • This seems to me to be Android only solution? As i wrote I need IOS solution that seems to be more complicated, Believe me that i when on reading every article out there trying to solve this on IOS, i read the tutorial also before but it is android only... It seems to me like for IOS there are less knowledge out there in regarding to Appium. – Erez Sep 13 '18 at 06:30
  • I don't know why the solution would be any different for IOS. This is an Appium issue. Perhaps the examples you see show Android locators, but the idea should be the same. I believe IOS devices likewise only make available in their document model the items that are visible at any given time. Since you can scroll using Appium independent of the element types displayed using swipe-like motions, there should be no problem. Take note of the last item displayed in the grid on the screen, scroll until your item is visible or the last item has not changed. – Bill Hileman Sep 13 '18 at 16:54