如何在反应原生的Android应用程序中使用detox在DatePicker对象上选择日期?

问题描述 投票:0回答:1

我在React-Native 0.59.1应用程序上使用detox 12.0.0进行e2e测试,我无法弄清楚如何在DatePicker对话框上选择日期:

enter image description here

这是代码:

await this.datePicker.tap() // this opens the date picker dialog, current year is 2001
await element(by.text('2000')).tap() // crash happens here
await element(by.text('1999')).tap() 

测试崩溃,这是输出:

    Failed: [Error: Error: No views in hierarchy found matching: (with text: is "2000" and view has effective visibility=VISIBLE)

    View Hierarchy:
    +>DecorView{id=-1, visibility=VISIBLE, width=735, height=789, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(wrapxwrap) gr=#11 sim=#20 ty=2 fl=#1800002 fmt=-3 wanim=0x7f0f0002 needsMenuKey=2 colorMode=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +->LinearLayout{id=-1, visibility=VISIBLE, width=651, height=705, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@fbb1f44, tag=null, root-is-layout-requested=false, has-input-connection=false, x=42.0, y=42.0, child-count=2}
    |
    +-->ViewStub{id=16908679, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@8cb382d, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +-->FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=651, height=705, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@57b32f3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +--->AlertDialogLayout{id=16909135, res-name=parentPanel, visibility=VISIBLE, width=651, height=705, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@e2d12dc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
    |
    +---->LinearLayout{id=16909385, res-name=topPanel, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@c280d6b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
    |
    +----->LinearLayout{id=16909375, res-name=title_template, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@66f3886, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
    |
    +------>AppCompatImageView{id=16908294, res-name=icon, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@e381547, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +------>DialogTitle{id=16908697, res-name=alertTitle, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@46e174, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
    |
    +----->Space{id=16909370, res-name=titleDividerNoCustom, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@a97869d, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +---->FrameLayout{id=16908801, res-name=contentPanel, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@c56bee3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +----->ScrollView{id=16909223, res-name=scrollView, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@3eaef99, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +------>LinearLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@171ec55, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
    |
    +------->Space{id=16909353, res-name=textSpacerNoTitle, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@241b66a, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +------->AppCompatTextView{id=16908299, res-name=message, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@b8b275b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
    |
    +------->Space{id=16909352, res-name=textSpacerNoButtons, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@b9fabf8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +---->FrameLayout{id=16908808, res-name=customPanel, visibility=VISIBLE, width=651, height=557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@8bccf36, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +----->FrameLayout{id=16908331, res-name=custom, visibility=VISIBLE, width=651, height=557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@a1f8fa4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +------>DatePicker{id=16908812, res-name=datePicker, visibility=VISIBLE, width=651, height=557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@4fea8c2, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +------->LinearLayout{id=-1, visibility=VISIBLE, width=651, height=557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@9b9f109, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
    |
    +-------->LinearLayout{id=16909151, res-name=pickers, visibility=VISIBLE, width=651, height=557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@e8794c5, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
    |
    +--------->NumberPicker{id=16909058, res-name=month, visibility=VISIBLE, width=168, height=473, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@7a09d4b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=21.0, y=42.0, child-count=1}
    |
    +---------->CustomEditText{id=16909105, res-name=numberpicker_input, visibility=VISIBLE, width=168, height=51, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@cb571e6, tag=null, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x80001 imeOptions=0x5 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=3 initialSelEnd=3 initialCapsMode=0x0 hintText=null label=null packageName=null fieldId=0 fieldName=null extras=null hintLocales=null contentMimeTypes=null ], x=0.0, y=211.0, text=Mar, input-type=524289, ime-target=false, has-links=false}
    |
    +--------->NumberPicker{id=16908819, res-name=day, visibility=VISIBLE, width=168, height=473, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@5829d4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=231.0, y=42.0, child-count=1}
    |
    +---------->CustomEditText{id=16909105, res-name=numberpicker_input, visibility=VISIBLE, width=168, height=51, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@40977d, tag=null, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x2 imeOptions=0x5 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=null label=null packageName=null fieldId=0 fieldName=null extras=null hintLocales=null contentMimeTypes=null ], x=0.0, y=211.0, text=29, input-type=2, ime-target=false, has-links=false}
    |
    +--------->NumberPicker{id=16909471, res-name=year, visibility=VISIBLE, width=168, height=473, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@956ac3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=441.0, y=42.0, child-count=1}
    |
    +---------->CustomEditText{id=16909105, res-name=numberpicker_input, visibility=VISIBLE, width=168, height=51, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@bf80f40, tag=null, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x2 imeOptions=0x6 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=null label=null packageName=null fieldId=0 fieldName=null extras=null hintLocales=null contentMimeTypes=null ], x=0.0, y=211.0, text=2001, input-type=2, ime-target=false, has-links=false}
    |
    +-------->CalendarView{id=16908770, res-name=calendar_view, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@c46d7be, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
    |
    +--------->DayPickerView{id=16908770, res-name=calendar_view, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@e94b1ca, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
    |
    +---------->DayPickerViewPager{id=16908821, res-name=day_picker_view_pager, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@fb76f3b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
    |
    +---------->AppCompatImageButton{id=16909171, res-name=prev, desc=Previous month, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@7a08658, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +---------->AppCompatImageButton{id=16909075, res-name=next, desc=Next month, visibility=INVISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@85833b1, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
    |
    +---->ScrollView{id=16908757, res-name=buttonPanel, visibility=VISIBLE, width=651, height=148, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@723c417, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=557.0, child-count=1}
    |
    +----->ButtonBarLayout{id=-1, visibility=VISIBLE, width=651, height=148, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@689b022, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
    |
    +------>AppCompatButton{id=16908315, res-name=button3, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@8968ab3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
    |
    +------>Space{id=16909293, res-name=spacer, visibility=INVISIBLE, width=217, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@fcdc870, tag=null, root-is-layout-requested=false, has-input-connection=false, x=32.0, y=137.0}
    |
    +------>AppCompatButton{id=16908314, res-name=button2, visibility=VISIBLE, width=202, height=126, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@450a7e9, tag=null, root-is-layout-requested=false, has-input-connection=false, x=249.0, y=11.0, text=Cancel, input-type=0, ime-target=false, has-links=false}
    |
    +------>AppCompatButton{id=16908313, res-name=button1, visibility=VISIBLE, width=168, height=126, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@b6ac6e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=451.0, y=11.0, text=OK, input-type=0, ime-target=false, has-links=false}
    |]

它应该选择2000,但我怀疑这是一个本地对话,排毒无法访问它,可能是吗?有替代方案(有排毒)吗?

android react-native datepicker detox
1个回答
0
投票

这有效:

    await element(by.text('Mar')).replaceText('Jun')
    await element(by.text('29')).replaceText('04')
    await element(by.text('2001')).replaceText('2000')
© www.soinside.com 2019 - 2024. All rights reserved.