Search code examples
iosreact-nativedetox

How to add an id to a native ios screen


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?


Solution

  • 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().