Search code examples
react-nativedetox

How do I determine which platform a specific detox test is running on?


When using detox matcher by class name i.e. by.type(className) https://github.com/wix/Detox/blob/master/docs/APIRef.Matchers.md#bytypeclassname

Is it possible to change the classname depending on the platform the test is running on (ios/android)

e.g. element(by.type(className)) becomes:

  • element(by.type('android.widget.ImageView')) on android
  • element(by.type('RCTImageView')) on ios

Solution

  • Use device.getPlatform() to determine the current device platform.

    Documentation: https://github.com/wix/Detox/blob/master/docs/APIRef.DeviceObjectAPI.md#devicegetplatform

    Example: https://github.com/wix/Detox/blob/240a709c609addf8b67e2ed6b91cba1293ad76c8/detox/test/e2e/03.actions.test.js#L124