0

I'm using detox on a hybrid app. I'd like to use by.id in native code

Currently I'm logging in like this:

  try {
// 'Email address' is the input's placeholder text
await waitFor(element(by.text('Email address')).atIndex(0))
  .toBeVisible()
  .withTimeout(TIMEOUT);
await expect(element(by.label('Email address')).atIndex(0)).toBeVisible();
await element(by.label('Email address')).atIndex(0).typeText(config[email].email);
} catch (err) {
  // Email addresses get cached, so you won't find the text 'Email address' after the first login
} finally {
  await element(by.label('Password')).atIndex(0).typeText(devConfig[email].password);
  await element(by.label('Sign in')).atIndex(0).tap();
}

I want to do something like this.

await element(by.id('email')).typeText(devConfig[email].password);
await element(by.id('password')).typeText(devConfig[email].password);
await element(by.id('login')).tap();

How can I add ids to native ios inputs?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Tai
  • 490
  • 4
  • 18

2 Answers2

1

testID is mapped on iOS to accessibilityIdentifier. So if you set that to the desired value, you will be able to match it using by.id().

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
0

I added an accessibilityLabel and used by.label. https://github.com/wix/detox/blob/master/docs/APIRef.Matchers.md

Tai
  • 490
  • 4
  • 18