plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[@nativescript/detox] Cannot match elements .byLabel (with automationText) nor .byId (on android)

Open MrSnoozles opened this issue 4 years ago • 1 comments

Hello,

I really enjoy how Detox works, but the element matchers do not seem to be working in NativeScript.

element.byId() works on iOS, but not on android element.byLabel() which - as far as I understand the documentation - should find elements labeled with the property automationText does not work at all.

I've created a small example repository showing the behaviour: https://github.com/MrSnoozles/ns-detox (The name of the installed emulator has to be defined in .detoxrc.json). The tests are failing because it doesn't find the elements.

MrSnoozles avatar Oct 21 '21 09:10 MrSnoozles

I had to do a custom testID for it to work, only when testing should this be included though:

https://github.com/rigor789/ui-tested-nsvue-app/blob/fecd9ed0392b8903d20a0967d87d60201082bc32/app/app.js#L6-L26

ns8 version should be something like this:

import { Property, Utils, View } from '@nativescript/core'

export const testIDProperty = new Property({
    name: "testID",
    defaultValue: "",
})
testIDProperty.register(View)

View.prototype[testIDProperty.setNative] = function (value) {
    if(global.android) {
        const id = Utils.ad.resources.getId(':id/nativescript_test_id')
        this.nativeViewProtected.setTag(id, value)
        this.nativeViewProtected.setTag(value)
        // this.nativeViewProtected.setContentDescription(value)
    } else {
        this.nativeViewProtected.accessibilityIdentifier = value
    }
}

I can't recall what we landed on - there were some discussions about adding a testID to core, but then it was not, let me find the discussion.

Refs:

  • https://github.com/NativeScript/NativeScript/pull/8944
  • https://github.com/NativeScript/NativeScript/issues/8943

rigor789 avatar Oct 21 '21 12:10 rigor789