Tyler Stutson
Tyler Stutson

Reputation: 53

Appium XCUITest iOSDriver sendkeys() not working

TLDR: sendKeys() not working in web application text field, but only with IOSDriver/XCUITest and only on my web app's page. When running the same test in an Android simulator it works fine on my page, and everywhere else that I've tested (google and ask.com search inputs), but when I test in an iOS simulator, sendKeys() does not work on my web app's page, but works everywhere else (google and ask.com) and I have no idea why.

Capabilities config file:

["Safari", "12.2", "iOS", "iPhone Simulator", "XCUITest", "1.12.1"]

The test:

public class AppiumFieldsTest extends TestBase {
    @Test(dataProvider = "appium", groups = "Appium", description = "appium fields test")
    public void appiumFieldsTest(String browser, String version, String platform, String device, Method method, String automationName, String appiumVersion) throws Exception {

        IOSDriver<WebElement> driver;
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, platform);
        caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, version);
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, device);
        caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, automationName);
        caps.setCapability(MobileCapabilityType.BROWSER_NAME, browser);
        caps.setCapability("autoAcceptAlerts", true);
        caps.setCapability("connectHardwareKeyboard", false);
        caps.setCapability("sendKeyStrategy", "oneByOne");
        System.out.println(caps);
        String url = "http://127.0.0.1:4723/wd/hub";
        driver = new IOSDriver(new URL(url), caps);
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

driver.get("https://dev-app.pactsafe.com/sign?r=5cd32b47e89fc12f110449ca&s=5b2a6a597a7a3c1e4fa39c0b&signature=kto0Xohrz52ss7kc5z6t0grRbzUPsg6TrfbCbKtRuC5nQM82lNEhFL-zPgN7LaTvGG8mhuifNSc0nayvch1Rgc858Ptx8yRRD9MWJSoD4mEuHFg7LmJ-FHP~UsVEypv-gwwy-6N14BnhdkN94OZ73Kq9mBfS8QGlYKTqa76uclW0FIdnclRfA8NvK0z8CxjPcA8Luv9orw6Ye7wEuHAGqhqFURa15WeFrjrFKW9PNf6NkLVURNvOwqH4xBsfJubCkETMfjtnD4xT7PFSpgykAuU-Av0HehxCFNCYaHmyj5qvB3l9h7xgm8KKoSOO0c9VH1HpnLtwG6KAwwItawcsjg__");
        String textFieldtext = "some random text";
        Thread.sleep(10000);
        WebElement ele = driver.findElementByXPath("//*[@data-name=\"field-5b6305f656bcff936a3c53ca\"]");
        ele.click();
        Thread.sleep(3000);
        ele.sendKeys(textFieldtext);
        Assert.assertEquals(ele.getAttribute("data-value"), textFieldtext);
...
...
...

I am trying to do a .click() then a .sendKeys() on the first field at the top of the page, but it is not sending any text. If you run the test you can see that the field is actually being clicked, as it turns a darker blue color, as expected, but then then the sendKeys() function does nothing. Also, when testing on Android, the keyboard opens on click() but not on iOS.

The appium logs show that it is indeed trying to send the text after successfully finding the element:

[HTTP] {"id":"5000","text":"some random text","value":["s","o","m","e"," ","r","a","n","d","o","m"," ","t","e","x","t"]}
[W3C (bf5882ff)] Calling AppiumDriver.setValue() with args: [["s","o","m","e"," ","r","a","n","d","o","m"," ","t","e","x","t"],"5000","bf5882ff-f1a1-4ce1-bb79-02836762cb88"]
[XCUITest] Executing command 'setValue'

Any and all help/suggestions are greatly appreciated

Upvotes: 1

Views: 1541

Answers (1)

Luis Solano
Luis Solano

Reputation: 11

You can try using one of these options:

  1. setValue() This clears the value before sending the string.
  2. Add maxTypingFrequency capability, this is ONLY for IOS when you notice errors during typing, for example the wrong keys being pressed or visual oddities you notice while watching a test, try slowing the typing down. Set this cap to an integer and play around with the value until things work. Lower is slower, higher is faster! The default is 60.

Upvotes: 1

Related Questions