How can I find a NativeScript TextField with Appium on Android?

Viewed 351

I'm trying to setup automated e2e tests using nativescript-dev-appium. I can't figure out how to locate a TextField when running a NativeScript app through Appium on Android. I'm using tns-core-modules v5.2.1 and nativescript-angular 7.0.2.

The only NativeScript element property I can find that seems to be for automation tests to find elements is automationText. When I set automationText on iOS, I can find a text field by using the Appium driver's driver.findElementByAutomationId or driver.findElementByAutomationText. However, when on Android, neither of those methods return the right element. findElementByAutomationId doesn't work at all (I think automation IDs may be iOS-specific), and findElementByAutomationText is returning a label next to my TextField and not the TextField itself.

My actual view has quite a few TextFields, but here's the basic idea:

<StackLayout>
  <Label text="Name"></Label>
  <TextField automationText="Name" ...></TextField>
</StackLayout>

Then, in my e2e test, I want to do this

const nameInput = await driver.findElementByAutomationText("Name") // Returns the Label and not the TextField

Since findElementByAutomationText seems to be searching elements by Text and not by AutomationText on Android, what is the most reliable way I could find my TextField when running my tests? Preferably, I'd like a cross-platform solution so I don't have to use different find strategies on iOS and Android.

1 Answers

Why can't you ask the developer to set id locator for the given component and use below snippet.

await driver.findElementById("#name");

I see your component doesn't have locator which is a reliable also....

Related