首页 > 解决方案 > 有没有办法在 Detox 中记录找到的值?

问题描述

我正在尝试调试一些排毒测试,我有一些如下断言:

await expect(eventScreenMatcher.component).toExist();
await expect(eventScreenMatcher.toggleButton).toExist();
await expect(eventScreenMatcher.toggleButton).toHaveText('Add to schedule');

我相信的按钮toggleButton在屏幕上并且有正确的文本Add to schedule。但是 Detox 在最后一个断言上失败了。

Detox 如何确定文本是什么(它只是检查那个元素),有没有办法记录它认为的内容?

这是我目前得到的输出:

预期:(文本:是“添加到计划”并且视图具有有效的可见性=VISIBLE)得到:“ReactViewGroup{id=4605, visibility=VISIBLE, width=1300, height=139, 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, 布局-params=android.view.ViewGroup$LayoutParams@34f98eb, tag=ToggleScheduleButton, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}

标签: javascriptend-to-enddetox

解决方案


您是否尝试过使用“getAttributes()”方法?有时可能有点棘手,但我认为这将有助于解决您的问题。 https://wix.github.io/Detox/docs/api/actions-on-element/#getattributes

然后你可以尝试类似

const buttonAttributes = await eventScreenMatcher.toggleButton.getAttributes();

await jestExpect(buttonAttributes.text).toBe('Add to Schedule');

推荐阅读